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
merge: origin/main into litellm_internal_copy_37075
mateo-berri4f27573424d2
diff --cc litellm/responses/litellm_completion_transformation/transformation.pyindex 2b011abf0e2,4415b0cbbbb..01fb6cb483d--- a/litellm/responses/litellm_completion_transformation/transformation.py+++ b/litellm/responses/litellm_completion_transformation/transformation.py@@@ -2654,35 -2822,24 +2822,41 @@@ class LiteLLMCompletionResponsesConfig# Translate prompt_tokens_details to input_tokens_detailsif hasattr(usage, "prompt_tokens_details") and usage.prompt_tokens_details is not None:prompt_details: Final = usage.prompt_tokens_details- input_details_dict: Final[dict[str, int]] = {}-- if hasattr(prompt_details, "cached_tokens") and prompt_details.cached_tokens is not None:- input_details_dict["cached_tokens"] = prompt_details.cached_tokens- else:- input_details_dict["cached_tokens"] = 0-- if hasattr(prompt_details, "text_tokens") and prompt_details.text_tokens is not None:- input_details_dict["text_tokens"] = prompt_details.text_tokens-- if hasattr(prompt_details, "audio_tokens") and prompt_details.audio_tokens is not None:- input_details_dict["audio_tokens"] = prompt_details.audio_tokens-+ cached_tokens_details: Final = getattr(prompt_details, "cached_tokens_details", None)+ cache_write_tokens: Final = getattr(prompt_details, "cache_write_tokens", None) or getattr(+ prompt_details, "cache_creation_tokens", None+ )+ cache_write_extra: Final[Mapping[str, int]] = (+ MappingProxyType({"cache_write_tokens": cache_write_tokens})+ if cache_write_tokens is not None+ else MappingProxyType({})+ )+ # The cost path reads the grounding counters off the input details, and a realtime+ # session's usage is rebuilt from its own response.done, so dropping them here bills+ # no per-query grounding fee at all.- for counter in ("web_search_requests", "google_maps_grounding_requests"):- counter_value = getattr(prompt_details, counter, None)- if counter_value is not None:- input_details_dict[counter] = counter_value-- cache_write_tokens = getattr(prompt_details, "cache_write_tokens", None) or getattr(- prompt_details, "cache_creation_tokens", None++ grounding_request_counts: Final[Mapping[str, int]] = MappingProxyType(++ {++ counter: count++ for counter, count in (++ ("web_search_requests", getattr(prompt_details, "web_search_requests", None)),++ (++ "google_maps_grounding_requests",++ getattr(prompt_details, "google_maps_grounding_requests", None),++ ),++ )++ if count is not None++ }++ )+ response_usage.input_tokens_details = InputTokensDetails(+ 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,+ cached_tokens_details=(+ cached_tokens_details if isinstance(cached_tokens_details, CachedTokensDetails) else None+ ),+ **cache_write_extra,++ **grounding_request_counts,)- if cache_write_tokens is not None:- input_details_dict["cache_write_tokens"] = cache_write_tokens-- if input_details_dict:- response_usage.input_tokens_details = InputTokensDetails(**input_details_dict)# Translate completion_tokens_details to output_tokens_detailsif hasattr(usage, "completion_tokens_details") and usage.completion_tokens_details is not None:diff --cc litellm/responses/utils.pyindex b2844834860,d63e3ddf0aa..41a3ded7022--- a/litellm/responses/utils.py+++ b/litellm/responses/utils.py@@@ -1136,11 -1179,10 +1179,14 @@@ class ResponseAPILoggingUtilsaudio_tokens=getattr(response_api_usage.input_tokens_details, "audio_tokens", None),text_tokens=getattr(response_api_usage.input_tokens_details, "text_tokens", None),image_tokens=getattr(response_api_usage.input_tokens_details, "image_tokens", None),+ cached_tokens_details=getattr(+ response_api_usage.input_tokens_details, "cached_tokens_details", 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(+ response_api_usage.input_tokens_details, "google_maps_grounding_requests", None+ ),)completion_tokens_details: CompletionTokensDetailsWrapper | None = Noneoutput_tokens_details: Final[OutputTokensDetails | None] = getattr(