[Bug]: Bedrock /v1/messages: claude-opus-5-5 rejects thinking.type=enabled, no adaptive translation and output_config is stripped

这个报错通常发生在通过 LiteLLM 的 /v1/messages 透明转发访问 Bedrock 上的 claude-opus-5-5 ,且客户端(如 Claude Code)开启了 thinking 的场景。Bedrock 对 opus-5-5 只接受 thinking.type=adaptiv

快速结论:这个报错通常发生在通过 LiteLLM 的 /v1/messages 透明转发访问 Bedrock 上的 claude-opus-5-5,且客户端(如 Claude Code)开启了 thinking 的场景。Bedrock 对 opus-5-5 只接受 thinking.type=adaptive,而旧版转发逻辑把 enabled(以及可能被允许列表过滤掉的 output_config)原样透传,导致 400。优先排查 LiteLLM 版本与 Bedrock messages 转换逻辑是否已包含 adaptive 翻译。

适用环境:镜像 ghcr.io/berriai/litellm-database:main-v1.83.14-stable;模型 bedrock/eu.anthropic.claude-opus-5-5(eu-west-1、eu-central-1 已验证);客户端 Claude Code 2.1.303 / 2.1.x,走 /v1/messages。Issue 未确认操作系统、Python、CUDA、显卡版本。

最快修复方案:升级到包含修复提交 9082f8e 的 main 构建。该修复已合并:旧版 thinking 会被翻译为 adaptive,且调用方传入的 output_config.effort 会被保留。

注意事项:Issue 中的补丁以 "opus-5-5" 字符串匹配模型,属于模型特定处理,其他要求 adaptive thinking 的模型不一定自动生效;将 budget_tokens 映射到 output_config.effort 的通用能力在 Issue 中仅作为建议提出,未验证。升级前请确认所用镜像/构建已包含该提交。

问题场景

用户使用 LiteLLM 作为 Anthropic API 代理,通过 /v1/messages 直通访问 Amazon Bedrock 上的 eu.anthropic.claude-opus-5-5。客户端 Claude Code 2.1.x 在开启 thinking 时会发送 thinking: {"type": "enabled", "budget_tokens": N},因此每个开启 thinking 的 opus-5-5 请求经代理转发后都返回 400,模型实际不可用。

报错原文

"thinking.type.enabled" is not supported for this model. Use "thinking.type.adaptive" and "output_config.effort" to control thinking behavior.

原因分析

Bedrock 对 opus-5-5 拒绝经典扩展思考结构,只接受 thinking.type=adaptive 配合 output_config.effort。Issue 正文指出 Bedrock messages 转换层(invoke_transformations/anthropic_claude3_transformation.py)存在两个缺口:

  • 没有把 thinking.type: enabled 翻译为 adaptive;clear_thinking 路径已有 adaptive 翻译,但普通 /v1/messages 请求不会走到该分支,旧结构被直接转发导致 400。
  • output_config 未列入 BedrockInvokeAnthropicMessagesRequest.__annotations__,会被第 7 步的允许列表过滤掉,即使客户端传了 output_config.effort 也无法到达 Bedrock。

Issue 作者通过 boto3 invoke_model 直接验证:enabled 结构报 ValidationException;adaptive 结构正常;adaptive 加 output_config.effort(high/low)也正常。

环境排查

  • 确认 LiteLLM 版本或镜像构建是否包含提交 9082f8e;main-v1.83.14-stable 镜像是 Issue 复现时的原始版本。
  • 确认请求确实走 /v1/messages 路径,而非其他代理路径。
  • 确认模型标识为 Bedrock 的 opus-5-5 型号(如 bedrock/eu.anthropic.claude-opus-5-5)。
  • 确认客户端 Claude Code 版本(Issue 使用 2.1.303)及是否开启 thinking。
  • 确认所在 Bedrock 区域(Issue 在 eu-west-1 与 eu-central-1 验证)。
  • 检查转换层文件中是否存在 adaptive 翻译逻辑及 output_config 字段定义。

解决步骤

  1. 将 LiteLLM 升级到包含修复提交 9082f8e5d0549d93c27009b6d4f6a0a631a73435 的构建。维护者确认该提交已合并到 main,旧版 thinking 被翻译为 adaptive,调用方提供的 effort 被保留。
  2. 若暂时无法升级,可参考 Issue 补丁在本地构建中实施两处改动(可优先尝试):
    • 在 invoke_transformations/anthropic_claude3_transformation.py 的第 7 步允许列表过滤之前,对 opus-5-5 模型把 thinking.type=enabled 替换为 {"type": "adaptive"},并在未提供时补上 output_config(Issue 补丁默认 {"effort": "high"})。
    • 在 litellm/types/llms/bedrock.py 的 BedrockInvokeAnthropicMessagesRequest.__annotations__ 中增加 output_config: dict,避免被过滤。
  3. 重建并重启 LiteLLM 服务,再用 Claude Code 发起开 thinking 的请求测试。

验证方法

用 Claude Code 风格的请求(thinking 开启、多个工具、system blocks、多轮历史)访问 claude-opus-5-5,观察是否返回 HTTP 200 流式响应而非 400。维护者已用 6 个真实 Bedrock 请求验证,覆盖流式与非流式、默认/高/低 effort,均返回 HTTP 200。也可分别测试默认 effort 与显式 output_config.effort 为 high/low 的情况。

参考来源

BerriAI/litellm #47382;修复提交 9082f8e

GamsGo AI

AI 工具推荐

想把多个 AI 模型放在一个入口?

GamsGo AI 集成 ChatGPT、DeepSeek、Gemini、Claude、Midjourney、Veo 等常用模型,适合写作、绘图、视频和日常 AI 工作流。

了解 GamsGo AI

推广链接:通过此链接购买,我可能获得佣金,不影响你的价格。

这个方案解决了吗?

celebrityanime
celebrityanime
文章: 29781

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注