ModelScope reports 401 token invalid - Claude Code
Quick fix
Add ANTHROPIC_MODEL to the provider environment variables in cc-switch to resolve the 401. It is not synced to settings.json by design.
Symptom
Section titled “Symptom”我用魔搭是报错 401 token 失效ModelScope reports 401 token invalid
Claude Code uses the native Anthropic Messages protocol, while aggregation platforms such as ModelScope usually offer an OpenAI-compatible endpoint by default. Configuring a third-party model in cc-switch requires setting the ANTHROPIC_MODEL environment variable explicitly for requests to route correctly; without it, authentication fails or the protocols do not match.
Separately, cc-switch deliberately does not write ANTHROPIC_MODEL and other model variables into ~/.claude/settings.json in proxy mode, because the model a request actually reaches is converted dynamically by the middle layer, and hard-coding it locally would interfere with the proxy layer model mapping.
Edit the relevant provider config in cc-switch and add an ANTHROPIC_MODEL field with the model name to the environment variables (env).
// cc-switch Provider settings_config{"env": {"ANTHROPIC_MODEL": "ZhipuAI/GLM-4.5"}}
Affected Versions
Section titled “Affected Versions”Source Issues
Section titled “Source Issues”This page is distilled from 2 real issues
- Why is there no ANTHROPIC_MODEL in ~/.claude/settings.json after switching provider?
- That is deliberate in cc-switch. In proxy mode the model mapping is controlled dynamically by the proxy layer, and writing model variables into the local settings.json would interfere with that dynamic substitution, so only the minimum needed to reach the proxy (BASE_URL and TOKEN) is kept.
- The model name shown in the Claude Code UI (Sonnet 4.6) does not match what is actually used. What now?
- A known limitation. Because cc-switch does not write model variables into the local config, the Claude Code interface cannot see the real model name — but that keeps the proxy logic and dynamic model mapping correct and does not affect use.
- What if my provider only offers an OpenAI-compatible endpoint?
- cc-switch currently only supports providers that natively speak the Anthropic/Claude protocol. If you must use an OpenAI-compatible endpoint, try an open-source project such as Claude Code Router for protocol conversion.
Related problems
Section titled “Related problems”This is an unofficial community wiki with no affiliation to the cc-switch authors or the project itself. Its content is compiled from the project's public GitHub issues. This site distributes no software.