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
style: ruff format xAI cost calculator and responses transform
Yang Yang4a536098e129
diff --git a/litellm/llms/xai/cost_calculator.py b/litellm/llms/xai/cost_calculator.pyindex ebeac61fb43..a32e2af0959 100644--- a/litellm/llms/xai/cost_calculator.py+++ b/litellm/llms/xai/cost_calculator.py@@ -17,9 +17,7 @@ if TYPE_CHECKING:_DEFAULT_WEB_SEARCH_COST_PER_CALL = 5.0 / 1000.0-def apply_server_side_tool_usage_details_to_usage(- usage: Usage, details: Mapping[str, Any] | None-) -> None:+def apply_server_side_tool_usage_details_to_usage(usage: Usage, details: Mapping[str, Any] | None) -> None:"""Attach server_side_tool_usage_details and mirror web_search_calls ontoprompt_tokens_details.web_search_requests for built-in tool cost gating.diff --git a/litellm/llms/xai/responses/transformation.py b/litellm/llms/xai/responses/transformation.pyindex de041854b3a..35be5602029 100644--- a/litellm/llms/xai/responses/transformation.py+++ b/litellm/llms/xai/responses/transformation.py@@ -96,9 +96,7 @@ class XAIResponsesAPIConfig(OpenAIResponsesAPIConfig):attaching server_side_tool_usage_details here, stream=true web_search usage isdropped when usage is normalized for billing."""- event = super().transform_streaming_response(- model=model, parsed_chunk=parsed_chunk, logging_obj=logging_obj- )+ event = super().transform_streaming_response(model=model, parsed_chunk=parsed_chunk, logging_obj=logging_obj)if isinstance(event,(ResponseCompletedEvent, ResponseIncompleteEvent, ResponseFailedEvent),@@ -117,9 +115,7 @@ class XAIResponsesAPIConfig(OpenAIResponsesAPIConfig):details = getattr(usage, "server_side_tool_usage_details", None)if details is not None:return details- model_extra = getattr(usage, "model_extra", None) or getattr(- usage, "__pydantic_extra__", None- )+ model_extra = getattr(usage, "model_extra", None) or getattr(usage, "__pydantic_extra__", None)if isinstance(model_extra, dict):return model_extra.get("server_side_tool_usage_details")return None@@ -131,9 +127,7 @@ class XAIResponsesAPIConfig(OpenAIResponsesAPIConfig):if response.usage is None:return- details = XAIResponsesAPIConfig._server_side_tool_usage_details_from_usage(- response.usage- )+ details = XAIResponsesAPIConfig._server_side_tool_usage_details_from_usage(response.usage)if details is None:return