Add Claude Opus 4.8 support
Merged
DS
6mo ago+269+269+012345678901234567890123456789-54-54-01234567890123456789
No issue; this is a compatibility update for Anthropic Claude Opus 4.8, which launched on 2026-05-28 (release notes, what's new). Anthropic's migration guide confirms the API contract is unchanged from Opus 4.7, so this PR mirrors the existing 4.7 dispatch sites onto claude-opus-4-8.
Changes
- add
claude-opus-4-8toAnthropicModelNameandKnownModelName(bothanthropic:andgateway/anthropic:). TheanthropicSDK pin (0.97.0) still predates the release that lists 4.8 inModelParam, so the literal is added via a localLiteral['claude-opus-4-8']bridge with a comment to drop it once the pin moves past the SDK version that ships it - extend every
claude-opus-4-7profile branch inpydantic_ai_slim/pydantic_ai/profiles/anthropic.pyto also match 4.8: adaptive thinking,xhigheffort, sampling-param rejection, budget-thinking rejection, task budgets, tool search, JSON schema output, and thecode_execution_20260120default version - extend
anthropic_supports_fast_speedto('claude-opus-4-6', 'claude-opus-4-7', 'claude-opus-4-8')per Anthropic's fast mode docs - defensively add
claude-opus-4-8tobedrock_structured_output_unsupportedmatching the 4.7 precedent; AWS Bedrock structured-output docs have not yet listed Opus 4.8 - surface Anthropic's now-publicly-documented refusal
stop_detailsonModelResponse.provider_details:explanation→provider_details['refusal'](matches the OpenAI shape) andcategory→provider_details['refusal_category']. Applied in both_process_responseand the streaming path - parametrize the existing
_opus_47_*unit tests over[claude-opus-4-7, claude-opus-4-8]so both model ids exercise the shared profile-driven behaviour, and parametrize theanthropic_model_profilecapability assertion intests/test_thinking.pythe same way - record
test_anthropic_opus_48_featureslive against the Anthropic API to lock in the 4.8 adaptive-thinking +xhigheffort request shape (tests/models/cassettes/test_anthropic/test_anthropic_opus_48_features.yaml) - update
docs/models/anthropic.mdanddocs/thinking.mdso the migration callout, fast-mode support list, task-budget gating, and adaptive-thinking notes name 4.8 alongside 4.7
Not in this PR (tracked separately)
- Mid-conversation system messages — Anthropic's new role placement inside the
messagesarray, Opus 4.8-only and Claude API only. Net-new public API shape; out of scope for this compatibility PR. Tracked in #5706 - Refusal
stop_detailsmapping is included here because it applies to every Anthropic model that emits the field (4.7+) and was a simple two-place surface; the Opus 4.8 launch entry is what triggered the public documentation output-300k-2026-03-24extended-output beta — PAI has no existing handler for this beta; adding it would be a new feature, not an extension. Will track separately if needed
Checklist
- Any AI generated code has been reviewed line-by-line by the human PR author, who stands by it.
- No breaking changes in accordance with the version policy.
- PR title is fit for the release changelog.