Litellm hotfix opus 4.7 - #25876
Conversation
Litellm day 0 opus 4.7 support
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
|
| from litellm.utils import ( | ||
| ModelResponse, | ||
| Usage, | ||
| _supports_factory, |
Greptile SummaryThis PR adds day-0 support for Claude Opus 4.7 across the Anthropic direct provider, Bedrock (Converse and Invoke/Messages), Vertex AI, and Azure AI, along with model pricing and context-window entries. It mirrors the existing Opus 4.6 adaptive-thinking path — the new model uses Confidence Score: 5/5Safe to merge; all findings are style/maintenance P2 concerns with no correctness issues. No P0 or P1 issues found. The adaptive-thinking and effort-mapping logic for Opus 4.7 mirrors the correct Opus 4.6 path. Model-map entries are present and consistent. Remaining findings (duplicate method, redundant guard, misleading function name, hardcoded model detection) are all P2 style improvements. litellm/llms/anthropic/chat/transformation.py (duplicate _is_opus_4_7_model and redundant guard in get_supported_openai_params); litellm/llms/bedrock/common_utils.py (misleading function name is_claude_4_5_on_bedrock)
|
| Filename | Overview |
|---|---|
| litellm/llms/anthropic/chat/transformation.py | Adds _is_opus_4_7_model (duplicate of inherited _is_claude_4_7_model) and wires 4.7 into adaptive-thinking paths; _is_claude_4_7_model in get_supported_openai_params is redundant since supports_reasoning() already covers it. |
| litellm/llms/anthropic/common_utils.py | Adds _is_claude_4_7_model (hardcoded string list) and extends _is_adaptive_thinking_model to include 4.7; follows the same pattern as _is_claude_4_6_model but still a hardcoded model flag per rule 2605a1b1. |
| litellm/llms/bedrock/common_utils.py | Extends is_claude_4_5_on_bedrock() with 4.7 patterns; function name is now misleading since it covers 4.5, 4.6, and 4.7 models. |
| litellm/llms/bedrock/chat/converse_transformation.py | Correctly adds Opus 4.7 patterns to the computer-use-2025-11-24 beta header selection block for Bedrock Converse. |
| litellm/llms/bedrock/messages/invoke_transformations/anthropic_claude3_transformation.py | Adds Opus 4.7 to _supports_extended_thinking_on_bedrock; correctly excludes Opus 4.7 from the tool-search beta block with an explanatory comment. |
| model_prices_and_context_window.json | Adds claude-opus-4-7 entries for Anthropic direct, Bedrock (anthropic., us., eu., au., global. prefixes), Vertex AI, and Azure AI with correct pricing and capability flags including supports_xhigh_reasoning_effort. |
| tests/test_litellm/test_utils.py | Adds supports_xhigh_reasoning_effort to the model-prices JSON schema validation; no Opus 4.7-specific behavior test added. |
| tests/test_litellm/llms/bedrock/messages/invoke_transformations/test_anthropic_claude3_transformation.py | Existing tests unchanged; no new Opus 4.7 test covering adaptive thinking or xhigh effort added. |
| litellm/setup_wizard.py | Adds claude-opus-4-7 to the Anthropic provider model list and updates the description string. |
| litellm/llms/anthropic/experimental_pass_through/messages/transformation.py | Relies on _is_adaptive_thinking_model which now covers 4.7; docstring updated to mention 4.6/4.7; no logic change required. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[reasoning_effort param] --> B{_is_claude_4_6_model\nor _is_claude_4_7_model?}
B -- Yes --> C[thinking = adaptive\noutput_config = effort_map value]
B -- No --> D{effort value}
D -- low/minimal --> E[thinking = enabled\nbudget=1024]
D -- medium --> F[thinking = enabled\nbudget=2048]
D -- high --> G[thinking = enabled\nbudget=4096]
C --> H[_apply_output_config]
H --> I{effort == max?}
I -- Yes, not Opus 4.6 --> J[ValueError]
I -- No OR Opus 4.6 --> K{effort == xhigh?}
K -- not in model map --> L[ValueError]
K -- supported --> M[Request sent]
E & F & G --> M
Comments Outside Diff (2)
-
litellm/llms/anthropic/chat/transformation.py, line 237-248 (link)_is_claude_4_7_modelcheck is redundant hereclaude-opus-4-7hassupports_reasoning: trueinmodel_prices_and_context_window.json, so theor supports_reasoning(...)branch at lines 241–244 already covers it. The explicit_is_claude_4_7_modelguard on line 240 is dead code under any recognised 4.7 model name — adding per-version checks here is exactly what rule 2605a1b1 aims to prevent.Rule Used: What: Do not hardcode model-specific flags in the ... (source)
-
litellm/llms/bedrock/common_utils.py, line 565-597 (link)Function name no longer matches its scope
is_claude_4_5_on_bedrocknow covers 4.5, 4.6, and 4.7 model families. The name and docstring ("Claude 4.5 models support prompt caching with '5m' and '1h' TTL") are misleading to any caller. Consider renaming to something likeis_modern_claude_on_bedrock(oris_claude_4_5_plus_on_bedrock) and updating the docstring to reflect the full list of covered generations.
Reviews (1): Last reviewed commit: "Fix version in docs" | Re-trigger Greptile
| @staticmethod | ||
| def _is_opus_4_7_model(model: str) -> bool: | ||
| """Check if the model is specifically Claude Opus 4.7.""" | ||
| model_lower = model.lower() | ||
| return any( | ||
| v in model_lower for v in ("opus-4-7", "opus_4_7", "opus-4.7", "opus_4.7") | ||
| ) |
There was a problem hiding this comment.
Duplicate static method already inherited from
AnthropicModelInfo
_is_opus_4_7_model is byte-for-byte identical to the _is_claude_4_7_model method defined in AnthropicModelInfo (which AnthropicConfig already inherits). Every call site in this file that uses _is_opus_4_7_model could instead call _is_claude_4_7_model, matching the pattern used for _is_opus_4_6_model / _is_claude_4_6_model.
Rule Used: What: Do not hardcode model-specific flags in the ... (source)
| @staticmethod | ||
| def _is_claude_4_7_model(model: str) -> bool: | ||
| """Check if the model is a Claude 4.7 model (Opus 4.7).""" | ||
| model_lower = model.lower() | ||
| return any( | ||
| v in model_lower | ||
| for v in ( | ||
| "opus-4-7", | ||
| "opus_4_7", | ||
| "opus-4.7", | ||
| "opus_4.7", | ||
| ) | ||
| ) |
There was a problem hiding this comment.
Hardcoded model-name detection — consider a model-map flag
_is_claude_4_7_model (and the analogous _is_opus_4_7_model in transformation.py) detect the adaptive-thinking API by string-matching the model name. Per rule 2605a1b1, the preferred approach is to add a capability flag to model_prices_and_context_window.json (e.g. "supports_adaptive_thinking": true) and read it with _supports_factory / get_model_info, so that a future model that supports the same API path "just works" without a code change. The supports_xhigh_reasoning_effort flag added in this same PR is a good example of the preferred pattern.
Rule Used: What: Do not hardcode model-specific flags in the ... (source)
Litellm hotfix opus 4.7
Relevant issues
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/test_litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unit@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewDelays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
CI (LiteLLM team)
Branch creation CI run
Link:
CI run for the last commit
Link:
Merge / cherry-pick CI run
Links:
Screenshots / Proof of Fix
Type
🆕 New Feature
🐛 Bug Fix
🧹 Refactoring
📖 Documentation
🚄 Infrastructure
✅ Test
Changes