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): tell an unknown deployment apart from a known non-reasoning one
mateo-berri96acac1f9152
diff --git a/litellm/router_utils/reasoning_effort_capability.py b/litellm/router_utils/reasoning_effort_capability.pyindex 7c8b5523d7c..53a159af7d1 100644--- a/litellm/router_utils/reasoning_effort_capability.py+++ b/litellm/router_utils/reasoning_effort_capability.py@@ -54,15 +54,19 @@ def _supports_none_reasoning_effort(model_info: Mapping[str, object]) -> bool:def resolve_supported_reasoning_efforts(model_info: Mapping[str, object]) -> tuple[str, ...] | None:- """None = the caller passed no supports_reasoning key at all; () = this deployment adds no- effort levels to its group. The router always supplies the key, so a deployment absent from the- model map arrives with supports_reasoning None and lands on (), the same answer a mapped- non-reasoning model gets: the group cannot promise a level on behalf of a model nothing is known- about. () therefore reads as "no usable answer" downstream, which is why the dashboard falls- back to the capability-blind level list on an empty group rather than hiding the control."""+ """None = nothing is known about this deployment, so it must not narrow its group; () = this is a+ known model that accepts no effort level, which correctly empties the group. Keeping the two+ apart matters because the router registers a deployment absent from the model map under a+ synthesized entry, and get_model_info then answers with supports_reasoning None exactly as it+ does for a mapped non-reasoning model. That entry carries no mode, which every real map entry for+ a routable model does, so an unset flag with no mode is the unknown case and one custom model in+ a group no longer wipes the levels its mapped siblings agree on."""if "supports_reasoning" not in model_info:return None- if model_info.get("supports_reasoning") is not True:+ supports_reasoning: Final = model_info.get("supports_reasoning")+ if supports_reasoning is None and model_info.get("mode") is None:+ return None+ if supports_reasoning is not True:return ()opt_out: Final = frozenset(effort for effort, flag in _OPT_OUT_FLAGS if model_info.get(flag) is not False)opt_in: Final = frozenset(effort for effort, flag in _OPT_IN_FLAGS if model_info.get(flag) is True)diff --git a/tests/test_litellm/router_utils/test_reasoning_effort_capability.py b/tests/test_litellm/router_utils/test_reasoning_effort_capability.pyindex 1c7d5355549..f3d71d19c47 100644--- a/tests/test_litellm/router_utils/test_reasoning_effort_capability.py+++ b/tests/test_litellm/router_utils/test_reasoning_effort_capability.py@@ -11,8 +11,16 @@ class TestResolveSupportedReasoningEfforts:assert resolve_supported_reasoning_efforts({}) is Nonedef test_non_reasoning_model_supports_no_efforts(self):- assert resolve_supported_reasoning_efforts({"supports_reasoning": None}) == ()assert resolve_supported_reasoning_efforts({"supports_reasoning": False}) == ()+ assert resolve_supported_reasoning_efforts({"mode": "chat", "supports_reasoning": None}) == ()++ def test_unset_flag_on_an_entry_with_no_mode_resolves_to_unknown(self):+ # The router registers a deployment absent from the model map under a synthesized entry, and+ # get_model_info then answers with supports_reasoning None just as it does for a mapped+ # non-reasoning model. Only the missing mode tells them apart, and reading the synthesized+ # one as () would let one custom model empty every level its mapped siblings agree on.+ assert resolve_supported_reasoning_efforts({"supports_reasoning": None}) is None+ assert resolve_supported_reasoning_efforts({"mode": None, "supports_reasoning": None}) is Nonedef test_reasoning_model_with_no_flags_gets_the_opt_out_levels_only(self):# The kimi shape: supports_reasoning true, zero effort flags. medium/high are unconditional,diff --git a/tests/test_litellm/test_router.py b/tests/test_litellm/test_router.pyindex 62c6411c3cc..ba23075e7cc 100644--- a/tests/test_litellm/test_router.py+++ b/tests/test_litellm/test_router.py@@ -8927,11 +8927,11 @@ def test_model_group_info_intersects_supported_reasoning_efforts():assert result.supported_reasoning_efforts == ("minimal", "low", "medium", "high")-def test_model_group_info_reasoning_efforts_empty_when_a_deployment_is_off_the_map():+def test_model_group_info_reasoning_efforts_ignore_a_deployment_off_the_map():"""The router fills every ModelInfo key, so a deployment absent from the model map arrives with- supports_reasoning None rather than with the key missing, and the group can no longer promise a- level on its behalf. The dashboard reads the empty result as "nothing known" and falls back to- the capability-blind picker, which is what it showed before this field existed."""+ supports_reasoning None rather than with the key missing. Its synthesized entry carries no mode,+ which is what separates it from a mapped non-reasoning model, and nothing being known about it is+ no reason to drop the levels the rest of the group agrees on."""router = litellm.Router(model_list=[{@@ -8964,6 +8964,45 @@ def test_model_group_info_reasoning_efforts_empty_when_a_deployment_is_off_the_muser_facing_model_group_name="smart-group",)+ assert result is not None+ assert result.supported_reasoning_efforts == ("none", "minimal", "low", "medium", "high", "max")+++def test_model_group_info_reasoning_efforts_empty_on_a_mapped_non_reasoning_deployment():+ """A group mixing a reasoning model with one the map knows is not a reasoning model shares no+ level, so it advertises none and the picker offers nothing rather than a level routing would+ hand to a deployment that rejects it."""+ router = litellm.Router(+ model_list=[+ {+ "model_name": "mixed-group",+ "litellm_params": {"model": "anthropic/opus-like"},+ "model_info": {"id": "opus-like-deployment"},+ },+ {+ "model_name": "mixed-group",+ "litellm_params": {"model": "openai/plain-chat"},+ "model_info": {"id": "plain-chat-deployment"},+ },+ ]+ )++ def _model_info(model_id: str, model_name: str):+ if model_id == "opus-like-deployment":+ return {+ "key": model_name,+ "litellm_provider": "anthropic",+ "mode": "chat",+ "supports_reasoning": True,+ }+ return {"key": model_name, "litellm_provider": "openai", "mode": "chat", "supports_reasoning": None}++ with patch.object(router, "get_deployment_model_info", side_effect=_model_info):+ result = router._set_model_group_info(+ model_group="mixed-group",+ user_facing_model_group_name="mixed-group",+ )+assert result is not Noneassert result.supported_reasoning_efforts == ()diff --git a/ui/litellm-dashboard/src/components/add_model/ComplexityRouterConfig.test.tsx b/ui/litellm-dashboard/src/components/add_model/ComplexityRouterConfig.test.tsxindex 09a710c8729..dbc5bd6ee86 100644--- a/ui/litellm-dashboard/src/components/add_model/ComplexityRouterConfig.test.tsx+++ b/ui/litellm-dashboard/src/components/add_model/ComplexityRouterConfig.test.tsx@@ -968,7 +968,9 @@ describe("ComplexityRouterConfig per-model effort filtering", () => {expect(options).toEqual(["Default", "none", "minimal", "low", "medium", "high", "xhigh"]);});- it("falls back to every effort when the group intersects to nothing", async () => {+ // An empty list is the group's own answer that its deployments share no level, which is different+ // from the field being absent, so the control is dropped rather than falling back to every level.+ it("offers no effort at all when the group intersects to nothing", () => {renderWithProviders(<ComplexityRouterConfig{...baseProps}@@ -978,12 +980,9 @@ describe("ComplexityRouterConfig per-model effort filtering", () => {]}/>,);- const user = userEvent.setup();- await user.click(- screen.getByRole("combobox", { name: "Reasoning effort for claude-3-opus in the Reasoning tier" }),- );- const options = (await screen.findAllByRole("option")).map((option) => option.textContent);- expect(options).toEqual(["Default", "none", "minimal", "low", "medium", "high", "xhigh"]);+ expect(+ screen.queryByRole("combobox", { name: "Reasoning effort for claude-3-opus in the Reasoning tier" }),+ ).not.toBeInTheDocument();});// Hand-authored configs can carry a level outside the supported set (e.g. max); it must renderdiff --git a/ui/litellm-dashboard/src/components/add_model/ComplexityRouterConfig.tsx b/ui/litellm-dashboard/src/components/add_model/ComplexityRouterConfig.tsxindex 77e093b63d9..a113e3643cc 100644--- a/ui/litellm-dashboard/src/components/add_model/ComplexityRouterConfig.tsx+++ b/ui/litellm-dashboard/src/components/add_model/ComplexityRouterConfig.tsx@@ -226,20 +226,6 @@ export const effectiveTierLabel = (tier: keyof ComplexityTiers, tierLabels: Compexport const planModeEligibleTiers = (tiers: ComplexityTiers): Array<keyof ComplexityTiers> =>TIER_KEYS.filter((tier) => (tiers[tier] ?? []).length > 0);-/**- * The backend list is the per-group intersection of accepted effort levels. An empty intersection- * carries no more information than a proxy that does not send the field yet (one deployment absent- * from the model map empties it), so both fall back to the coarse supports_reasoning gate with every- * level offered, which is what this dropdown showed before the field existed.- */-const effortOptionsForModel = (model: ModelGroup): string[] => {- const advertised = model.supported_reasoning_efforts ?? [];- if (advertised.length > 0) {- return [...advertised];- }- return model.supports_reasoning ? [...REASONING_EFFORT_OPTIONS] : [];-};-const ComplexityRouterConfig: React.FC<ComplexityRouterConfigProps> = ({modelInfo,value,@@ -265,8 +251,13 @@ const ComplexityRouterConfig: React.FC<ComplexityRouterConfigProps> = ({const derivedDefaultModel = resolveComplexityDefaultModel(value.tiers);const defaultModel = resolveComplexityDefaultModel(value.tiers, value.default_model);+ // An absent list means the proxy does not send the field yet, so every level is offered as before.+ // An empty list is the group's own answer that its deployments share no level, and is left empty.const effortOptionsByModel: Record<string, string[]> = Object.fromEntries(- modelInfo.map((model) => [model.model_group, effortOptionsForModel(model)]),+ modelInfo.map((model) => [+ model.model_group,+ model.supported_reasoning_efforts ?? (model.supports_reasoning ? [...REASONING_EFFORT_OPTIONS] : []),+ ]),);// Embedding models can't serve a chat-completion role, so they're excluded here.