Bedrock: anthropic_beta body field keeps whitespace and empty entries from the anthropic-beta header

Aperta
#2,023 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

@sebxt ci sta già lavorando.

Dal 18/10/2026.

  • #2024 di @sebxt — aperta
  • #2062 di @Nandaninaulaa — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
aws, python

Direzione di ricerca

Start with src/anthropic/lib/bedrock/_client.py and the _prepare_options function, using the supplied FinalRequestOptions example to reproduce the header splitting behavior. Update parsing so each beta token is trimmed and empty entries are removed, then verify anthropic_beta contains only valid names for default and per-call headers. The open linked pull request indicates this work is already underway.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

What happens

AnthropicBedrock copies the anthropic-beta header into the request body as anthropic_beta, because Bedrock reads betas from the body. It splits the header on , without trimming, so a header written with the usual comma and space separator produces entries with a leading space, and a trailing comma produces an empty entry.

from anthropic._models import FinalRequestOptions
from anthropic.lib.bedrock._client import _prepare_options

options = _prepare_options(
    FinalRequestOptions(
        method="post",
        url="/v1/messages",
        json_data={"model": "anthropic.claude-sonnet-4-5"},
        headers={"anthropic-beta": "context-1m-2025-08-07, interleaved-thinking-2025-05-14"},
    )
)
print(options.json_data["anthropic_beta"])
# ['context-1m-2025-08-07', ' interleaved-thinking-2025-05-14']

The same happens for default_headers={"anthropic-beta": "a, b"} on the client or extra_headers on a call. Bedrock then receives " interleaved-thinking-2025-05-14", which is not a valid beta name.

What should happen

Each entry is trimmed and empty entries are dropped, giving ['context-1m-2025-08-07', 'interleaved-thinking-2025-05-14']. The TypeScript Bedrock client already trims (betas.split(',').map((beta) => beta.trim())), and the other places in this SDK that parse the header (credentials auth, the fallback middleware, tracing) strip each token.

Root cause

src/anthropic/lib/bedrock/_client.py, _prepare_options:

betas = build_headers(options.headers)[0].get("anthropic-beta")
if betas:
    options.json_data.setdefault("anthropic_beta", betas.split(","))
Lingua principale
Python
Stelle
4.1k
Fork
915
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di anthropics/anthropic-sdk-python

Tutte le issue di anthropics/anthropic-sdk-python

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.