From bb247685da9d9c95e6a3a5b61047e3222f2f91cd Mon Sep 17 00:00:00 2001 From: Chesars Date: Sat, 21 Mar 2026 23:29:45 -0300 Subject: [PATCH] fix: skip token counting for multimodal inputs in process_response --- .../batch_embed_content_transformation.py | 7 +++++-- .../test_batch_embed_content_transformation.py | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/litellm/llms/vertex_ai/gemini_embeddings/batch_embed_content_transformation.py b/litellm/llms/vertex_ai/gemini_embeddings/batch_embed_content_transformation.py index 39de34169c2..834d3a5c0a8 100644 --- a/litellm/llms/vertex_ai/gemini_embeddings/batch_embed_content_transformation.py +++ b/litellm/llms/vertex_ai/gemini_embeddings/batch_embed_content_transformation.py @@ -312,8 +312,11 @@ def process_response( model_response.data = openai_embeddings model_response.model = model - input_text = get_formatted_prompt(data={"input": input}, call_type="embedding") - prompt_tokens = token_counter(model=model, text=input_text) + if _is_multimodal_input(input): + prompt_tokens = 0 + else: + input_text = get_formatted_prompt(data={"input": input}, call_type="embedding") + prompt_tokens = token_counter(model=model, text=input_text) model_response.usage = Usage( prompt_tokens=prompt_tokens, total_tokens=prompt_tokens ) diff --git a/tests/test_litellm/llms/vertex_ai/gemini_embeddings/test_batch_embed_content_transformation.py b/tests/test_litellm/llms/vertex_ai/gemini_embeddings/test_batch_embed_content_transformation.py index 2658646d59f..1417c04503c 100644 --- a/tests/test_litellm/llms/vertex_ai/gemini_embeddings/test_batch_embed_content_transformation.py +++ b/tests/test_litellm/llms/vertex_ai/gemini_embeddings/test_batch_embed_content_transformation.py @@ -192,4 +192,4 @@ class TestProcessResponse: assert len(result.data) == 2 assert result.data[0]["index"] == 0 assert result.data[1]["index"] == 1 - assert result.usage.prompt_tokens >= 0 + assert result.usage.prompt_tokens == 0