Drop Anthropic sampling settings when the client sends API version `2026-10-21`, the `anthropic>=2` default

Merged
DO
9d ago
+126-1

Supersedes #14356, by @adar2378. His commit is cherry-picked here with his authorship, so this PR can run CI.

anthropic>=2 sends anthropic-version: 2026-10-21 by default. On that API version, Anthropic rejects temperature, top_p and top_k on every model. Pydantic AI only dropped them for models whose profile sets anthropic_disallows_sampling_settings (Opus 4.7+ and Claude 5). So Sonnet 4.6, Haiku 4.5 and the other older models returned a 400 whenever temperature was set.

Change (adar2378's commit): AnthropicModel reads anthropic-version from the client's default headers, in any capitalization. When it is 2026-10-21 or later, the sampling settings are dropped for every model, with the existing warning. The legacy AsyncAnthropicBedrock client is skipped because Pydantic AI pins its body anthropic_version to bedrock-2023-05-31. Clients that send the header (AsyncAnthropic, Foundry, Bedrock Mantle) are covered.

Docs (my commit): docs/models/anthropic.md said the older models take temperature, top_p and top_k. It now explains the API version, and how to keep the settings on anthropic>=2 by setting the header to 2023-06-01 on the client.

Verified live (2026-11-24, anthropic 2.10.0, temperature=0):

Casemainthis PR
Direct API, SDK default 2026-10-21, claude-sonnet-4-6 / claude-haiku-4-5400 temperature: Extra inputs are not permitted200, setting dropped with the warning
Direct API, header 2023-06-01200200, setting kept
Legacy Bedrock (AsyncAnthropicBedrock), claude-sonnet-4-6200200, setting kept
claude-opus-4-8200, dropped (profile flag)unchanged

On anthropic 1.15.0 (which sends 2023-06-01), all three models accept the setting, so nothing changes for users on the locked SDK.

Not covered: Vertex AI sends the API version in the request body, and on anthropic>=2 that's also 2026-10-21. Whether Vertex rejects the sampling settings is unverified: our GCP project has no Claude model access (404 in every region tried). So Vertex keeps today's behavior.

Checklist

  • No breaking changes in accordance with the version policy.
  • Any permitted compatibility impact has a label, warning, migration and release note, and an exact API-check waiver if the gate reports it.
  • PR title is fit for the release changelog.

šŸ¤– Generated with Claude Code


Summary by cubic

Fixes 400 errors on Anthropic models when using anthropic>=2, which sends API version 2026-10-21 by default. That API version rejects temperature, top_p, and top_k on every model, so AnthropicModel now reads the anthropic-version header and drops sampling settings for all models when it's 2026-10-21 or later, with the existing warning. Previously they were only dropped for models with anthropic_disallows_sampling_settings (Opus 4.7+ and Claude 5).

  • A per-request extra_headers anthropic-version value overrides the client's default header.
  • The legacy AsyncAnthropicBedrock client is unaffected since its request body pins anthropic_version to bedrock-2023-05-31.
  • Docs now explain how to keep sampling settings on anthropic>=2 by setting the header to 2023-06-01 on the client.

Closes #14352.