Add Claude Opus 4.7 support#5118
Conversation
|
Claude here: follow-up PR scope for Anthropic task budget support:
I split this out from #5118 to keep the first PR focused on bare Opus 4.7 compatibility and SDK support, without mixing in a new beta surface area. |
| assert exc_info.value.status_code == 400 | ||
| assert exc_info.value.model_name == 'claude-opus-4-6' | ||
| assert len(vcr.requests) == 1 | ||
| request_body = json.loads(vcr.requests[0].body) | ||
| assert request_body['model'] == 'claude-opus-4-6' | ||
| assert request_body['output_config'] == {'effort': 'xhigh'} |
There was a problem hiding this comment.
this is def not acceptable/relevant/necessary lol, I'd prefer snapshotting the exception
| request_body = json.loads(vcr.requests[0].body) | ||
| assert request_body['output_config'] == {'effort': 'xhigh'} |
There was a problem hiding this comment.
this part remains unnecessary, doesn't add any new information (the snapshot shows the effort level sent)
|
|
||
|
|
||
| async def test_anthropic_opus_47_drops_sampling_settings(allow_model_requests: None): | ||
| from anthropic._types import omit as OMIT |
There was a problem hiding this comment.
no inline imports, imports go at the top behind an import gate
| supports_json_schema_output = model_name.startswith(models_that_support_json_schema_output) | ||
|
|
||
| # Sonnet 4.6+ and Opus 4.6+ support adaptive thinking; older models use budget-based | ||
| supports_adaptive = model_name.startswith(('claude-sonnet-4-6', 'claude-opus-4-6')) | ||
| supports_adaptive = model_name.startswith(('claude-sonnet-4-6', 'claude-opus-4-6', 'claude-opus-4-7')) | ||
|
|
||
| # Opus 4.5+ and Sonnet 4.6+ support the effort parameter in output_config | ||
| supports_effort = model_name.startswith(('claude-opus-4-5', 'claude-opus-4-6', 'claude-sonnet-4-6')) | ||
| supports_effort = model_name.startswith( | ||
| ('claude-opus-4-5', 'claude-opus-4-6', 'claude-opus-4-7', 'claude-sonnet-4-6') | ||
| ) | ||
| supports_xhigh_effort = model_name.startswith('claude-opus-4-7') | ||
| disallows_budget_thinking = model_name.startswith('claude-opus-4-7') | ||
| disallows_sampling_settings = model_name.startswith('claude-opus-4-7') |
There was a problem hiding this comment.
🚩 claude-mythos-preview gets conservative default profile — may need capability flags
The new claude-mythos-preview model is added to KnownModelName but has no special handling in anthropic_model_profile() (pydantic_ai_slim/pydantic_ai/profiles/anthropic.py:61-87). It won't match any startswith tuple, so it gets: supports_json_schema_output=False, supports_adaptive=False, supports_effort=False, and all disallows_*=False. This is a safe conservative default, but if claude-mythos-preview is actually a frontier model with these capabilities, users would need to manually configure a profile override. Worth verifying what capabilities this model actually has.
(Refers to lines 61-87)
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
valid to point out, but would be in a follow up PR
mythos usage/adoption is gated currently
There was a problem hiding this comment.
yeah we don't know anything about it
| AnthropicModelName = str | LatestAnthropicModelNames | ||
| LegacyAnthropicModelNames = Literal[ | ||
| 'claude-3-5-haiku-20241022', | ||
| 'claude-3-5-haiku-latest', | ||
| 'claude-3-7-sonnet-20250219', | ||
| 'claude-3-7-sonnet-latest', | ||
| 'claude-3-opus-20240229', | ||
| 'claude-3-opus-latest', | ||
| 'claude-4-opus-20250514', | ||
| 'claude-4-sonnet-20250514', | ||
| ] | ||
| """Anthropic model names we continue to support beyond the SDK's latest literal set.""" | ||
|
|
||
| AnthropicModelName = str | LatestAnthropicModelNames | LegacyAnthropicModelNames |
| `{'type': 'enabled', 'budget_tokens': ...}`. | ||
| """ | ||
|
|
||
| anthropic_disallows_sampling_settings: bool = False |
There was a problem hiding this comment.
Why use _disallows_ here rather than supports as everywhere else?
| supports_json_schema_output = model_name.startswith(models_that_support_json_schema_output) | ||
|
|
||
| # Sonnet 4.6+ and Opus 4.6+ support adaptive thinking; older models use budget-based | ||
| supports_adaptive = model_name.startswith(('claude-sonnet-4-6', 'claude-opus-4-6')) | ||
| supports_adaptive = model_name.startswith(('claude-sonnet-4-6', 'claude-opus-4-6', 'claude-opus-4-7')) | ||
|
|
||
| # Opus 4.5+ and Sonnet 4.6+ support the effort parameter in output_config | ||
| supports_effort = model_name.startswith(('claude-opus-4-5', 'claude-opus-4-6', 'claude-sonnet-4-6')) | ||
| supports_effort = model_name.startswith( | ||
| ('claude-opus-4-5', 'claude-opus-4-6', 'claude-opus-4-7', 'claude-sonnet-4-6') | ||
| ) | ||
| supports_xhigh_effort = model_name.startswith('claude-opus-4-7') | ||
| disallows_budget_thinking = model_name.startswith('claude-opus-4-7') | ||
| disallows_sampling_settings = model_name.startswith('claude-opus-4-7') |
There was a problem hiding this comment.
yeah we don't know anything about it
| Anthropic's [Claude Opus 4.7 migration guide](https://platform.claude.com/docs/en/about-claude/models/migration-guide) recommends removing `temperature`, `top_p`, and `top_k` from Opus 4.7 requests. Pydantic AI drops those keys automatically for `claude-opus-4-7`, including `extra_body` overrides. | ||
|
|
||
| The same guide also recommends re-evaluating `max_tokens` and any token-count assumptions when migrating from Opus 4.6, since Opus 4.7 uses updated tokenization. If you rely on `count_tokens()` or `count_tokens_before_request`, verify your thresholds against the new model. |
There was a problem hiding this comment.
🟡 Migration note uses plain backticks for pydantic-ai API elements instead of mkdocs reference links
The new "Claude Opus 4.7 migration" note at docs/models/anthropic.md:45-48 mentions several pydantic-ai API elements (count_tokens(), count_tokens_before_request, max_tokens, temperature, top_p, extra_body) using plain backticks instead of mkdocs reference-style links. This violates the mandatory rule in docs/.cursor/rules.mdc: "Always reference the python code in the docs e.g. ModelSettings should link to [ModelSettings][pydantic_ai.settings.ModelSettings]." At minimum, count_tokens() should link to [count_tokens()][pydantic_ai.models.Model.count_tokens] and count_tokens_before_request should link to [count_tokens_before_request][pydantic_ai.usage.UsageLimits.count_tokens_before_request].
| Anthropic's [Claude Opus 4.7 migration guide](https://platform.claude.com/docs/en/about-claude/models/migration-guide) recommends removing `temperature`, `top_p`, and `top_k` from Opus 4.7 requests. Pydantic AI drops those keys automatically for `claude-opus-4-7`, including `extra_body` overrides. | |
| The same guide also recommends re-evaluating `max_tokens` and any token-count assumptions when migrating from Opus 4.6, since Opus 4.7 uses updated tokenization. If you rely on `count_tokens()` or `count_tokens_before_request`, verify your thresholds against the new model. | |
| Anthropic's [Claude Opus 4.7 migration guide](https://platform.claude.com/docs/en/about-claude/models/migration-guide) recommends removing [`temperature`][pydantic_ai.settings.ModelSettings.temperature], [`top_p`][pydantic_ai.settings.ModelSettings.top_p], and `top_k` from Opus 4.7 requests. Pydantic AI drops those keys automatically for `claude-opus-4-7`, including [`extra_body`][pydantic_ai.settings.ModelSettings.extra_body] overrides. | |
| The same guide also recommends re-evaluating [`max_tokens`][pydantic_ai.settings.ModelSettings.max_tokens] and any token-count assumptions when migrating from Opus 4.6, since Opus 4.7 uses updated tokenization. If you rely on [`count_tokens()`][pydantic_ai.models.Model.count_tokens] or [`count_tokens_before_request`][pydantic_ai.usage.UsageLimits.count_tokens_before_request], verify your thresholds against the new model. |
Was this helpful? React with 👍 or 👎 to provide feedback.
No issue; this is a compatibility update for Anthropic Claude Opus 4.7.
Changes
claude-opus-4-7to the Anthropic and gateway known-model registriesanthropic>=0.96.0and refreshuv.lockxhigheffort supportChecklist