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.py index 99f269758fc..28c14a747e5 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 @@ -727,10 +727,8 @@ class StandardBuiltInToolCostTracking: web_search_options: Optional[WebSearchOptions] = None file_search: Optional[FileSearchTool] = None - # Check direct web_search_options first - web_search_options_dict = kwargs.get("web_search_options") - if web_search_options_dict: - web_search_options = WebSearchOptions(**web_search_options_dict) + if "web_search_options" in kwargs: + web_search_options = WebSearchOptions(**kwargs["web_search_options"]) # Get tools once tools = kwargs.get("tools") 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.py index de77cea92a5..54d12dcf506 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 @@ -376,3 +376,11 @@ class TestGetBuiltInToolsFromKwargs: # Direct web_search_options should take precedence assert web_search is not None assert web_search.get("search_context_size") == "high" + + def test_empty_web_search_options_dict_returns_web_search_options(self): + """An empty web_search_options dict should still produce WebSearchOptions (use defaults).""" + kwargs = {"web_search_options": {}} + web_search, file_search = StandardBuiltInToolCostTracking.get_built_in_tools_from_kwargs(kwargs) + + assert web_search is not None + assert file_search is None