From eff7a9931c70e5face27efe095de9442fc77f46a Mon Sep 17 00:00:00 2001 From: Yiyang Liu <37043548+ianliuy@users.noreply.github.com> Date: Thu, 16 Apr 2026 14:10:13 -0700 Subject: [PATCH] fix: count image tokens in Titan embed response (fixes #25857) Signed-off-by: Yiyang Liu <37043548+ianliuy@users.noreply.github.com> --- .../bedrock/embed/amazon_titan_multimodal_transformation.py | 4 ++-- .../test_litellm/llms/bedrock/embed/test_bedrock_embedding.py | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/litellm/llms/bedrock/embed/amazon_titan_multimodal_transformation.py b/litellm/llms/bedrock/embed/amazon_titan_multimodal_transformation.py index 07b04734c30..d67f936aa88 100644 --- a/litellm/llms/bedrock/embed/amazon_titan_multimodal_transformation.py +++ b/litellm/llms/bedrock/embed/amazon_titan_multimodal_transformation.py @@ -93,9 +93,9 @@ class AmazonTitanMultimodalEmbeddingG1Config: ) usage = Usage( - prompt_tokens=total_prompt_tokens, + prompt_tokens=total_prompt_tokens + image_count, completion_tokens=0, - total_tokens=total_prompt_tokens, + total_tokens=total_prompt_tokens + image_count, prompt_tokens_details=prompt_tokens_details, ) return EmbeddingResponse(model=model, usage=usage, data=transformed_responses) diff --git a/tests/test_litellm/llms/bedrock/embed/test_bedrock_embedding.py b/tests/test_litellm/llms/bedrock/embed/test_bedrock_embedding.py index a38a6612f79..d2813ecb3a8 100644 --- a/tests/test_litellm/llms/bedrock/embed/test_bedrock_embedding.py +++ b/tests/test_litellm/llms/bedrock/embed/test_bedrock_embedding.py @@ -863,6 +863,8 @@ def test_titan_multimodal_embedding_image_cost_tracking(): ) assert result.usage is not None + assert result.usage.prompt_tokens == 1 # image_count included in prompt_tokens + assert result.usage.total_tokens == 1 assert result.usage.prompt_tokens_details is not None assert result.usage.prompt_tokens_details.image_count == 1