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(router): guard the declared-provider check for requests without a model
mateo-berri28d0ac5339ba
diff --git a/litellm/litellm_core_utils/get_llm_provider_logic.py b/litellm/litellm_core_utils/get_llm_provider_logic.pyindex 5474725966c..ce51fb19970 100644--- a/litellm/litellm_core_utils/get_llm_provider_logic.py+++ b/litellm/litellm_core_utils/get_llm_provider_logic.py@@ -127,7 +127,7 @@ def handle_anthropic_text_model_custom_llm_provider(return model, custom_llm_provider-def declared_authenticating_provider(model: str, custom_llm_provider: str | None = None) -> str | None:+def declared_authenticating_provider(model: str | None, custom_llm_provider: str | None = None) -> str | None:"""The authenticating provider this pair already names, or None.get_llm_provider runs the OAuth device flow for github_copilot and chatgpt, because their@@ -135,7 +135,7 @@ def declared_authenticating_provider(model: str, custom_llm_provider: str | Noneand for a declared pair the resolver's answer is the declaration itself, so metadata callersadopt the declaration instead of resolving."""- declared: Final = custom_llm_provider or (model.split("/", 1)[0] if "/" in model else None)+ declared: Final = custom_llm_provider or (model.split("/", 1)[0] if model and "/" in model else None)return declared if declared in PROVIDERS_THAT_AUTHENTICATE_ON_PROVIDER_INFO else Nonediff --git a/litellm/router_utils/pattern_match_deployments.py b/litellm/router_utils/pattern_match_deployments.pyindex 850ca74b387..0775e0a4039 100644--- a/litellm/router_utils/pattern_match_deployments.py+++ b/litellm/router_utils/pattern_match_deployments.py@@ -204,7 +204,7 @@ class PatternMatchRouter:return litellm_deployment_litellm_model- def get_pattern(self, model: str, custom_llm_provider: str | None = None) -> list[dict] | None:+ def get_pattern(self, model: str | None, custom_llm_provider: str | None = None) -> list[dict] | None:"""Check if a pattern exists for the given model and custom llm provider@@ -221,9 +221,9 @@ class PatternMatchRouter:return self.route(model) or self.route(f"{provider}/{model}")@staticmethod- def _resolved_provider(model: str) -> str | None:+ def _resolved_provider(model: str | None) -> str | None:try:- return get_llm_provider(model=model)[1]+ return get_llm_provider(model=model)[1] if model else Noneexcept Exception: # noqa: BLE001 # get_llm_provider raises when the provider is unknown; the name then routes as-isreturn Nonediff --git a/tests/test_litellm/router_utils/test_pattern_match_deployments.py b/tests/test_litellm/router_utils/test_pattern_match_deployments.pyindex af43644a305..795d448ef5f 100644--- a/tests/test_litellm/router_utils/test_pattern_match_deployments.py+++ b/tests/test_litellm/router_utils/test_pattern_match_deployments.py@@ -53,6 +53,20 @@ def test_get_pattern_bare_provider_name_never_matches_that_providers_wildcard(moassert router.get_pattern("github_copilot") is None+def test_get_pattern_missing_model_returns_none(monkeypatch):+ """Regression: a request without a model reaches the auth layer's pattern walk as ``None``; the+ declared-provider guard raised ``TypeError`` where the old inline resolve swallowed every+ resolver error, so the proxy's missing-model 400 became a crash."""++ def _unknown_provider(model, *args, **kwargs):+ raise ValueError(f"unknown provider for {model}")++ monkeypatch.setattr(pattern_match_deployments, "get_llm_provider", _unknown_provider)+ router = PatternMatchRouter()+ router.add_pattern("openai/*", _wildcard_deployment("openai/*"))+ assert router.get_pattern(None) is None++def test_get_pattern_still_resolves_unqualified_names(monkeypatch):monkeypatch.setattr(pattern_match_deployments,