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

オープン
#2,023 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

@sebxt がすでに取り組んでいます。

2026年10月18日 から。

  • #2024 @sebxt による — オープン
  • #2062 @Nandaninaulaa による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
aws, python

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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(","))
主要言語
Python
スター
4.1k
フォーク
915
PR マージ指標
30日以内にマージされた PR はありません

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

anthropics/anthropic-sdk-python のほかの issue

anthropics/anthropic-sdk-python の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。