400 The `content[].thinking` in the thinking mode must be passed back to the API...

2026年05月28日 12:03 37.70 秒 success

错误信息

API Error: 400 The `content[].thinking` in the thinking mode must be passed back to the API. (request id: 20260528120110622892286cHFkJeTd)

AI 解决方案

1. 🌐 错误翻译


原文:The `content[].thinking` in the thinking mode must be passed back to the API.
译文:在思考模式(thinking mode)下,`content[].thinking` 中的内容必须被回传给API。

2. 🎯 原因分析


根本原因是在调用支持“思考模式”(如某些高级推理模型)的API时,首次请求的响应中包含了模型的思考过程(即 thinking 部分)。在后续进行多轮对话或继续请求时,必须将前次响应中完整的 content 数组(特别是包含 thinking 的部分)原样传回。您当前的请求未能满足此要求,导致API返回400错误。

3. 💡 解决方案


在后续的API调用中,将上一次响应的 choices[0].message.content 完整地作为用户下一条消息的一部分传递。

// 假设第一次API调用后,将响应存储在变量 `response` 中
const previousAssistantMessage = response.choices[0].message;

// 构建下一轮对话的 messages 数组
const messages = [
  // ... 历史消息(如有)
  previousAssistantMessage, // 关键:将包含 thinking 的完整 assistant 消息传回
  { role: "user", content: "你的下一个问题" }
];

// 使用正确的 messages 数组进行第二次API调用
const nextResponse = await fetch('YOUR_API_ENDPOINT', {
  method: 'POST',
  headers: { /* ... */ },
  body: JSON.stringify({ model: "your-model", messages })
});

4. 🛡️ 预防措施


规范消息管理:在客户端严格维护一个 messages 对话历史数组,确保每次请求都携带完整的历史记录,特别是当响应包含 thinking 等特殊字段时。
阅读官方文档:使用新模型或新特性前,务必仔细阅读其API文档,了解是否需要回传 thinking 等字段、响应格式以及错误码说明。