[extra-headers] Merge an `anthropic-beta` header from `extra_headers` with the other Anthropic betas however its name is capitalized
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 -
- Decision: Move the header pop into
AnthropicModel._pop_beta_headers; the caller grows by one call - Why:
_get_betas_and_extra_headersis 24 > limit 15; agent_docs/complexity.md 'Existing debt' says put added logic in a method (now 20) - Source: https://github.com/pydantic/pydantic-ai/tree/anthropic-beta-header-case/agent_docs/complexity.md
- Session: e7eaeee4-af9e-477b-8cd0-8a99222fb804
2026-11-08 · mock transport over VCR for the wire test · iter -
- Decision: Assert the
anthropic-betaheader via httpx2.MockTransport, six params, no cassette - Why: Claim is the header the request carries, not the API's answer; six recordings buy nothing
- Source: https://github.com/pydantic/pydantic-ai/tree/anthropic-beta-header-case/tests/models/test_anthropic.py
- Session: e7eaeee4-af9e-477b-8cd0-8a99222fb804
2026-11-08 · batch accepts any spelling like lowercase · iter -
- Decision:
batch_encodenow takesAnthropic-Betainto the batch's betas instead of raising UserError - Why: Same function feeds batch; lowercase already did this on main, so every spelling now matches it
- Source: https://github.com/pydantic/pydantic-ai/tree/anthropic-beta-header-case/pydantic_ai_slim/pydantic_ai/models/anthropic/_batch.py
- Session: e7eaeee4-af9e-477b-8cd0-8a99222fb804
2026-11-08 · falsy beta header value is skipped · iter -
- Decision:
_pop_beta_headersskips a falsy value (None, SDKomit) with main's walrus guard - Why: Verifier regression 1: lowercase
None/omitwas 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 ofanthropic-betais 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_headersafter 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 -
- Decision: reserved; outcome pending
- Why: tree a580a4f6be35412dabf6caa442d348c5c6e6386c; full branch scope a355f7a80e..952c6ca91c; policy base a355f7a80e (upstream/main); first review; light tier (haiku, effort medium)
- Source: https://github.com/pydantic/pydantic-ai/tree/anthropic-beta-header-case
- Session: e7eaeee4-af9e-477b-8cd0-8a99222fb804
2026-11-08 · pre-push review 1 of 3 at 952c6ca91c7e645a7a795fd3822dc67cc478f5b9 · iter -
- Decision: remediated: test moved to request_capture with recorded cassettes (tests/AGENTS.md first reach for header asserts); anthropic_betas docstring names any capitalization
- Why: tree a580a4f6be; full branch a355f7a80e..952c6ca91c; both findings net-positive, policy-backed
- Source: https://github.com/pydantic/pydantic-ai/tree/anthropic-beta-header-case
- Session: e7eaeee4-af9e-477b-8cd0-8a99222fb804
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 -
- Decision: CI run 42505799238 success; douwebot APPROVE (run 42507102161) on c69faa1c20 with no comments; 0 unresolved threads
- Why: Second-opinion surface and final metadata check pending the manager's choice
- Source: https://github.com/pydantic/pydantic-ai/pull/12875#pullrequestreview-5818975806
- Session: e7eaeee4-af9e-477b-8cd0-8a99222fb804
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 -
- Decision: No additional review surface for #12875
- Why: David's choice for the whole extra-headers cluster, relayed by the manager
- Source: https://github.com/pydantic/pydantic-ai/pull/12875
- Session: e7eaeee4-af9e-477b-8cd0-8a99222fb804
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 -
- Decision: labels.tsv refresh for cluster:extra-headers stays out of #12875
- Why: Manager's call: #12878 carries the refresh for the cluster
- Source: https://github.com/pydantic/pydantic-ai/pull/12878
- Session: e7eaeee4-af9e-477b-8cd0-8a99222fb804
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.