Skip to content

Litellm hotfix opus 4.7 - #25876

Merged
ishaan-berri merged 2 commits into
mainfrom
litellm_hotfix_opus_4.7
Apr 16, 2026
Merged

Litellm hotfix opus 4.7#25876
ishaan-berri merged 2 commits into
mainfrom
litellm_hotfix_opus_4.7

Conversation

@Sameerlite

Copy link
Copy Markdown
Contributor

Relevant issues

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have Added testing in the tests/test_litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem
  • I have requested a Greptile review by commenting @greptileai and received a Confidence Score of at least 4/5 before requesting a maintainer review

Delays 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)

CI status guideline:

  • 50-55 passing tests: main is stable with minor issues.
  • 45-49 passing tests: acceptable but needs attention
  • <= 40 passing tests: unstable; be careful with your merges and assess the risk.
  • 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

@vercel

vercel Bot commented Apr 16, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
litellm Ready Ready Preview, Comment Apr 16, 2026 5:22pm

Request Review

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ Sameerlite
❌ ishaan-berri
You have signed the CLA already but the status is still pending? Let us recheck it.

@codspeed-hq

codspeed-hq Bot commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 16 untouched benchmarks


Comparing litellm_hotfix_opus_4.7 (fe6fef9) with main (72a461b)

Open in CodSpeed

from litellm.utils import (
ModelResponse,
Usage,
_supports_factory,
@greptile-apps

greptile-apps Bot commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This 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 output_config.effort (adaptive thinking) rather than the legacy thinking.budget_tokens API.

Confidence Score: 5/5

Safe 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)

Important Files Changed

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
Loading

Comments Outside Diff (2)

  1. litellm/llms/anthropic/chat/transformation.py, line 237-248 (link)

    P2 _is_claude_4_7_model check is redundant here

    claude-opus-4-7 has supports_reasoning: true in model_prices_and_context_window.json, so the or supports_reasoning(...) branch at lines 241–244 already covers it. The explicit _is_claude_4_7_model guard 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)

  2. litellm/llms/bedrock/common_utils.py, line 565-597 (link)

    P2 Function name no longer matches its scope

    is_claude_4_5_on_bedrock now 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 like is_modern_claude_on_bedrock (or is_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

Comment on lines +193 to +199
@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")
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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)

Comment on lines +259 to +271
@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",
)
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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)

@ishaan-berri
ishaan-berri merged commit c0fc4c4 into main Apr 16, 2026
104 of 110 checks passed
@ishaan-berri
ishaan-berri deleted the litellm_hotfix_opus_4.7 branch April 16, 2026 19:19
fzowl pushed a commit to fzowl/litellm that referenced this pull request Jun 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants