跳转到内容

api failed deserialize json body into cc-switch

Quick fix

按错误类型回退 Claude Code、升级 cc-switch、关闭本地代理或停止发送不支持的字段。

报错原文
API Error: 400 Failed to deserialize the JSON body into the target type: messages[1].role: unknown variant `system`, expected `user` or `assistant` at line 1 column 4371

该报错是上游模型 API 拒绝了 cc-switch 转发或客户端生成的 JSON 请求体。issues 里包含多种变体:Claude Code 2.1.154 将 system prompt 以 role: "system" 放入 messages 数组,而 DeepSeek 的 /anthropic 端点要求 system 必须位于顶层字段;Codex /responses 经 cc-switch 转换为 Chat Completions 时,工具调用可能丢失 name 字段,该问题在 cc-switch 3.16.4 修复;DeepSeek 非多模态模型收到 image_url / image 内容也会报同类 400;另有用户发现开启或关闭 cc-switch 本地代理会影响部分模型兼容性。

  1. 如果错误包含 messages[1].role: unknown variant `system`,将 Claude Code 回退到 2.1.153 或 2.1.152,并关闭自动更新。

  2. 如果错误包含 missing field `name`,将 cc-switch 升级到 3.16.4 或更高版本;该问题在 3.16.3 中仍存在。

  3. 如果错误包含 unknown variant `image_url`、unknown variant `image` 或类似多模态字段,不要向 DeepSeek 等非多模态模型发送图片。

  4. 如果切换多个模型时部分模型可用、部分模型报 400,尝试关闭或重新打开 cc-switch 主页面本地代理;维护者说明部分 provider 开启本地代理更兼容,部分 provider 关闭后更稳定。

  5. 如果 DeepSeek 官方 API 曾报 system / developer role 问题,维护者反馈 DeepSeek 官方后续已修复,可先重试;若仍失败再使用回退 Claude Code 的方案。

ToolClaude Code / Codex
Version未知
PlatformsmacOSWindows
Claude Code 应该回退到哪个版本?
多个用户确认 npm i -g @anthropic-ai/[email protected] 可用;也有用户回退到 2.1.152 后解决。回退后建议关闭 Claude Code 自动更新。
VS Code 里的 Claude Code 插件也要回退吗?
如果使用 VS Code 插件,可以卸载当前插件并重新安装 2.1.153 版本。
为什么关闭 cc-switch 本地代理后 DeepSeek 就能用了?
不同 provider 对 Anthropic 特有字段和代理转换的兼容性不同。维护者建议:部分模型开启本地代理和 Claude takeover 更好,部分模型关闭本地代理更稳定。
DeepSeek 为什么不能发图片?
issues 中维护者和用户确认 DeepSeek V3.2 等模型不是多模态模型,不支持 image / image_url 内容,发送图片会触发 deserialize 400 错误。
missing field `name` 是模型问题还是 cc-switch 问题?
该问题与 Codex /responses 转 Chat Completions 时工具调用丢失 name 有关。维护者确认 cc-switch 3.16.3 受影响,3.16.4 已修复。

这是一个非官方社区 wiki,与 cc-switch 作者及项目本身无隶属关系。内容整理自项目公开的 GitHub issues。本站不分发任何软件。