The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(cost): carry image and video input tokens through the Responses usage bridge
Marty Sullivan785c6cffc482
diff --git a/litellm/responses/litellm_completion_transformation/transformation.py b/litellm/responses/litellm_completion_transformation/transformation.pyindex 01fb6cb483d..ffd7ce491b1 100644--- a/litellm/responses/litellm_completion_transformation/transformation.py+++ b/litellm/responses/litellm_completion_transformation/transformation.py@@ -2851,6 +2851,8 @@ class LiteLLMCompletionResponsesConfig:cached_tokens=prompt_details.cached_tokens if prompt_details.cached_tokens is not None else 0,text_tokens=prompt_details.text_tokens,audio_tokens=prompt_details.audio_tokens,+ image_tokens=prompt_details.image_tokens,+ video_tokens=prompt_details.video_tokens,cached_tokens_details=(cached_tokens_details if isinstance(cached_tokens_details, CachedTokensDetails) else None),diff --git a/litellm/responses/utils.py b/litellm/responses/utils.pyindex 41a3ded7022..f50c17aff85 100644--- a/litellm/responses/utils.py+++ b/litellm/responses/utils.py@@ -1182,6 +1182,7 @@ class ResponseAPILoggingUtils:cached_tokens_details=getattr(response_api_usage.input_tokens_details, "cached_tokens_details", None),+ video_tokens=getattr(response_api_usage.input_tokens_details, "video_tokens", None),cache_write_tokens=getattr(response_api_usage.input_tokens_details, "cache_write_tokens", None),web_search_requests=getattr(response_api_usage.input_tokens_details, "web_search_requests", None),google_maps_grounding_requests=getattr(diff --git a/litellm/types/llms/openai.py b/litellm/types/llms/openai.pyindex e3eac9b9205..98548705979 100644--- a/litellm/types/llms/openai.py+++ b/litellm/types/llms/openai.py@@ -1291,7 +1291,9 @@ class InputTokensDetails(BaseLiteLLMOpenAIResponseObject):audio_tokens: int | None = Nonecached_tokens: int = 0cached_tokens_details: CachedTokensDetails | None = None+ image_tokens: int | None = Nonetext_tokens: int | None = None+ video_tokens: int | None = Nonemodel_config = {"extra": "allow"}diff --git a/tests/test_litellm/responses/litellm_completion_transformation/test_litellm_completion_responses.py b/tests/test_litellm/responses/litellm_completion_transformation/test_litellm_completion_responses.pyindex 0ed101952be..2f9f7adfcf1 100644--- a/tests/test_litellm/responses/litellm_completion_transformation/test_litellm_completion_responses.py+++ b/tests/test_litellm/responses/litellm_completion_transformation/test_litellm_completion_responses.py@@ -2885,6 +2885,39 @@ class TestUsageTransformation:assert getattr(response_usage.input_tokens_details, "cache_write_tokens", None) == 800assert response_usage.input_tokens_details.model_dump()["cache_write_tokens"] == 800+ def test_transform_usage_preserves_input_modality_tokens(self):+ """Regression: the bridge dropped image and video input tokens.++ Vertex reports prompt tokens split by modality, so a Live session that sends+ camera frames arrives with image_tokens set. InputTokensDetails declared only+ audio/cached/text, so those tokens were folded into text and lost their+ attribution, and any per-modality rate could never apply to them.+ """+ usage = Usage(+ prompt_tokens=300,+ completion_tokens=10,+ total_tokens=310,+ prompt_tokens_details=PromptTokensDetailsWrapper(+ text_tokens=20, audio_tokens=80, image_tokens=150, video_tokens=50, cached_tokens=0+ ),+ completion_tokens_details=CompletionTokensDetailsWrapper(text_tokens=10),+ )++ response_usage = LiteLLMCompletionResponsesConfig._transform_chat_completion_usage_to_responses_usage(+ chat_completion_response=usage+ )+ details = response_usage.input_tokens_details+ assert details is not None+ assert getattr(details, "image_tokens", None) == 150+ assert getattr(details, "video_tokens", None) == 50+ assert getattr(details, "audio_tokens", None) == 80++ from litellm.responses.utils import ResponseAPILoggingUtils++ back = ResponseAPILoggingUtils._transform_response_api_usage_to_chat_usage(response_usage.model_dump())+ assert back.prompt_tokens_details.image_tokens == 150+ assert back.prompt_tokens_details.video_tokens == 50+def test_transform_usage_with_reasoning_tokens_gemini(self):"""Test that reasoning_tokens from Gemini are properly transformed to output_tokens_details"""# Setup: Simulate Gemini usage with thoughtsTokenCount