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): strip @version suffix in _model_map_lookup_candidates (#32833)
Mateo Wang4baf326a39e7
diff --git a/litellm/llms/anthropic/common_utils.py b/litellm/llms/anthropic/common_utils.pyindex db540e5441d..964186fd76a 100644--- a/litellm/llms/anthropic/common_utils.py+++ b/litellm/llms/anthropic/common_utils.py@@ -289,6 +289,13 @@ class AnthropicModelInfo(BaseLLMModelInfo):status_code=400,)+ @staticmethod+ def _strip_version_suffix(model: str) -> str:+ at = model.rfind("@")+ if at > 0:+ return model[:at]+ return model+@staticmethoddef _model_map_lookup_candidates(model: str) -> List[str]:"""Model-map keys to try for ``model``: the id itself, the same id with a@@ -324,6 +331,7 @@ class AnthropicModelInfo(BaseLLMModelInfo):_DATED_RELEASE_SUFFIX_RE.sub("", cand),_DOTTED_VERSION_RE.sub(r"\1-\2", cand),_strip_bedrock_id_suffixes(cand),+ AnthropicModelInfo._strip_version_suffix(cand),))return list(dict.fromkeys((*primary, *normalized)))diff --git a/tests/test_litellm/llms/anthropic/test_anthropic_common_utils.py b/tests/test_litellm/llms/anthropic/test_anthropic_common_utils.pyindex a2fbb68bbb9..f7a234c8ae8 100644--- a/tests/test_litellm/llms/anthropic/test_anthropic_common_utils.py+++ b/tests/test_litellm/llms/anthropic/test_anthropic_common_utils.py@@ -772,7 +772,6 @@ class TestProxyOAuthHeaderForwarding:self,):"""OAuth Authorization header IS forwarded when x-litellm-api-key was used for proxy auth."""- from unittest.mock import patchfrom starlette.datastructures import Headers@@ -1724,3 +1723,48 @@ class TestClaudeOpus48AdaptiveThinking:from litellm.llms.anthropic.common_utils import AnthropicModelInfoassert AnthropicModelInfo._is_adaptive_thinking_model(model) is False+++class TestDefaultSuffixAdaptiveThinking:+ """@default-suffixed Vertex AI model names (e.g. vertex_ai/claude-opus-4-8@default)+ must resolve as adaptive thinking. Before the fix, _model_map_lookup_candidates+ never stripped the @default suffix, so the lookup fell through to the bare+ model name without @default, which may or may not have the flag, and for+ provider-prefixed forms the lookup always missed (issue #31760)."""++ @pytest.mark.parametrize(+ "model",+ [+ "vertex_ai/claude-opus-4-8@default",+ "vertex_ai/claude-sonnet-4-6@default",+ "vertex_ai/claude-opus-4-7@default",+ "vertex_ai/claude-opus-4-6@default",+ "vertex_ai/claude-fable-5@default",+ ],+ )+ def test_default_suffix_models_are_adaptive_thinking(+ self, local_model_cost_map, model: str+ ) -> None:+ from litellm.llms.anthropic.common_utils import AnthropicModelInfo++ assert AnthropicModelInfo._is_adaptive_thinking_model(model) is True, (+ f"{model} not classified as adaptive thinking. "+ "Check _model_map_lookup_candidates strips @default suffix."+ )++ @pytest.mark.parametrize(+ "model,expected_bare",+ [+ ("vertex_ai/claude-opus-4-8@default", "claude-opus-4-8"),+ ("vertex_ai/claude-sonnet-4-6@default", "claude-sonnet-4-6"),+ ],+ )+ def test_lookup_candidates_include_bare_name(+ self, model: str, expected_bare: str+ ) -> None:+ from litellm.llms.anthropic.common_utils import AnthropicModelInfo++ candidates = AnthropicModelInfo._model_map_lookup_candidates(model)+ assert expected_bare in candidates, (+ f"Expected '{expected_bare}' in candidates for '{model}', got: {candidates}"+ )