AuthError Missing API key - cc-switch auth header fix
Quick fix
The upstream Anthropic-compatible endpoint only reads x-api-key, so set the auth field to ANTHROPIC_API_KEY rather than ANTHROPIC_AUTH_TOKEN.
Symptom
Section titled “Symptom”{"type":"error","error":{"type":"AuthError","message":"Missing API key."}}When forwarding requests, the cc-switch Claude proxy sends an Authorization: Bearer header based on ANTHROPIC_AUTH_TOKEN by default. But Anthropic Messages-compatible endpoints such as OpenCode Go accept only the x-api-key header and ignore Bearer, so upstream returns HTTP 401 and AuthError Missing API key.
In the Claude Code CLI you can resolve this by picking the auth field on the form. The Claude Desktop provider lacks that option in some versions and still uses ANTHROPIC_AUTH_TOKEN unconditionally. A closed issue states the auth header logic was fixed: ANTHROPIC_API_KEY sends x-api-key while ANTHROPIC_AUTH_TOKEN keeps sending Bearer. Another issue notes the Claude Desktop side still needs the auth field selector added.
In the cc-switch provider config, change the auth field from ANTHROPIC_AUTH_TOKEN to ANTHROPIC_API_KEY so cc-switch sends x-api-key upstream rather than Authorization: Bearer.
cc-switch Provider 配置 {"env": {"ANTHROPIC_BASE_URL": "https://opencode.ai/zen/go/v1","ANTHROPIC_API_KEY": "sk-***","ANTHROPIC_MODEL": "minimax-m2.5"}}If you use Claude Desktop and the UI has no auth field selector, use a fixed version that adds the selector to the Claude Desktop provider form, or convert Authorization: Bearer into x-api-key with a local adapter before forwarding upstream.
Send the request again and confirm upstream no longer returns HTTP 401 and that the request headers carry x-api-key.
Affected Versions
Section titled “Affected Versions”Source Issues
Section titled “Source Issues”This page is distilled from 3 real issues
- I configured an API key — why does it still say Missing API key?
- Because cc-switch sends Authorization: Bearer while the upstream Anthropic-compatible endpoint only reads x-api-key, so it considers the API key absent.
- Why do Claude Code CLI and Claude Desktop behave differently?
- The Claude Code CLI form lets you pick the auth field and switch to ANTHROPIC_API_KEY; the Claude Desktop provider in some versions uses ANTHROPIC_AUTH_TOKEN unconditionally with no such option.
- Why does the OpenAI format work?
- OpenAI-compatible endpoints accept Authorization: Bearer, so the openai_chat format is unaffected by this problem.
- How do I work around it without a fixed version?
- Put a local adapter between cc-switch and upstream that converts Authorization: Bearer into x-api-key before forwarding.
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.