[BUG] API Error: 400 Invalid 'user_id': string does not match pattern. Expected a string that matches the pattern '^[a-zA-Z0-9_-]+$'.
Resolved 💬 17 comments Opened May 6, 2026 by xiaowang-code Closed May 12, 2026
💡 Likely answer: A maintainer (dicksontsai, collaborator)
responded on this thread — see the highlighted reply below.
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
我正在用Claude Agent,然后报错
API Error: 400 Invalid 'user_id': string does not match pattern. Expected a string that matches the pattern '^[a-zA-Z0-9_-]+$'.
What Should Happen?
API报错
Error Messages/Logs
Steps to Reproduce
API报错
Claude Model
None
Is this a regression?
No, this never worked
Last Working Version
_No response_
Claude Code Version
2.1.129 (Claude Code)
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
VS Code integrated terminal
Additional Information
_No response_
17 Comments
我也是,正常对话过程中,突然就报错了。期间没有改动任何配置
1
me too
11
me too help help
The same situation.
<img width="1624" height="484" alt="Image" src="https://github.com/user-attachments/assets/985d76ed-3db8-404c-abd8-3c4cec64d834" />
me too
不会遇到这个问题的,用的模型都是deepseek v4吧
I am using DeepSeek V4 API with Claude Code, and I saved
export ANTHROPIC_USER_ID=<USER_ID>to~/.zshenvand it works now for me.export ANTHROPIC_USER_ID=<USER_ID>, what is the USER_ID
Just a random name to satisfy
^[a-zA-Z0-9_-]+$pattern.是的,直接删除cc,换成ccb也能继续用,哈哈
刚才还在报错呢。而在期间,我还是没有做任何改动,又恢复正常了。是不是API波动?你们现在正常了吗?
<img width="1170" height="267" alt="Image" src="https://github.com/user-attachments/assets/b69f4dc4-c634-426e-a00a-38719ccee955" />
not use cc-switch
Same here — Claude Code 2.1.131 + deepseek-v4-pro on WSL2.
Our findings after investigating session crash logs:
~/.openclaw/skill-workspace/). The session worked fine for many turns, then suddenly every subsequent request got this 400 error immediately (0s response time).export ANTHROPIC_USER_ID=jarvis(any string matching^[a-zA-Z0-9_-]+$) resolves it.user_idmore strictly than Anthropic's. When CC doesn't explicitly set it (or it gets unset/corrupted mid-session), the request is rejected at the gateway level before reaching the model.Adding this for the
needs-reprolabel — the issue is consistently reproducible with deepseek-v4-pro without ANTHROPIC_USER_ID set.We do not officially support DeepSeek.
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.