mirror of
https://github.com/deepseek-ai/awesome-deepseek-agent.git
synced 2026-11-05 01:07:37 +00:00
[GH-ISSUE #161] claude code cli 使用 api 出现 400 错误 #57
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
deepseek-ai/awesome-deepseek-agent#57
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Nine499 on GitHub (May 27, 2026).
Original GitHub issue: https://github.com/deepseek-ai/awesome-deepseek-agent/issues/161
2.1.152 (Claude Code)
@KITWealth commented on GitHub (May 27, 2026):
https://blog.csdn.net/m0_52539320/article/details/161453394
@z125316840-code commented on GitHub (May 27, 2026):
我也遇到了,突然就这样了
@DillionApple commented on GitHub (May 28, 2026):
是新版本 claude code 引入的问题,建议各位先降级一下。
@Nine499 commented on GitHub (May 28, 2026):
有没有计划修复时间?
@wujunran commented on GitHub (May 28, 2026):
降级了2.1.148还是会报一样的错
@FalseLeonLai commented on GitHub (May 29, 2026):
我也一样,claude code现在修改了请求格式导致的
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 30325@huangqinquan commented on GitHub (May 29, 2026):
测试这个方案可以解决
@wujunran commented on GitHub (May 29, 2026):
如果是用了vscode的插件,记得插件也要降级,2.1.145 我正常了
@Sanjeever commented on GitHub (May 29, 2026):
遇到同样的问题。根因是 Claude Code v2.1.154+ 改了请求结构,会在
messages数组中间插入role: "system"的消息,而 DeepSeek 的 Anthropic 兼容层只接受user/assistant,于是报错:降级到 2.1.153 确实能用,但自动更新会反复拉回新版本,每次都要手动回滚,比较折腾。
另一个思路:不降级 CC、不改配置,在中间加一层本地代理把请求改写掉。我写了一个小工具专门干这个:
👉 deepseek-cc-proxy: https://github.com/Sanjeever/deepseek-cc-proxy
原理:把
messages里所有的role: "system"剥离、合并进顶层system字段,再转发给 DeepSeek。流式 / 非流式响应都原样透传,鉴权头也完整透传。依赖只有starlette+uvicorn+httpx,单文件实现。用法:
然后把
~/.claude/settings.json里的ANTHROPIC_BASE_URL从https://api.deepseek.com/anthropic改成http://127.0.0.1:8787,token、模型映射等其他配置全部不动。之后正常使用 Claude Code,400 报错消失,不用跟自动更新斗智斗勇了。Same issue here. Root cause: Claude Code v2.1.154+ inserts
role: "system"messages into themessagesarray, but DeepSeek's Anthropic-compatible endpoint only acceptsuser/assistant.Downgrading to 2.1.153 works, but auto-update keeps pulling you back to the broken version.
Alternative approach — a local proxy that rewrites the request on the fly, no downgrade needed:
👉 deepseek-cc-proxy: https://github.com/Sanjeever/deepseek-cc-proxy
It hoists all
messages[].role: "system"entries into the top-levelsystemfield, then forwards to DeepSeek. Streaming (SSE) and non-streaming responses are relayed transparently. Auth headers pass through intact.Quick start:
Then change
ANTHROPIC_BASE_URLtohttp://127.0.0.1:8787in~/.claude/settings.json. Everything else (token, model mappings) stays the same. Works with 2.1.154+ through 2.1.156.@GuanLuoFu commented on GitHub (May 29, 2026):
Alternative workaround: full-featured Node.js proxy
▎
▎ The Python hoist-proxy above handles the system role issue, but there's another problem: thinking block signature validation.
▎ If your session history loses thinking blocks, you get another 400. I wrote a more complete proxy that covers both:
▎
▎ - 🔧 System messages merged into adjacent user messages (wrapped in <system_context>)
▎ - 💾 Thinking block caching & auto-injection with valid signature (fixes /resume sessions)
▎ - 📡 Streaming response capture for real-time thinking accumulation
▎ - 🛠 Rewrites thinking.type: "adaptive" → "enabled"
▎
▎ Usage:
▎ git clone https://github.com/GuanLuoFu/deepseek-claude-proxy
▎ cd deepseek-claude-proxy
▎ node proxy.js
▎ export ANTHROPIC_BASE_URL=http://127.0.0.1:8080
▎ # ANTHROPIC_MODEL / ANTHROPIC_AUTH_TOKEN unchanged
▎
▎ Zero dependencies (Node.js stdlib only). Works on Win/Mac/Linux.
@BenedictKing commented on GitHub (May 29, 2026):
重复讨论 解决方案在此 https://github.com/deepseek-ai/awesome-deepseek-agent/issues/167#issuecomment-4580661360
@chansen2000 commented on GitHub (May 30, 2026):
The model issue has been resolved, no other methods are needed. Verified with version 2.1.157.
@Lemon7ProPlus commented on GitHub (May 30, 2026):
But it has some bugs, i think.
The job always be interrupted without any condition.
When I switch back to 150, it works well.