400 {"error":{"type":"<nil>","message":"InvokeModelWithResponseStream: operation...
错误信息
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"}
在使用Claude Code的时候出现的该问题 并不是API调用 无法修正请求方式
AI 解决方案
报错分析报告
1.错误翻译
原文:Invalid `signature` in `thinking` block
译文:在`thinking`块中存在无效的`signature`
2. 原因分析
content数组第0个元素的thinking块内signature字段未通过AWS Bedrock验证 content[0].thinking.signature属性,因格式错误、密钥不匹配或签名计算逻辑失效导致3.解决方案
# 修复示例(AWS Bedrock Claude 3.7+ 请求构造)
import boto3
import json
client = boto3.client('bedrock-runtime', region_name='us-east-1')
# 正确构造含thinking块的请求(signature需按模型要求生成)
payload = {
"anthropic_version": "bedrock-2023-05-31",
"messages": [{
"role": "user",
"content": [{
"type": "thinking",
"signature": "GENERATE_VALID_SIGNATURE_HERE", # 替换为有效签名
"thinking": "你的思考内容"
}]
}]
}
response = client.invoke_model(
modelId="anthropic.claude-3-7-sonnet-20250219-v1:0",
body=json.dumps(payload)
)
关键修复点:
thinking块结构符合Claude 3.7+规范(type/signature/thinking字段完整) signature4. 预防措施
SigV4Auth),禁止手动拼接签名 thinking块必填字段)注:报错本质是AWS Bedrock API的验证失败,与“是否API调用”无关——Claude Code底层仍通过Bedrock API交互。需修正请求中的signature有效性。