CC Switch local proxy failed while handling Codex endpoint /responses. Provider:...

2026年08月25日 16:40 26.97 秒 success

错误信息

CC Switch local proxy failed while handling Codex endpoint /responses. Provider: DeepSeek; model: deepseek-v4-flash; upstream_status: HTTP 400; cause: The `reasoning_content` in the thinking mode must be passed back to the API.

AI 解决方案

🔍 错误分析

1. 🌐 错误翻译


原文:CC Switch local proxy failed while handling Codex endpoint /responses. Provider: DeepSeek; model: deepseek-v4-flash; upstream_status: HTTP 400; cause: The `reasoning_content` in the thinking mode must be passed back to the API.
译文:CC切换本地代理在处理Codex端点/responses时失败。服务商:DeepSeek;模型:deepseek-v4-flash;上游状态:HTTP 400;原因:思考模式中的`reasoning_content`必须传回API。

2. 🎯 原因分析


该错误的核心原因是DeepSeek API在思考模式下,未正确将reasoning_content字段返回给上游服务,导致请求被拒绝并返回HTTP 400状态码。
  • 错误位置:DeepSeek模型调用过程中的响应处理环节

  • 问题本质:API要求调用方必须在思考模式下,完整回传模型生成的reasoning_content字段,而当前实现缺失或未正确传递该字段,违反了API的响应格式规范。
  • 3. 💡 解决方案


    确保在接收DeepSeek API响应后,保留reasoning_content字段,并按规范完整返回给上游服务,以下是修复后的代码示例(以Python调用为例):
    import requests
    
    def call_deepseek_api(api_key, model, messages, **kwargs):
        url = "https://api.deepseek.com/v1/chat/completions"
        headers = {"Authorization": f"Bearer {api_key}"}
        data = {
            "model": model,
            "messages": messages,
            # 确保开启思考模式时传入必要参数
            "thinking": {"type": "enabled"}
        }
        # 合并额外参数,避免覆盖核心配置
        data.update({k: v for k, v in kwargs.items() if k not in data})
        
        response = requests.post(url, headers=headers, json=data)
        # 严格检查上游要求的必填字段,完整转发响应
        if response.status_code == 200:
            result = response.json()
            # 确保包含reasoning_content字段(思考模式下必选)
            if "choices" in result and result["choices"] and "reasoning_content" in result["choices"][0].get("message", {}):
                return result
            else:
                raise ValueError("API响应缺失必选的reasoning_content字段")
        else:
            response.raise_for_status()
    

    4. 🛡️ 预防措施


  • 严格遵循API字段规范:调用前仔细核对DeepSeek官方文档,明确不同模型模式(尤其是思考模式)的必填/可选字段,确保响应与请求严格匹配,不缺失核心字段。

  • 启用API响应校验工具:使用Postman、Insomnia等API调试工具,开启响应格式校验功能,或在代码中添加字段完整性检查,提前发现缺失reasoning_content等关键字段的问题,避免请求失败。