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-tracking): price web search on dated search-preview map entries
mateo-berri7e539405edae
diff --git a/litellm/model_prices_and_context_window_backup.json b/litellm/model_prices_and_context_window_backup.jsonindex 3577fba359b..284e12675dd 100644--- a/litellm/model_prices_and_context_window_backup.json+++ b/litellm/model_prices_and_context_window_backup.json@@ -23894,6 +23894,11 @@"mode": "chat","output_cost_per_token": 6e-07,"output_cost_per_token_batches": 3e-07,+ "search_context_cost_per_query": {+ "search_context_size_high": 0.03,+ "search_context_size_low": 0.025,+ "search_context_size_medium": 0.0275+ },"supports_function_calling": true,"supports_parallel_function_calling": true,"supports_pdf_input": true,@@ -24028,6 +24033,11 @@"mode": "chat","output_cost_per_token": 1e-05,"output_cost_per_token_batches": 5e-06,+ "search_context_cost_per_query": {+ "search_context_size_high": 0.05,+ "search_context_size_low": 0.03,+ "search_context_size_medium": 0.035+ },"supports_function_calling": true,"supports_parallel_function_calling": true,"supports_pdf_input": true,diff --git a/model_prices_and_context_window.json b/model_prices_and_context_window.jsonindex 3577fba359b..284e12675dd 100644--- a/model_prices_and_context_window.json+++ b/model_prices_and_context_window.json@@ -23894,6 +23894,11 @@"mode": "chat","output_cost_per_token": 6e-07,"output_cost_per_token_batches": 3e-07,+ "search_context_cost_per_query": {+ "search_context_size_high": 0.03,+ "search_context_size_low": 0.025,+ "search_context_size_medium": 0.0275+ },"supports_function_calling": true,"supports_parallel_function_calling": true,"supports_pdf_input": true,@@ -24028,6 +24033,11 @@"mode": "chat","output_cost_per_token": 1e-05,"output_cost_per_token_batches": 5e-06,+ "search_context_cost_per_query": {+ "search_context_size_high": 0.05,+ "search_context_size_low": 0.03,+ "search_context_size_medium": 0.035+ },"supports_function_calling": true,"supports_parallel_function_calling": true,"supports_pdf_input": true,diff --git a/tests/test_litellm/litellm_core_utils/llm_cost_calc/test_tool_call_cost_tracking.py b/tests/test_litellm/litellm_core_utils/llm_cost_calc/test_tool_call_cost_tracking.pyindex 1adee045e17..0c945151a90 100644--- a/tests/test_litellm/litellm_core_utils/llm_cost_calc/test_tool_call_cost_tracking.py+++ b/tests/test_litellm/litellm_core_utils/llm_cost_calc/test_tool_call_cost_tracking.py@@ -730,6 +730,60 @@ def test_web_search_call_count_reads_dict_output_items(local_model_cost_map):)+def test_dated_search_preview_entries_carry_search_pricing(local_model_cost_map):+ """+ Regression for the live QA finding: OpenAI resolves gpt-4o-search-preview requests to the+ dated id gpt-4o-search-preview-2025-03-11, whose cost map entry lacked+ search_context_cost_per_query, so the default chat path silently billed the $0.035 search+ fee as $0. Dated entries must price identically to their undated siblings.+ """+ from litellm.types.utils import Usage++ for dated, undated in (+ ("gpt-4o-search-preview-2025-03-11", "gpt-4o-search-preview"),+ ("gpt-4o-mini-search-preview-2025-03-11", "gpt-4o-mini-search-preview"),+ ):+ assert (+ litellm.get_model_info(dated)["search_context_cost_per_query"]+ == litellm.get_model_info(undated)["search_context_cost_per_query"]+ )++ response = ModelResponse(+ model="gpt-4o-search-preview-2025-03-11",+ choices=[+ {+ "index": 0,+ "finish_reason": "stop",+ "message": {+ "role": "assistant",+ "content": "headlines",+ "annotations": [+ {+ "type": "url_citation",+ "url_citation": {+ "url": "https://example.com",+ "title": "t",+ "start_index": 0,+ "end_index": 1,+ },+ }+ ],+ },+ }+ ],+ )+ cost = StandardBuiltInToolCostTracking.get_cost_for_built_in_tools(+ model="gpt-4o-search-preview-2025-03-11",+ response_object=response,+ usage=Usage(prompt_tokens=14, completion_tokens=825, total_tokens=839),+ custom_llm_provider="openai",+ standard_built_in_tools_params=None,+ )+ assert cost == pytest.approx(0.035), (+ f"dated search-preview id must bill the $0.035 search fee, got ${cost}"+ )++# Note: File search integration test removed due to complex annotation detection logic# The unit tests in test_azure_assistant_cost_tracking.py provide comprehensive coverage