From 199fbabfb3fd9e748049d2e06bc2d7a0300eeb2a Mon Sep 17 00:00:00 2001 From: jquinter Date: Fri, 6 Feb 2026 12:33:20 -0300 Subject: [PATCH] Fix MCP streaming test skip logic and metadata None check (#20428) - Fix skip condition to detect claude models (was only checking for "anthropic" in model name, missing "claude-haiku-4-5") - Add missing skip for OpenAI tests when OPENAI_API_KEY is not set - Fix TypeError in utils.py when metadata is explicitly None instead of missing (use `or {}` fallback) --- litellm/litellm_core_utils/get_llm_provider_logic.py | 10 ++++++++-- litellm/utils.py | 4 ++-- tests/mcp_tests/test_aresponses_api_with_mcp.py | 4 ++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/litellm/litellm_core_utils/get_llm_provider_logic.py b/litellm/litellm_core_utils/get_llm_provider_logic.py index 718773a1b1..8ab4ec15b0 100644 --- a/litellm/litellm_core_utils/get_llm_provider_logic.py +++ b/litellm/litellm_core_utils/get_llm_provider_logic.py @@ -51,7 +51,7 @@ def handle_cohere_chat_model_custom_llm_provider( if custom_llm_provider == "cohere" and model in litellm.cohere_chat_models: return model, "cohere_chat" - if "/" in model: + if model and "/" in model: _custom_llm_provider, _model = model.split("/", 1) if ( _custom_llm_provider @@ -84,7 +84,7 @@ def handle_anthropic_text_model_custom_llm_provider( ): return model, "anthropic_text" - if "/" in model: + if model and "/" in model: _custom_llm_provider, _model = model.split("/", 1) if ( _custom_llm_provider @@ -113,6 +113,12 @@ def get_llm_provider( # noqa: PLR0915 Return model, custom_llm_provider, dynamic_api_key, api_base """ try: + # Early validation - model is required + if model is None: + raise ValueError( + "model parameter is required but was None. Please provide a valid model name." + ) + if litellm.LiteLLMProxyChatConfig._should_use_litellm_proxy_by_default( litellm_params=litellm_params ): diff --git a/litellm/utils.py b/litellm/utils.py index 0fa5436d98..3fbc2ce1dc 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -2008,9 +2008,9 @@ def client(original_function): # noqa: PLR0915 kwargs["model"] = context_window_fallback_dict[model] return await original_function(*args, **kwargs) elif call_type == CallTypes.aresponses.value: - _is_litellm_router_call = "model_group" in kwargs.get( + _is_litellm_router_call = "model_group" in (kwargs.get( "metadata", {} - ) # check if call from litellm.router/proxy + ) or {}) # check if call from litellm.router/proxy if ( num_retries and not _is_litellm_router_call diff --git a/tests/mcp_tests/test_aresponses_api_with_mcp.py b/tests/mcp_tests/test_aresponses_api_with_mcp.py index a7bbfef14a..bae0b15dfe 100644 --- a/tests/mcp_tests/test_aresponses_api_with_mcp.py +++ b/tests/mcp_tests/test_aresponses_api_with_mcp.py @@ -683,8 +683,8 @@ async def test_streaming_responses_api_with_mcp_tools( Return the user the result of request 2 """ - # Skip test if required API keys are not set - if ("anthropic" in model.lower() or "claude" in model.lower()) and not os.getenv("ANTHROPIC_API_KEY"): + # Skip test if API keys are not set for the respective models + if ("claude" in model.lower() or "anthropic" in model.lower()) and not os.getenv("ANTHROPIC_API_KEY"): pytest.skip("ANTHROPIC_API_KEY not set, skipping anthropic model test") if ("gpt" in model.lower() or "openai" in model.lower()) and not os.getenv("OPENAI_API_KEY"): pytest.skip("OPENAI_API_KEY not set, skipping openai model test")