[extra-headers] Merge an `anthropic-beta` header from `extra_headers` with the other Anthropic betas however its name is capitalized

Merged
DS
1mo ago
+820-4

This pull request was posted by Claude Code using claude-opus-5-5 on behalf of David.

Why we make these changes

The Anthropic SDK matches header names case-insensitively, so an anthropic-beta header in a request's extra_headers replaces the one the SDK builds from betas. AnthropicModel already takes a lowercase anthropic-beta out of extra_headers and merges it into the betas it sends. Any other capitalization reached the SDK as-is and dropped every other beta: those from anthropic_betas and the ones Pydantic AI adds itself (Files API, context management, fast mode and so on). Every capitalization now merges the way lowercase does, including its handling of a falsy value: None, or the SDK's omit (both outside the declared dict[str, str]), names no betas and leaves the others in place. Under a non-lowercase name, None used to raise AttributeError and omit used to remove the header.

New public surface

None

User-visible behavior

settings = AnthropicModelSettings(
    anthropic_betas=['interleaved-thinking-2025-05-14'],
    extra_headers={'Anthropic-Beta': 'custom-feature-1'},
)
# before: anthropic-beta: custom-feature-1
# after:  anthropic-beta: custom-feature-1,interleaved-thinking-2025-05-14

Verification

test_anthropic_beta_extra_header_merges_in_any_spelling reads the header off recorded requests through the request_capture fixture, for anthropic-beta, Anthropic-Beta and ANTHROPIC-BETA, each alone, with anthropic_betas, and with no value. On main, the non-lowercase cases with anthropic_betas send only the header's beta, and the non-lowercase cases with no value raise AttributeError.

What changes for existing users

An anthropic-beta header in any capitalization now merges with the other betas, as the lowercase one already did, and batch requests accept one instead of raising UserError.

PR decisions

2026-11-08 · beta header pop in its own method · iter -

2026-11-08 · mock transport over VCR for the wire test · iter -

2026-11-08 · batch accepts any spelling like lowercase · iter -

2026-11-08 · falsy beta header value is skipped · iter -

  • Decision: _pop_beta_headers skips a falsy value (None, SDK omit) with main's walrus guard
  • Why: Verifier regression 1: lowercase None/omit was ignored on main, raised AttributeError on 8858422260
  • Source: local-notes/verifier/repro_nonstr_value.py (local repro, not committed)
  • Session: e7eaeee4-af9e-477b-8cd0-8a99222fb804

2026-11-08 · SDK omit behaves the same in every spelling · iter -

  • Decision: A falsy value (incl. SDK omit) under any spelling of anthropic-beta is skipped, so {'Anthropic-Beta': omit} no longer removes the header; noted in the PR body
  • Why: David accepted option A after stop rule (regression 2): omit is outside dict[str, str] and lowercase omit was always skipped
  • Source: local-notes/siblings/omit_probe.py (local repro, not committed)
  • Session: e7eaeee4-af9e-477b-8cd0-8a99222fb804

2026-11-08 · sibling defects split to a manager-started PR · iter -

  • Decision: Batch User-Agent one-spelling check and client default_headers beta loss stay out of this PR; repros in local-notes/siblings and local-notes/verifier/probe2.py
  • Why: David's call via manager: a separate follow-up PR the manager starts
  • Source: local-notes/siblings/batch_probe.py (local repro, not committed)
  • Session: e7eaeee4-af9e-477b-8cd0-8a99222fb804

2026-11-08 · helper kept after #12833 merged · iter -

  • Decision: Keep AnthropicModel._pop_beta_headers after merging upstream/main a355f7a80e
  • Why: #12833 took _get_betas_and_extra_headers to 13; inlining the any-spelling pop measures 18 > limit 15 (complexity.md 'Extract a method'), helper keeps it at 9
  • Source: https://github.com/pydantic/pydantic-ai/pull/12833
  • Session: e7eaeee4-af9e-477b-8cd0-8a99222fb804
  • Supersedes: beta header pop in its own method

2026-11-08 · pre-push review 1 of 3 at 952c6ca91c7e645a7a795fd3822dc67cc478f5b9 · iter -

2026-11-08 · pre-push review 1 of 3 at 952c6ca91c7e645a7a795fd3822dc67cc478f5b9 · iter -

2026-11-08 · recorded wire test over mock transport · iter -

  • Decision: Test reads the header through the request_capture fixture on recorded cassettes, with real beta names
  • Why: tests/AGENTS.md names request_capture the first reach for outbound headers; cassettes strip anthropic-* so the wire tap is where beta gating is visible
  • Source: https://github.com/pydantic/pydantic-ai/tree/anthropic-beta-header-case/tests/AGENTS.md
  • Session: e7eaeee4-af9e-477b-8cd0-8a99222fb804
  • Supersedes: mock transport over VCR for the wire test

2026-11-08 · exempt delta c69faa1c20 chains from reviewed 952c6ca91c · iter -

  • Decision: Push c69faa1c20 (tree 3793abc5ba) without review 2: review-1 remediation is test code/data plus a docstring-only source change
  • Why: Exempt rows 'test code/data only' (new cassettes, no product wire change; red on main for with-setting non-lowercase) and 'comments or docstrings only' (git diff 952c6ca91c..HEAD -- pydantic_ai_slim is one docstring); budget used 1 of 3
  • Source: https://github.com/pydantic/pydantic-ai/tree/anthropic-beta-header-case
  • Session: e7eaeee4-af9e-477b-8cd0-8a99222fb804

2026-11-08 · merge bar met at c69faa1c20 · iter -

2026-11-09 · cluster:extra-headers · iter -

  • Decision: Label cluster:extra-headers and title prefix '[extra-headers] ' applied together; cluster is #12871, #12875, #12877, #12878
  • Why: David approved the cluster name; the manager created the label (pushing skill 'PR clusters': label and prefix, both or neither)
  • Source: https://github.com/pydantic/pydantic-ai/pull/12875
  • Session: e7eaeee4-af9e-477b-8cd0-8a99222fb804

2026-11-09 · second opinion: none · iter -

2026-11-09 · final metadata check at c69faa1c20 · iter -

  • Decision: Kept: one-sentence 'What changes' (edge cases moved into Why), added labels 'model settings' and 'HTTP'; skipped: label-catalog refresh for cluster:extra-headers
  • Why: Skill 'Write the title and body' item 5 and 'Keep labels current'; catalog refresh belongs to the label's creator, and committing it here restarts CI and douwebot on four cluster PRs; reported to the manager
  • Source: https://github.com/pydantic/pydantic-ai/pull/12875
  • Session: e7eaeee4-af9e-477b-8cd0-8a99222fb804

2026-11-09 · label catalog refresh lands in #12878 · iter -

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.