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

Abierto
#2,023 0 comentarios 0 reacciones 0 asignados Ver en GitHub

@sebxt ya está trabajando en esto.

Desde el 18/10/2026.

  • #2024 de @sebxt — abierto
  • #2062 de @Nandaninaulaa — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
aws, python

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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(","))
Lenguaje dominante
Python
Estrellas
4.1k
Forks
915
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de anthropics/anthropic-sdk-python

Todos los issues de anthropics/anthropic-sdk-python

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.