Code: invalid_request_error, HTTP Status: 400)

2026年04月28日 10:15 processing

错误信息

he `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时,未在请求中包含「思考模式」下要求的reasoning_content必填参数。

  • 发生位置:向模型提供商API发送POST请求的环节,因参数缺失触发invalid_request_error(HTTP 400)。
  • 3. 解决方案


    import requests
    
    # 修复后的API调用示例(含必填参数)
    api_endpoint = "https://api.dmxapi.com/v1/chat/completions"
    payload = {
        "model": "your-model-name",
        "mode": "thinking",  # 启用思考模式
        "messages": [{"role": "user", "content": "你的问题"}],
        "reasoning_content": "此处填写思考过程的推理内容",  # 补全必填参数
        # 其他可选参数...
    }
    
    response = requests.post(
        api_endpoint,
        json=payload,
        headers={"Authorization": "Bearer YOUR_API_KEY"}
    )
    print(response.json())
    

    4. 预防措施


  • 最佳实践1:调用API前严格对照文档核对「模式-参数」映射关系(如思考模式需传reasoning_content)。

  • 最佳实践2:用Postman/curl先做「干跑测试」,验证请求体包含所有必填字段。

  • 推荐工具:使用[OpenAPI Validator](https://github.com/OpenAPITools/openapi-generator)自动校验请求格式。
  • :若需进一步分析,请提供完整的代码上下文或Traceback。