400 Invoke ModelWithResponseStream: operation error Bedrock Runtime: InvokeModel...
错误信息
API Error: 400 Invoke ModelWithResponseStream: operation error Bedrock Runtime: InvokeModelWithResponseStream, https response error
StatusCode: 400, RequestlD: 9332e7b7-227e-4fd2-b94e-84014d16b3e6, ValidationException: Unexpected value(s) prompt-caching-scope-2026-01-05
for the anthropic-beta header. Please consult our documentation at..com/docs or try again without the header. (request id
202609080908067703745298268d9d6QxMeHEbj)
AI 解决方案
🔍 错误分析
1. 🌐 错误翻译
原文:API Error: 400 Invoke ModelWithResponseStream: operation error Bedrock Runtime: InvokeModelWithResponseStream, https response error StatusCode: 400, RequestlD: 9332e7b7-227e-4fd2-b94e-84014d16b3e6, ValidationException: Unexpected value(s) prompt-caching-scope-2026-01-05 for the anthropic-beta header. Please consult our documentation at..com/docs or try again without the header. (request id 202609080908067703745298268d9d6QxMeHEbj)
译文:API错误:400 Invoke ModelWithResponseStream:操作错误 Bedrock Runtime:InvokeModelWithResponseStream,https响应错误,状态码:400,请求ID:9332e7b7-227e-4fd2-b94e-84014d16b3e6,验证异常:anthropic-beta 标头中存在意外值 prompt-caching-scope-2026-01-05。请参阅我们的文档或尝试不带该标头重新调用。(请求ID:202609080908067703745298268d9d6QxMeHEbj)
2. 🎯 原因分析
anthropic-beta 字段使用了不支持的值 prompt-caching-scope-2026-01-05,违反了API的验证规则。InvokeModelWithResponseStream 接口时,在请求头中传递的 anthropic-beta 参数值无效。anthropic-beta 标头值不在API允许的范围内,可能是使用了错误的缓存范围标识或版本不兼容。3. 💡 解决方案
移除无效的
anthropic-beta 标头,或修正为API支持的合法值(根据报错提示,直接移除是最直接的解决方式):``
代码语言
// 修复后的调用代码示例(以Python boto3为例)
import boto3bedrock_client = boto3.client('bedrock-runtime')
response = bedrock_client.invoke_model_with_response_stream(
modelId='anthropic.claude-v2', # 替换为实际模型ID
body='{"prompt": "你的提示词", "max_tokens": 200}'
# 移除包含错误值的headers参数,或仅传递API文档中允许的合法标头
)
处理响应流
``