Request body format invalid 报错 Claude Code
Quick fix
升级 cc-switch 并开启 Rectifier 整流器,或添加环境变量 MAX_THINKING_TOKENS=0 以兼容第三方 API 格式。
Symptom
Section titled “Symptom”API Error: 400 {"error":{"code":"invalid_parameter_error","message":"event:error\ndata:{"code":"InvalidParameter","message":"Request body format invalid","request_id":"eedf1443-5885-9123-b239-ea0ad34d499a"}\n\n","param":null,"type":"invalid_request_error"},"request_id":"f7cd2ca2-718e-9a2b-93a5-56bb212e493a"}该 400 错误由 Claude Code 或 Codex 发送的请求体与第三方 Provider(如阿里百炼、DeepSeek)的 API 规范不兼容引起。主要包含三种变体:1. 思考模式不兼容:Claude 默认发送 thinking: adaptive,但部分第三方仅支持 enabled/disabled。2. System Prompt 格式变更:Claude Code >= 2.1.154 将系统提示词作为 role: system 放入 messages 数组,而第三方期望其在顶层且为字符串。3. 超大参数转换异常:Codex 中超大或复杂嵌套的 tool_call 参数在协议转换时生成不合法 payload。
将 cc-switch 升级至 v3.11.0 或更高版本(推荐 v3.12.3+),以获取 Thinking Budget Rectifier 和 Normalize system messages 功能。
在 cc-switch 设置中启用整流器。进入 Settings > Proxy > Rectifier,确保开启 Normalize system messages 开关。
若问题依旧,在配置中强制关闭自适应思考模式。
// .claude/settings.json{"env": {"MAX_THINKING_TOKENS": "0"},"alwaysThinkingEnabled": false}(备选)若使用阿里百炼,可尝试切换为 OpenAI 兼容协议,将 Base URL 改为 https://coding.dashscope.aliyuncs.com/v1,API 格式选择 openai 并开启代理。
Affected Versions
Section titled “Affected Versions”Source Issues
Section titled “Source Issues”本页汇总自 4 个真实 issue
- 为什么添加了 MAX_THINKING_TOKENS=0 环境变量后依然报错?
- 修改环境变量或配置后,必须点击保存并重启 Claude Code 终端才能生效。此外,如果是 Claude Code >= 2.1.154 引起的 system prompt 格式问题,仅关闭 thinking 不够,必须升级 cc-switch 并开启 Normalize system messages 整流功能。
- 换成 OpenAI 兼容协议后报错 Cannot read properties of null (reading 'output_tokens') 怎么办?
- 这通常是因为模型名称未正确映射或上游返回格式不标准。建议放弃 OpenAI 兼容协议,换回 Anthropic 协议并依赖 cc-switch 的 Rectifier 功能进行请求体自动修正。
这是一个非官方社区 wiki,与 cc-switch 作者及项目本身无隶属关系。内容整理自项目公开的 GitHub issues。本站不分发任何软件。