Bedrock Runtime: InvokeModelWithResponseStream, https response error StatusCode:...
错误信息
status_code=400, InvokeModelWithResponseStream: operation error Bedrock Runtime: InvokeModelWithResponseStream, https response error StatusCode: 400, RequestID: 6a772173-6c5b-4693-8517-f64e0a8261b5, ValidationException: context_management: Extra inputs are not permitted (request id: 20260713015907926000656rMQtQc3sKmeFHjR7)
AI 解决方案
🔍 报错分析
1. 🌐 错误翻译
原文:status_code=400, InvokeModelWithResponseStream: operation error Bedrock Runtime: InvokeModelWithResponseStream, https response error StatusCode: 400, RequestID: 6a772173-6c5b-4693-8517-f64e0a8261b5, ValidationException: context_management: Extra inputs are not permitted (request id: 20260713015907926000656rMQtQc3sKmeFHjR7)
译文:状态码=400,InvokeModelWithResponseStream:操作错误 Bedrock Runtime:InvokeModelWithResponseStream,https响应错误 状态码:400,请求ID:6a772173-6c5b-4693-8517-f64e0a8261b5,验证异常:context_management:不允许额外输入(请求id:20260713015907926000656rMQtQc3sKmeFHjR7)
2. 🎯 原因分析
InvokeModelWithResponseStream API 发送了不允许的额外输入参数,违反了接口参数校验规则。InvokeModelWithResponseStream 操作时,请求参数中包含了超出允许范围的字段,被服务器直接拒绝。3. 💡 解决方案
InvokeModelWithResponseStream 接口的参数定义,移除所有未明确允许的额外字段。// 正确调用示例(以调用Anthropic Claude模型为例)
const bedrock = new AWS.BedrockRuntime({ region: 'us-east-1' });
const params = {
modelId: 'anthropic.claude-3-sonnet-20240229-v1:0', // 仅保留必需参数,移除额外自定义字段
body: JSON.stringify({
input: {
message: '你的提示词内容'
},
// 严格按接口要求添加必要配置,不添加非文档允许的参数
})
};
try {
const response = await bedrock.invokeModelWithResponseStream(params).promise();
// 处理响应
} catch (error) {
console.error('调用失败:', error);
}