[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_

View original on GitHub ↗

17 Comments

TFL-TFL · 2 months ago

我也是,正常对话过程中,突然就报错了。期间没有改动任何配置

lilelewod · 2 months ago

1

ForinMH · 2 months ago

me too

lxpStu · 2 months ago

11

yangyixiang-cc · 2 months ago

me too help help

lvxingqi · 2 months ago

The same situation.

<img width="1624" height="484" alt="Image" src="https://github.com/user-attachments/assets/985d76ed-3db8-404c-abd8-3c4cec64d834" />

suncan0207 · 2 months ago

me too

lxpStu · 2 months ago

不会遇到这个问题的,用的模型都是deepseek v4吧

brian-pakhin · 2 months ago

I am using DeepSeek V4 API with Claude Code, and I saved export ANTHROPIC_USER_ID=<USER_ID> to ~/.zshenv and it works now for me.

ForinMH · 2 months ago
I am using DeepSeek V4 API with Claude Code, and I saved export ANTHROPIC_USER_ID=<USER_ID> to ~/.zshenv and it works now for me.

export ANTHROPIC_USER_ID=<USER_ID>, what is the USER_ID

brian-pakhin · 2 months ago
> I am using DeepSeek V4 API with Claude Code, and I saved export ANTHROPIC_USER_ID=<USER_ID> to ~/.zshenv and 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.

ziqtech · 2 months ago
不会遇到这个问题的,用的模型都是deepseek v4吧

是的,直接删除cc,换成ccb也能继续用,哈哈

TFL-TFL · 2 months ago
我也是,正常对话过程中,突然就报错了。期间没有改动任何配置

刚才还在报错呢。而在期间,我还是没有做任何改动,又恢复正常了。是不是API波动?你们现在正常了吗?

<img width="1170" height="267" alt="Image" src="https://github.com/user-attachments/assets/b69f4dc4-c634-426e-a00a-38719ccee955" />

ForinMH · 2 months ago

not use cc-switch

Jarvis-Baba · 2 months ago

Same here — Claude Code 2.1.131 + deepseek-v4-pro on WSL2.

Our findings after investigating session crash logs:

  1. Trigger: Seems to occur after ~30-60min of active use. In our case it happened while CC was reading files from a local workspace directory (~/.openclaw/skill-workspace/). The session worked fine for many turns, then suddenly every subsequent request got this 400 error immediately (0s response time).
  1. Behavior: Once triggered, all retries fail instantly. The session becomes completely unusable — restarting Claude Code is the only fix. If you keep retrying in the same session, CC eventually hangs.
  1. Workaround confirmed: export ANTHROPIC_USER_ID=jarvis (any string matching ^[a-zA-Z0-9_-]+$) resolves it.
  1. Speculation: Looks like deepseek's API gateway validates user_id more 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-repro label — the issue is consistently reproducible with deepseek-v4-pro without ANTHROPIC_USER_ID set.

dicksontsai collaborator · 2 months ago

We do not officially support DeepSeek.

github-actions[bot] · 15 days ago

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.