接入claude code会报错
例行检查
- [ ] 我已确认目前没有类似 issue
- [ ] 我已确认我已升级到最新版本
- [ ] 我已完整查看过项目 README,尤其是常见问题部分
- [ ] 我理解并愿意跟进此 issue,协助测试和提供反馈
- [ ] 我理解并认可上述内容,并理解项目维护者精力有限,不遵循规则的 issue 可能会被无视或直接关闭
问题描述 我使用new api提供的baseurl作为claude code的baseurl,在执行任务的时候报错API Error: Cannot read properties of undefined (reading 'filter')
复现步骤
预期结果
相关截图
这个问题我也遇到了,linuxDo社区上也有提到,概率性问题,好像没有修复过,很多依赖于这个平台的镜像站,接入cc都会时不时报这个错误。
如果能提供可以必定复现的案例就更好了,因为现在找不到问题,
如果能提供可以必定复现的案例就更好了,因为现在找不到问题,
报错内容是 JS 的数组 filter 遍历,盲猜是 go 的空数组JSON序列化后转为了 nil 导致
如果能提供可以必定复现的案例就更好了,因为现在找不到问题,
报错内容是 JS 的数组 filter 遍历,盲猜是 go 的空数组JSON序列化后转为了 nil 导致
newapi对claude渠道类型返回内容都是原样返回,没有经过序列化的
如果能提供可以必定复现的案例就更好了,因为现在找不到问题,
我可以提供下我观察到的具体表现,供大佬分析下。
准备工作
首先A、B两个渠道全部都是能正常在 Claude Code 正常使用输出的,然后故意给A渠道的秘钥填写错误让其服务返回401,B渠道正常。
同时得知, Claude Code 请求对话出错之后会自动重试,最后开启渠道自动禁用。
有意思的来了:
当系统只有一个无法正常使用的A渠道的时候,那么 Claude Code 会直接报错,这里的报错会显示正常的错误信息,json格式的(一般就是第三方服务的原始错误),此为正常现象。
一旦B渠道能正常工作, 那么 A渠道因为401错误导致客户端重试请求, 这时候因为A渠道因上次失败而自动禁用, 重试的请求直接打到B渠道上,就会发现 B 渠道的在输出内容在日志中是正常的流式结果,一旦B渠道流式输出结束之后, Claude Code 立即显示 API Error: Cannot read properties of undefined (reading 'filter') 错误信息。
我简单的理解下就是 Claude Code 遇到错误自动重试请求之后,即使后续请求成功也会显示错误。
这也与之前一些镜像站出现了 API Error: Cannot read properties of undefined (reading 'filter') 错误之后依旧计费的原因。
如果能提供可以必定复现的案例就更好了,因为现在找不到问题,
报错内容是 JS 的数组 filter 遍历,盲猜是 go 的空数组JSON序列化后转为了 nil 导致
newapi对claude渠道类型返回内容都是原样返回,没有经过序列化的
我在其他类似的问题下发现有人反馈 openrouter 集成到 CC 也有类似的情况出现:https://github.com/anthropics/claude-code/issues/4788#issuecomment-3172667043
same to me. And sometimes bash instruction won't excute or ask for permission when it looks like already excuting.
Edit: And sometimes bash instruction won't excute or ask for permission when it looks like already excuting. that's another error at https://github.com/musistudio/claude-code-router/issues/473
测试过了,如果大家不嫌麻烦可以自己装ccr,把响应结果包装一下ccr启动claude,就不会报错了,但是这没有从根源上解决问题,权宜之计罢了,如果大家在乎连续的使用体验,还是弄一下吧,不费时间,一天就搞定了。
I’ve found a workaround: we can use claude-code-router to wrap the response into the Anthropic format and then start Claude Code. This prevents the issue from occurring, but it’s only a stop-gap measure—not a root-cause fix, merely a permanent adaptation.
我也是,甚至没有流式输出,问第二句就是filter了
同样的问题,坐等大佬排查
我也是,搞得都暂时用litellm了。但是这个litellm还是不太好用。
测试过了,如果大家不嫌麻烦可以自己装ccr,把响应结果包装一下ccr启动claude,就不会报错了,但是这没有从根源上解决问题,权宜之计罢了,如果大家在乎连续的使用体验,还是弄一下吧,不费时间,一天就搞定了。
I’ve found a workaround: we can use claude-code-router to wrap the response into the Anthropic format and then start Claude Code. This prevents the issue from occurring, but it’s only a stop-gap measure—not a root-cause fix, merely a permanent adaptation.
大佬,请教下我用docker部署了ccr,但是可能config.json写得不好,报错:
我的config配置:
{
"LOG": false,
"LOG_LEVEL": "debug",
"CLAUDE_PATH": "",
"HOST": "0.0.0.0",
"PORT": 3456,
"APIKEY": "sk-my-api-keys",
"API_TIMEOUT_MS": "600000",
"PROXY_URL": "",
"transformers": [
{
"name": "",
"path": "Anthropic",
"options": {}
}
],
"Providers": [
{
"name": "MySelfHost",
"api_base_url": "https://newapi.domain.cn/v1/chat/completions",
"api_key": "sk-eWv8az107B1C7",
"models": [
"claude-3-5-haiku-20241022",
"claude-3-5-sonnet-20241022",
"claude-3-7-sonnet-20250219",
"claude-opus-4-1-20250805",
"claude-opus-4-20250514",
"claude-sonnet-4-20250514",
"gemini-2.5-pro",
"claude-opus-4-20250514-thinking"
]
}
],
"StatusLine": {
"enabled": false,
"currentStyle": "default",
"default": {
"modules": []
},
"powerline": {
"modules": []
}
},
"Router": {
"default": "MySelfHost,claude-sonnet-4-20250514",
"background": "MySelfHost,claude-sonnet-4-20250514",
"think": "MySelfHost,claude-sonnet-4-20250514",
"longContext": "MySelfHost,claude-sonnet-4-20250514",
"longContextThreshold": 60000,
"webSearch": "MySelfHost,claude-sonnet-4-20250514",
"image": "MySelfHost,claude-sonnet-4-20250514"
},
"CUSTOM_ROUTER_PATH": ""
}
我也遇到了
我也遇到了. same here
API Error: Cannot read properties of undefined (reading 'map')
API Error: Cannot read properties of undefined (reading 'map')
API Error: Cannot read properties of undefined (reading 'map')
你们上面发的这个报错是自己部署的最新版本服务吗....还是说别人的
近期发现一个现象:
claude code 接入new-api ,如果请求的模型是Anthropic渠道类型,则该请求正常响应;如果请求的模型是openai渠道类型转化的claude请求格式,经常容易出现这个错误。
所以用claude code调用new api时,对应分组最好都是 Anthropic 渠道。
以上是我的观察,不一定正确。各位可以试一下。
你们上面发的这个报错是自己部署的最新版本服务吗....还是说别人的
确实是自己部署的当时最新版本。