400 {"error":{"type":"<nil>","message":"InvokeModelWithResponseStream: operation...

2026年04月09日 18:44 processing

错误信息

API Error: 400 {"error":{"type":"<nil>","message":"InvokeModelWithResponseStream: operation error Bedrock Runtime: InvokeModelWithResponseStream, https response error StatusCode: 400, RequestID: 291177b0-f613-452b-95b9-be427ab77697, ValidationException: ***.***.content.0: Invalid `signature` in `thinking` block (request id: 20260409104224914347551x7Ih5O1Z) (request id: 20260409104224901415643hnrF6Hrp) (request id: 20260409104223920632757KrytLLhK)"},"type":"error"}

AI 解决方案

报错分析报告

1.错误翻译


原文:Invalid `signature` in `thinking` block
译文:`thinking`块中的`signature`无效

2.原因分析


  • 根本原因:请求中thinking块的signature字段未通过Bedrock Runtime API的验证(格式/算法不符)。

  • 具体位置:请求Payload的..content[0]thinking块所在的内容项),对应错误中的content.0
  • 3.解决方案


    需修正thinking块的signature为API认可的有效值(以Python为例):
    import hmac
    import hashlib
    import base64
    
    def gen_valid_signature(secret: str, content: str) -> str:
        """生成符合API要求的HMAC-SHA256签名(示例)"""
        digest = hmac.new(
            secret.encode("utf-8"),
            content.encode("utf-8"),
            hashlib.sha256
        ).digest()
        return base64.b64encode(digest).decode("utf-8")
    
    # 修复后的`thinking`块
    fixed_thinking_block = {
        "type": "thinking",
        "content": "你的思考逻辑文本",  # 需与签名原文一致
        "signature": gen_valid_signature("YOUR_API_SECRET", "你的思考逻辑文本")
    }
    

    4. 预防措施


  • 前置验证:用JSON Schema校验请求Payload,确保thinking.signature存在且格式合规。

  • 工具辅助:用Postman/curl先测试签名有效性,再集成代码;推荐用ajv(JS)或jsonschema(Python)做Schema校验。
  • ---
    请补充具体语言的实现细节或签名规则,可进一步细化方案。