CC Switch local proxy failed while handling Codex endpoint /responses. Provider:...
错误信息
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状态码。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. 🛡️ 预防措施
reasoning_content等关键字段的问题,避免请求失败。