Error code: 400 - {'error': {'message': 'The content[].thinking in the thinking ...

2026年06月05日 15:12 27.61 秒 success

错误信息

Error: Error code: 400 - {'error': {'message': 'The content[].thinking in the thinking mode must be passed back to the API.', 'type': 'rix_api_error', 'param': '', 'code': 'invalid_request_error'}}

AI 解决方案

🌐 1. 错误翻译


原文:The content[].thinking in the thinking mode must be passed back to the API.
译文:在思维模式下,`content[].thinking` 字段必须被回传给API。

🎯 2. 原因分析


  • 根本原因:您调用的API启用了“思维模式”(thinking mode),并要求在后续的交互中,必须将上一轮响应中返回的content列表里的thinking字段,完整地作为下一轮请求的一部分。

  • 发生位置:错误发生在您的应用向该API发送请求时。请求体(request body)的messages数组中,历史消息(Assistant的回复)缺少了必要的thinking字段。
  • 💡 3. 解决方案


    您需要修改构建请求的代码,确保在传递对话历史时,将包含thinking字段的完整Assistant消息结构包含进去。通常,API响应会像这样:
    {
      "choices": [{
        "message": {
          "role": "assistant",
          "content": [
            {"type": "thinking", "thinking": "...模型的推理过程..."},
            {"type": "text", "text": "...最终的回复..."}
          ]
        }
      }]
    }
    

    在下一次请求中,您的messages数组应该包含这个完整的content结构(包括thinkingtext部分)。错误的写法是只保存text部分,正确的做法是保存整个content数组。

    示例修正代码 (Python):

    import requests
    
    # 假设这是你从API响应中解析出的上一轮助手的回复
    previous_assistant_response = {
        "role": "assistant",
        "content": [
            {"type": "thinking", "thinking": "让我思考一下..."},
            {"type": "text", "text": "这是最终的回答。"}
        ]
    }
    
    # 构建下一次请求的messages列表
    messages = [
        {"role": "system", "content": "你是一个助手"},
        {"role": "user", "content": "你好"},
        # 关键:将包含完整content(包括thinking)的助手消息作为历史传入
        previous_assistant_response,
        {"role": "user", "content": "下一个问题"}
    ]
    
    # 发起请求
    response = requests.post(api_url, json={"messages": messages, ...})
    

    🛡️ 4. 预防措施


  • 仔细阅读API文档:在使用任何高级功能(如思维模式)前,务必详细阅读官方文档,了解其输入和输出的完整数据结构要求。

  • 使用结构化数据管理对话历史:避免手动拼接字符串。使用对象或字典来管理整个对话历史,确保从API响应中解析并存储完整的message对象,而不仅仅是文本部分。推荐使用官方提供的SDK(如有),它能自动处理这些复杂结构。