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(anthropic): handle per-level reasoning_effort flags without supports_reasoning (#38618)
tin-berrib3322e30a738
diff --git a/litellm/router_utils/reasoning_effort_capability.py b/litellm/router_utils/reasoning_effort_capability.pyindex 2a4fae4109f..9185d901a28 100644--- a/litellm/router_utils/reasoning_effort_capability.py+++ b/litellm/router_utils/reasoning_effort_capability.py@@ -148,16 +148,25 @@ def resolve_supported_reasoning_efforts(unset flag as () would let one custom deployment empty every level its mapped siblings agreeon. deployment_is_mapped is that provenance, and an operator who wants either answer for anoff-map deployment gets it by setting supports_reasoning explicitly.++ If supports_reasoning is unset but at least one per-level flag (e.g.+ supports_minimal_reasoning_effort) is present, treat it as implicitly True, since the+ per-level flags are evidence the model supports reasoning. An explicit False always wins:+ it is the operator's escape hatch and must not be overridden by inherited per-level flags."""supports_reasoning: Final = model_info.get("supports_reasoning")- if supports_reasoning is not True:- return () if supports_reasoning is False or deployment_is_mapped else None+ if supports_reasoning is False:+ return ()++ flags: Final = _declared_effort_flags(model_info)+ has_per_level_flag: Final = any(value is not None for value in flags.values())+ if supports_reasoning is not True and not has_per_level_flag:+ return () if deployment_is_mapped else Nonedeclared: Final = declared_reasoning_efforts(model_info)if declared is not None:return declared- flags: Final = _declared_effort_flags(model_info)if all(value is None for value in flags.values()):return Nonediff --git a/tests/test_litellm/router_utils/test_reasoning_effort_capability.py b/tests/test_litellm/router_utils/test_reasoning_effort_capability.pyindex ff5660288f5..a0dbf3b6637 100644--- a/tests/test_litellm/router_utils/test_reasoning_effort_capability.py+++ b/tests/test_litellm/router_utils/test_reasoning_effort_capability.py@@ -85,6 +85,25 @@ class TestResolveSupportedReasoningEfforts:)assert resolved == ("none", "minimal", "low", "medium", "high")+ def test_per_level_flag_without_supports_reasoning_treats_as_implicit_true(self):+ resolved = resolve_supported_reasoning_efforts(+ {+ "supports_minimal_reasoning_effort": True,+ },+ deployment_is_mapped=True,+ )+ assert resolved == ("none", "minimal", "low", "medium", "high")++ def test_explicit_supports_reasoning_false_wins_over_per_level_flags(self):+ resolved = resolve_supported_reasoning_efforts(+ {+ "supports_reasoning": False,+ "supports_minimal_reasoning_effort": True,+ },+ deployment_is_mapped=True,+ )+ assert resolved == ()+class TestBareModelNameFallback:def test_a_prefixed_entry_inherits_the_flags_of_its_unprefixed_twin(self):