Bedrock Runtime: InvokeModel, https response error StatusCode: 400, RequestID: a...

2026年10月23日 16:34 12.96 秒 success

错误信息

status_code=400, InvokeModel: operation error Bedrock Runtime: InvokeModel, https response error StatusCode: 400, RequestID: af711264-cecd-4198-a54e-8e478ecf6290, ValidationException: Unexpected value(s) `redact-thinking-2026-02-12`, `prompt-caching-scope-2026-01-05`, `advisor-tool-2026-03-01` for the `anthropic-beta` header. Please consult our documentation at ***.***.com/docs or try again without the header. (request id: 202610230832437950069698268d9d6BS8zKsYz)

AI 解决方案

1. 🌐 错误翻译


原文:ValidationException: Unexpected value(s) `redact-thinking-2026-02-12`, `prompt-caching-scope-2026-01-05`, `advisor-tool-2026-03-01` for the `anthropic-beta` header.
译文:验证异常:`anthropic-beta` 请求头中存在无法识别的值 `redact-thinking-2026-02-12`、`prompt-caching-scope-2026-01-05`、`advisor-tool-2026-03-01`。

2. 🎯 原因分析


  • 根本原因:请求中携带的 anthropic-beta 请求头传入了 Bedrock Runtime 不支持的实验性参数值,被服务端参数校验拦截,触发 ValidationException。

  • 具体位置:发起 Bedrock InvokeModel 调用时设置的 HTTP 请求头,当前传入的三个日期版本参数均为无效取值。
  • 3. 💡 解决方案


    // 修复后代码:移除无效的 anthropic-beta 请求头
    const invokeModelParams = {
      modelId: "your-model-id",
      body: JSON.stringify({
        messages: [{ role: "user", content: "需要处理的请求内容" }]
      }),
      // 已删除原 anthropic-beta 头配置
    };
    
    const response = await bedrockRuntimeClient.invokeModel(invokeModelParams);
    

    4. 🛡️ 预防措施


  • ✅ 仅使用官方文档公示的 anthropic-beta 合法取值,上线前核对参数兼容性。

  • ✅ 请求头统一做参数校验,过滤未知/过期实验性配置,避免无效请求触发异常。