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

未关闭
#2,023 0 条评论 0 个 reaction 已指派 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 账号启动这个项目的开发容器。

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

anthropics/anthropic-sdk-python 的其他 Issue

查看 anthropics/anthropic-sdk-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。