Code: invalid_request_error, HTTP Status: 400)

2026年05月12日 17:33 状态: 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的思考模式(或类似功能)时,API模型在返回的响应中包含了一个名为 reasoning_content 的字段。根据API设计,这个字段是后续对话所必需的上下文。客户端在进行下一轮对话请求时,未能将此字段正确保存并包含在新的请求体中,导致API服务器校验失败。

  • 发生位置:错误发生在客户端与API服务器交互的过程中,具体是在构建API请求体(Request Body)的环节。当API返回400错误时,表明请求格式或内容不符合要求。
  • 3.方案
    您需要修改代码,确保在存储对话历史记录时,将API返回的
    reasoning_content 字段完整保存,并在构造下一次API请求时,将其原样传递回去。

    错误的代码可能只保存了 content,忽略了 reasoning_content。正确的做法如下:

    python

    错误示例 (只保存 content)


    conversation_history.append({
    “role”: “assistant”,
    “content”: response.choices[0].message.content
    })

    ✅ 正确修复方案 (保存所有必要字段,包括 reasoning_content)


    conversation_history.append({
    “role”: “assistant”,
    “content”: response.choices[0].message.content,
    # 关键:如果API返回了 reasoning_content,必须保存下来
    “reasoning_content”: getattr(response.choices[0].message, ‘reasoning_content‘, None)
    })

    在构造新的API请求时,将整个 conversation_history 传递进去


    response = client.chat.completions.create(
    model=“your-model”,
    messages=conversation_history # 这里包含了上文的 reasoning_content
    )

    4. 预防措施

  • 全面记录响应:不要仅提取响应中您“感兴趣”的字段(如 content`)。最佳实践是完整保存API返回的、与对话状态相关的所有字段,或者至少保存API文档中明确说明需要用于多轮对话的字段。

  • 详阅API文档:在使用具有特殊模式(如思考模式)的API前,务必仔细阅读官方文档中关于 “上下文传递”“对话历史” 的章节,了解哪些字段是必须回传的。

  • 使用调试工具:在开发阶段,使用API调试工具(如Postman)打印出完整的请求和响应体,可以帮助您直观地看到需要传递哪些数据。