Skip to content

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]

fix(cost): carry grounding counters through the Responses usage bridge

Marty Sullivan6d71e3385b8c
diff --git a/litellm/responses/litellm_completion_transformation/transformation.py b/litellm/responses/litellm_completion_transformation/transformation.py
index b2d1a69e0d8..2b011abf0e2 100644
--- a/litellm/responses/litellm_completion_transformation/transformation.py
+++ b/litellm/responses/litellm_completion_transformation/transformation.py
@@ -2667,6 +2667,14 @@ class LiteLLMCompletionResponsesConfig:
if hasattr(prompt_details, "audio_tokens") and prompt_details.audio_tokens is not None:
input_details_dict["audio_tokens"] = prompt_details.audio_tokens
+ # 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
)
diff --git a/litellm/responses/utils.py b/litellm/responses/utils.py
index 540d492beec..7e0acd14b9c 100644
--- a/litellm/responses/utils.py
+++ b/litellm/responses/utils.py
@@ -1137,6 +1137,12 @@ class ResponseAPILoggingUtils:
text_tokens=getattr(response_api_usage.input_tokens_details, "text_tokens", None),
image_tokens=getattr(response_api_usage.input_tokens_details, "image_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(
+ response_api_usage.input_tokens_details, "google_maps_grounding_requests", None
+ ),
)
completion_tokens_details: CompletionTokensDetailsWrapper | None = None
output_tokens_details: Final[OutputTokensDetails | None] = getattr(