_from_response(err.response) from None openai.BadRequestError: Error code: 400 -...

2026年04月25日 10:43 processing

错误信息

File "c:\ProgramData\anaconda3\Lib\site-packages\openai\_base_client.py", line 1034, in request raise self._make_status_error_from_response(err.response) from None openai.BadRequestError: Error code: 400 - {'error': {'message': 'Error from provider (DeepSeek): thinking options type cannot be disabled when reasoning_effort is set', 'type': 'invalid_request_error', 'param': '', 'code': 'invalid_request_error'}}

AI 解决方案

报错分析报告

1.错误翻译


原文:Error from provider (DeepSeek): thinking options type cannot be disabled when reasoning_effort is set
译文:来自提供商(DeepSeek)的错误:当设置reasoning_effort时,无法禁用思考选项类型

2. 原因分析


  • 根本原因:请求中同时设置reasoning_effort参数与禁用thinking options type,两者存在冲突。

  • 发生位置:OpenAI客户端发起请求时(_base_client.py第1034行),由DeepSeek提供商返回invalid_request_error
  • 3.解决方案


    调整参数组合,避免冲突。以下是修复示例(以Python为例):
    # 方案1:保留reasoning_effort,启用thinking options(推荐)
    from openai import OpenAI
    client = OpenAI()
    
    response = client.chat.completions.create(
        model="deepseek-chat",
        messages=[{"role": "user", "content": "你的问题"}],
        reasoning_effort="high"  # 仅设置该参数,不禁用thinking
    )
    
    # 方案2:如需禁用thinking options,移除reasoning_effort
    response = client.chat.completions.create(
        model="deepseek-chat",
        messages=[{"role": "user", "content": "你的问题"}],
        thinking={"disabled": True}  # 仅禁用thinking,不设置reasoning_effort
    )
    

    4. 预防措施


  • 最佳实践1:调用API前查阅提供商(如DeepSeek)的[参数兼容性文档](https://platform.deepseek.com/docs),避免冲突组合。

  • 最佳实践2:用Pydantic等工具定义请求参数模型,提前校验合法性(如禁止同时传reasoning_effortthinking.disabled=True)。
  • ---
    :修复需根据实际业务场景选择参数组合,优先参考官方最新文档。