Add Claude Opus 4.8 support

Merged
DS
6mo ago
+269-54

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-8 to AnthropicModelName and KnownModelName (both anthropic: and gateway/anthropic:). The anthropic SDK pin (0.97.0) still predates the release that lists 4.8 in ModelParam, so the literal is added via a local Literal['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-7 profile branch in pydantic_ai_slim/pydantic_ai/profiles/anthropic.py to also match 4.8: adaptive thinking, xhigh effort, sampling-param rejection, budget-thinking rejection, task budgets, tool search, JSON schema output, and the code_execution_20260120 default version
  • extend anthropic_supports_fast_speed to ('claude-opus-4-6', 'claude-opus-4-7', 'claude-opus-4-8') per Anthropic's fast mode docs
  • defensively add claude-opus-4-8 to bedrock_structured_output_unsupported matching the 4.7 precedent; AWS Bedrock structured-output docs have not yet listed Opus 4.8
  • surface Anthropic's now-publicly-documented refusal stop_details on ModelResponse.provider_details: explanation → provider_details['refusal'] (matches the OpenAI shape) and category → provider_details['refusal_category']. Applied in both _process_response and 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 the anthropic_model_profile capability assertion in tests/test_thinking.py the same way
  • record test_anthropic_opus_48_features live against the Anthropic API to lock in the 4.8 adaptive-thinking + xhigh effort request shape (tests/models/cassettes/test_anthropic/test_anthropic_opus_48_features.yaml)
  • update docs/models/anthropic.md and docs/thinking.md so 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 messages array, 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_details mapping 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-24 extended-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.