code: 400 - {'error': {'message': 'The reasoning_content in the thinking mode mu...

2026年05月22日 18:41 23.34 秒 success

错误信息

{"msg": "API返回错误:Error code: 400 - {'error': {'message': 'The reasoning_content in the thinking mode must be passed back to the API.', 'type': 'rix_api_error', 'param': '', 'code': 'invalid_request_error'}}"}

AI 解决方案

🔍 错误分析报告

1. 🌐 错误翻译


原文:The reasoning_content in the thinking mode must be passed back to the API.
译文:在“思考模式”下,`reasoning_content`(推理内容)必须被回传给API。

2. 🎯 原因分析


  • 根本原因:您正在调用一个支持“思维链”(Chain-of-Thought)或“思考模式”的API。当API首次返回包含 reasoning_content 字段的响应后,在后续的对话或请求中,您必须将这个字段的值原封不动地传递回去,否则API无法维持正确的上下文和推理状态,从而返回400错误。

  • 错误位置:问题发生在客户端代码向DMXAPI发送请求时。请求体(JSON Body)中缺少了 reasoning_content 这个必需的字段,或者传递了错误的值。
  • 3. 💡 解决方案


    在构建后续请求时,必须包含上一次API响应中的 reasoning_content

    以Python伪代码为例:

    # 假设这是第一次调用,获得了包含reasoning_content的响应
    response_1 = call_api(messages=[{"role": "user", "content": "你的问题"}])
    reasoning_content = response_1["choices"][0]["message"]["reasoning_content"] # 假设响应结构如此
    
    # 构建后续请求时,必须在`message`对象中加上这个字段
    next_message = {
        "role": "assistant",
        "content": response_1["choices"][0]["message"]["content"], # 普通回复内容
        "reasoning_content": reasoning_content  # 关键!必须传回
    }
    
    # 发起第二次请求
    response_2 = call_api(messages=[previous_messages..., next_message, new_user_message])
    

    4. 🛡️ 预防措施


  • 仔细阅读API文档:在使用任何提供“思维链”、“CoT”或“思考模式”功能的API时,务必查阅其官方文档,了解 reasoning_content 等特殊字段的传递要求。

  • 设计状态管理:在您的应用中,应为对话会话设计一个状态存储机制,将API返回的临时状态(如 reasoning_contenttool_call_id 等)与对话历史一同保存,以便在下次请求时准确、自动地附加。

  • 使用中间件封装:可以考虑在API调用层进行封装,自动提取并缓存 reasoning_content 等字段,并在下次调用时自动注入,避免手动处理遗漏。