Code: invalid_request_error, HTTP Status: 400)

2026年05月08日 19:18 状态: processing

🚨 错误信息

The `reasoning_content` in the thinking mode must be passed back to the API. (Model Provider Error Code: invalid_request_error, HTTP Status: 400)

🤖 AI解决方案

报错分析

#### 1. 翻译
``
原文:The
reasoning_content in the thinking mode must be passed back to the API.
译文:思考模式下的
reasoning_content 必须回传给 API。
`

#### 2. 因分析
此错误表明您正在使用一个支持“思考模式”的特定模型(如某些推理模型),并且该模型的API接口有明确要求:在多轮或流式对话中,模型在首次响应中返回的
reasoning_content 字段,必须在后续的请求中完整回传。您很可能在第二次及之后的API请求中,忽略了这个必需的字段,导致服务器校验失败(HTTP 400)。

#### 3.
在发起后续的API请求时,确保
messages 列表中包含了上一轮API响应中的 reasoning_content。通常,您需要将上一轮完整的助手消息(Assistant Message)结构放入到新的请求中。

以下是一个伪代码示例,说明如何在Python中处理:

`python

假设 first_response 是您第一次API调用的返回结果


first_response = client.chat.completions.create(
# ... 其他参数
)

提取包含 reasoning_content 的助手消息


assistant_message = {
"role": "assistant",
"content": first_response.choices[0].message.content, # 常规回复内容
"reasoning_content": first_response.choices[0].message.reasoning_content # 关键字段
}

构建下一次请求,将上轮助手消息放入上下文


messages = [
{"role": "system", "content": "..."},
{"role": "user", "content": "用户的新问题"},
assistant_message # 将包含 reasoning_content 的消息加入历史
]

发起后续请求


second_response = client.chat.completions.create(
messages=messages,
# ... 其他参数
)
``

#### 4. 预防措施

  • 仔细阅读API文档:当使用具有特殊模式(如思考、推理)的模型时,务必查阅官方文档,了解其上下文管理的具体要求。

  • 维护完整的对话状态:在代码中设计一个状态管理器,确保在多轮交互中,将API每次返回的完整响应结构(包括所有特殊字段)存储下来,并在下一次请求时正确传递。

  • 使用官方SDK:尽量使用模型提供商的官方SDK,它们通常会更好地封装这些状态管理逻辑,降低手动处理的复杂度。