fix(anthropic): cap budget->effort at "high" when model lacks "xhigh" support

_translate_legacy_thinking_for_adaptive_model mapped budget_tokens >= 24000 to
"xhigh" for all adaptive-thinking models. claude-opus-4-6 and claude-sonnet-4-6
support high/medium/low/max but not xhigh, so those requests failed with
"This model does not support effort level 'xhigh'". Only claude-opus-4-7 (and
later models) expose xhigh.

Use AnthropicConfig._supports_effort_level(model, "xhigh") — the same per-model
lookup already used by _validate_effort_for_model — to decide the cap. Fall back
to "high" when xhigh is absent from the model map.

Fixes #27168
This commit is contained in:
PRABHU KIRAN VANDRANKI 2026-05-05 16:16:42 -04:00
parent 850fe595ac
commit a1ce7d9dac

View file

@ -179,9 +179,17 @@ class AnthropicMessagesConfig(BaseAnthropicMessagesConfig):
if not isinstance(thinking, dict) or thinking.get("type") != "enabled":
return
from litellm.llms.anthropic.chat.transformation import AnthropicConfig
budget = int(thinking.get("budget_tokens") or 0)
if budget >= 24000:
effort = "xhigh"
# Only use "xhigh" when the model actually supports it (e.g. claude-opus-4-7).
# claude-opus-4-6 and claude-sonnet-4-6 support high/medium/low/max but not xhigh.
effort = (
"xhigh"
if AnthropicConfig._supports_effort_level(model, "xhigh")
else "high"
)
elif budget >= 10000:
effort = "high"
elif budget >= 5000: