Code: invalid_request_error, HTTP Status: 400)
🚨 错误信息
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. 翻译
``reasoning_content
原文:The 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中处理:
`pythonfirst_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. 预防措施