": { "message": "InvokeModelWithResponseStream: operation error Bedrock Runtime:...

2025年12月03日 22:59 状态: processing

🚨 错误信息

{ "error": { "message": "InvokeModelWithResponseStream: operation error Bedrock Runtime: InvokeModelWithResponseStream, https response error StatusCode: 400, RequestID: f91b0578-8773-44dd-80f1-d16993f2f473, ValidationException: ***.***.***.***.type: Expected `thinking` or `redacted_thinking`, but found `text`. When `thinking` is enabled, a final `assistant` message must start with a thinking block (preceeding the lastmost set of `tool_use` and `tool_result` blocks). We recommend you include thinking blocks from previous turns. To avoid this requirement, disable `thinking`. Please consult our documentation at https://***.com/***/***/***/*** (request id: 20251203222538913807837b9unliCi) (request id: 20251203222521699643505Wy9ajRk8) (request id: 20251203222521670791432iXOOySMp) (request id: 20251203222449408878641vJMXi5bB)", "type": "rix_api_error", "param": "", "code": null } }

🤖 AI解决方案

错误翻译

``
原文:ValidationException: ....type: Expected
thinking or redacted_thinking, but found text. When thinking is enabled, a final assistant message must start with a thinking block (preceeding the lastmost set of tool_use and tool_result blocks).
译文:验证异常:期望类型为
thinkingredacted_thinking,但实际发现 text。当启用 thinking 功能时,最终的助手消息必须以思考块开头(位于最后一组 tool_usetool_result 块之前)。
`

原因分析

这是一个Bedrock Runtime API的请求格式验证错误。当启用了thinking功能时,API要求助手响应必须以思考块开始,但实际返回的是text类型的内容,违反了API的格式规范。

根本原因:消息格式不符合Bedrock API对思考功能的强制要求。

解决方案

json
{
"messages": [
{
"role": "user",
"content": "你的问题内容"
},
{
"role": "assistant",
"content": [
{
"type": "thinking",
"thinking": "这里是模型的思考过程..."
},
{
"type": "text",
"text": "这里是最终的回答内容"
}
]
}
]
}

或者禁用思考功能

json
{
"inferenceConfig": {
"thinkingConfig": {
"enabled": false
}
}
}

️ 预防措施

  • 格式检查:在使用Bedrock思考功能时,确保助手响应严格遵循thinking块在前、text`块在后的格式要求

  • 配置验证:在发送请求前,验证API配置参数,特别是思考功能的启用状态与消息格式的匹配性
  • 推荐工具:使用AWS Bedrock API文档中的消息格式验证工具来检查请求结构。