Litellm day 0 opus 4.7 support#25867
Conversation
…on Messages API Bedrock rejects clear_thinking_20251015 unless thinking is enabled or adaptive. Inject minimal extended thinking and interleaved-thinking beta when Claude Code sends context_management without thinking. Adds unit tests. Made-with: Cursor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryThis PR adds day-0 support for Claude Opus 4.7 across Anthropic, Bedrock (Converse + Invoke/Messages), Vertex AI, and Azure AI providers, including new pricing/capability entries in the model map, adaptive thinking handling, and correctly excluding tool-search on Bedrock Invoke for this model.
Confidence Score: 4/5Safe to merge after addressing the One P1 finding: litellm/llms/anthropic/chat/transformation.py —
|
| Filename | Overview |
|---|---|
| litellm/llms/anthropic/chat/transformation.py | Adds _is_opus_4_7_model() and _is_claude_4_7_model() helpers and wires them into reasoning-effort mapping and output_config routing; effort='max' guard remains hardcoded against Opus 4.6 instead of using the data-driven _supports_effort_level pattern already used for xhigh. |
| litellm/llms/anthropic/common_utils.py | Adds _is_claude_4_7_model() and _is_adaptive_thinking_model() string-match helpers; wires Opus 4.7 into beta-header logic. Hardcoded pattern is consistent with the existing 4.6 approach; correctness looks sound. |
| litellm/llms/bedrock/messages/invoke_transformations/anthropic_claude3_transformation.py | Correctly excludes Opus 4.7 from _supports_tool_search_on_bedrock with an explanatory comment; strips output_config for all Bedrock Invoke calls; extends extended-thinking model list to include Opus 4.7. |
| litellm/llms/bedrock/chat/converse_transformation.py | Silently drops tool_search_tool_* tools for all Converse models; adds Opus 4.7 to the computer-use-2025-11-24 beta-header list. Changes look correct. |
| model_prices_and_context_window.json | Adds Opus 4.7 entries for anthropic, bedrock (cross-region prefixes), vertex_ai, and azure_ai with correct pricing and capability flags; supports_xhigh_reasoning_effort: true is set. Missing supports_max_reasoning_effort (intentional — max is Opus 4.6-only). |
| tests/test_litellm/llms/bedrock/messages/invoke_transformations/test_anthropic_claude3_transformation.py | Adds mock-only tests for output_config stripping, SSE usage promotion, and clear_thinking injection; all tests are unit-level with no real network calls. No new Opus 4.7-specific test for tool-search exclusion. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[User sends request with reasoning_effort or thinking] --> B{Model is Opus 4.7?}
B -- Yes --> C[_map_reasoning_effort → type=adaptive]
B -- No --> D[_map_reasoning_effort → type=enabled + budget_tokens]
C --> E[Set output_config.effort via effort_map]
E --> F{effort == max?}
F -- Yes --> G[❌ ValueError: max is Opus 4.6 only]
F -- No --> H{effort == xhigh?}
H -- Yes --> I{_supports_effort_level via JSON?}
I -- No --> J[❌ ValueError: xhigh not supported]
I -- Yes --> K[Apply output_config to request]
H -- No --> K
K --> L{Provider?}
L -- Anthropic Direct --> M[Send with output_config]
L -- Bedrock Invoke --> N[Strip output_config step 5b]
L -- Bedrock Converse --> O[Pass through normally]
P[Tool search tools in request] --> Q{Provider?}
Q -- Bedrock Converse --> R[Strip tool_search_tool_* for ALL models]
Q -- Bedrock Invoke Opus 4.7 --> S[_supports_tool_search_on_bedrock → false]
Q -- Bedrock Invoke Opus 4.5/4.6 --> T[Add tool-search-tool-2025-10-19 beta header]
Reviews (2): Last reviewed commit: "Remove max support for opus 4.7" | Re-trigger Greptile
44c9924
into
litellm_internal_staging
| # ``max`` is Claude Opus 4.6 only (not Sonnet 4.6, not Opus 4.5/4.7). | ||
| # Keep this hardcoded so the error message is specific and stable. | ||
| if effort == "max" and not self._is_opus_4_6_model(model): | ||
| raise ValueError( | ||
| f"effort='max' is only supported by Claude Opus 4.6. Got model: {model}" | ||
| f"effort='max' is only supported by Claude Opus 4.6. " | ||
| f"Got model: {model}" | ||
| ) | ||
| # ``xhigh`` is data-driven via ``supports_xhigh_reasoning_effort`` so | ||
| # enabling it for a new model is a pure model-map change. | ||
| if effort == "xhigh" and not self._supports_effort_level(model, "xhigh"): |
There was a problem hiding this comment.
max effort check is hardcoded while xhigh is data-driven
effort='max' is validated with a hardcoded _is_opus_4_6_model() string match, while effort='xhigh' directly below uses _supports_effort_level(model, "xhigh") — exactly the pattern the project rule requires. The JSON schema already declares supports_max_reasoning_effort as a valid boolean field (see test_utils.py line 774). Any future model that supports max will require a code change here rather than a simple model-map addition.
The fix is a two-line change:
- Add
"supports_max_reasoning_effort": trueto theclaude-opus-4-6(and its regional/versioned) JSON entries. - Replace the hardcoded gate:
| # ``max`` is Claude Opus 4.6 only (not Sonnet 4.6, not Opus 4.5/4.7). | |
| # Keep this hardcoded so the error message is specific and stable. | |
| if effort == "max" and not self._is_opus_4_6_model(model): | |
| raise ValueError( | |
| f"effort='max' is only supported by Claude Opus 4.6. Got model: {model}" | |
| f"effort='max' is only supported by Claude Opus 4.6. " | |
| f"Got model: {model}" | |
| ) | |
| # ``xhigh`` is data-driven via ``supports_xhigh_reasoning_effort`` so | |
| # enabling it for a new model is a pure model-map change. | |
| if effort == "xhigh" and not self._supports_effort_level(model, "xhigh"): | |
| if effort == "max" and not self._supports_effort_level(model, "max"): | |
| raise ValueError( | |
| f"effort='max' is not supported by this model. Got model: {model}" | |
| ) |
Rule Used: What: Do not hardcode model-specific flags in the ... (source)
Litellm day 0 opus 4.7 support
Litellm day 0 opus 4.7 support
Anthropic's Messages API accepts `output_config.effort="max"` on `claude-opus-4-7-*` models, but `_apply_output_config` hardcoded the gate to `_is_opus_4_6_model`, so any request hitting LiteLLM with Opus 4.7 + effort=max was rejected with a 400 before reaching Anthropic. This was preserved on purpose in BerriAI#25867 (day-0 4.7 PR) under the old assumption that `max` was Opus-4.6-only. The Anthropic API has since extended `max` support to Opus 4.7. Allow the effort=max guard to also accept Opus 4.7. Update the two existing rejection tests to match the new error message and add a new regression test for Opus 4.7. Fixes BerriAI#25957
Anthropic's Messages API accepts `output_config.effort="max"` on `claude-opus-4-7-*` models, but `_apply_output_config` hardcoded the gate to `_is_opus_4_6_model`, so any request hitting LiteLLM with Opus 4.7 + effort=max was rejected with a 400 before reaching Anthropic. This was preserved on purpose in BerriAI#25867 (day-0 4.7 PR) under the old assumption that `max` was Opus-4.6-only. The Anthropic API has since extended `max` support to Opus 4.7. Allow the effort=max guard to also accept Opus 4.7. Update the two existing rejection tests to match the new error message and add a new regression test for Opus 4.7. Fixes BerriAI#25957
Anthropic's Messages API accepts `output_config.effort="max"` on `claude-opus-4-7-*` models, but `_apply_output_config` hardcoded the gate to `_is_opus_4_6_model`, so any request hitting LiteLLM with Opus 4.7 + effort=max was rejected with a 400 before reaching Anthropic. This was preserved on purpose in BerriAI#25867 (day-0 4.7 PR) under the old assumption that `max` was Opus-4.6-only. The Anthropic API has since extended `max` support to Opus 4.7. Allow the effort=max guard to also accept Opus 4.7. Update the two existing rejection tests to match the new error message and add a new regression test for Opus 4.7. Fixes BerriAI#25957
Litellm day 0 opus 4.7 support
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
Changes