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] LiteLLM does not support new web_search tool (Responses API) (#14083)
Ishaan Jaff37d885e46aea
diff --git a/litellm/litellm_core_utils/llm_cost_calc/tool_call_cost_tracking.py b/litellm/litellm_core_utils/llm_cost_calc/tool_call_cost_tracking.pyindex 75bb699292e..21ff44ab082 100644--- a/litellm/litellm_core_utils/llm_cost_calc/tool_call_cost_tracking.py+++ b/litellm/litellm_core_utils/llm_cost_calc/tool_call_cost_tracking.py@@ -580,7 +580,9 @@ class StandardBuiltInToolCostTracking:return WebSearchOptions(**kwargs.get("web_search_options", {}))tools = StandardBuiltInToolCostTracking._get_tools_from_kwargs(- kwargs, "web_search_preview"+ kwargs=kwargs, tool_type="web_search_preview"+ ) or StandardBuiltInToolCostTracking._get_tools_from_kwargs(+ kwargs=kwargs, tool_type="web_search")if tools:# Look for web search tool in the tools array@@ -612,6 +614,8 @@ class StandardBuiltInToolCostTracking:def _is_web_search_tool_call(tool: Dict) -> bool:if tool.get("type", None) == "web_search_preview":return True+ if tool.get("type", None) == "web_search":+ return Trueif "search_context_size" in tool:return Truereturn Falsediff --git a/litellm/types/llms/openai.py b/litellm/types/llms/openai.pyindex 74ff831503e..a0c8e5b6295 100644--- a/litellm/types/llms/openai.py+++ b/litellm/types/llms/openai.py@@ -1038,7 +1038,7 @@ class ResponsesAPIResponse(BaseLiteLLMOpenAIResponseObject):parallel_tool_calls: booltemperature: Optional[float]tool_choice: ToolChoice- tools: Union[List[Tool], List[ResponseFunctionToolCall]]+ tools: Union[List[Tool], List[ResponseFunctionToolCall], List[Dict[str, Any]]]top_p: Optional[float]max_output_tokens: Optional[int]previous_response_id: Optional[str]diff --git a/tests/llm_responses_api_testing/test_openai_responses_api.py b/tests/llm_responses_api_testing/test_openai_responses_api.pyindex d7042c4304f..b3947b26789 100644--- a/tests/llm_responses_api_testing/test_openai_responses_api.py+++ b/tests/llm_responses_api_testing/test_openai_responses_api.py@@ -1483,3 +1483,28 @@ async def test_openai_gpt5_reasoning_effort_parameter():# Validate the responseprint("Response:", json.dumps(response, indent=4, default=str))++++[email protected]("stream", [True, False])+async def test_basic_openai_responses_with_websearch(stream):+ litellm._turn_on_debug()+ request_model = "gpt-4o"+ response = await litellm.aresponses(+ model=request_model,+ stream=stream,+ input="hi",+ tools=[+ {+ "type": "web_search",+ "search_context_size": "low"+ }+ ]+ )+ if stream:+ async for chunk in response:+ print("chunk=", json.dumps(chunk, indent=4, default=str))+ else:+ print("response=", json.dumps(response, indent=4, default=str))