Bedrock Runtime: InvokeModelWithResponseStream, https response error StatusCode:...
🚨 错误信息
InvokeModelWithResponseStream: operation error Bedrock Runtime: InvokeModelWithResponseStream, https response error StatusCode: 400, RequestID: 9db7870a-aa6b-4af6-92da-cc02766a1478, ValidationException: ***.***.custom.input_examples: Extra inputs are not permitted (request id: 20251117202313735022317iJHViwC2) (request id: 2025111720230235456758fCbNP08U) (request id: 20251117202301977098771nt2OoPqp) (request id: 202511172022462034573156ST3qEkQ)
🤖 AI解决方案
代码报错分析报告
1. 错误翻译
原文:ValidationException: ***.***.custom.input_examples: Extra inputs are not permitted
译文:验证异常:***.***.custom.input_examples:不允许额外的输入
2. 原因分析
根本原因:您向 Bedrock Runtime 服务发送的请求中包含了超出预期或不允许的额外输入参数。具体问题:
- 请求中的
input_examples字段包含了系统不允许的额外参数 - AWS Bedrock 服务验证了输入格式,发现与预期的 schema 不匹配
- 这是一个请求参数验证错误,发生在 API 调用层面
3. 解决方案
# 修复后的 Bedrock 调用示例
import boto3
import json
bedrock_runtime = boto3.client('bedrock-runtime')
# 正确的请求体格式
request_body = {
"prompt": "您的提示词内容",
"max_tokens": 100,
# 仅包含必需的参数,移除额外的 input_examples
# "input_examples": ... # 移除这个字段或检查其格式
}
try:
response = bedrock_runtime.invoke_model_with_response_stream(
modelId='your-model-id',
body=json.dumps(request_body)
)
except Exception as e:
print(f"错误: {e}")
修复步骤:
input_examples 字段或确保其格式符合规范4. ️ 预防措施
最佳实践建议:
️ 推荐工具:
bedrock validate 命令预先验证请求格式---
关键提醒:此错误表明您的请求体格式不符合 Bedrock 服务的预期,请检查文档确认正确的参数结构。