Skip to content

HTTP 401 Unauthorized - CC Switch Anthropic

Quick fix

Upgrade cc-switch to a fixed build so it sends the x-api-key and anthropic-version headers Anthropic requires.

Error output
fetch_models returns 401 for Anthropic-compatible endpoints due to missing auth headers

The cc-switch `fetch_models` function sends only an `Authorization: Bearer <key>` header by default when fetching a model list. But Anthropic-compatible endpoints (`api.anthropic.com` or a third-party provider) require `x-api-key: <key>` and `anthropic-version: 2023-06-01` as well. Missing those necessary auth headers, the server returns HTTP 401 Unauthorized.

This was resolved in a downstream branch (SaladDay/cc-switch-cli) by introducing a `ModelFetchStrategy` enum that sends the right header combination per provider type: a Bearer token for OpenAI style, Bearer plus x-api-key plus the version header for Anthropic style, and x-goog-api-key for Gemini style.

  1. Check whether your cc-switch version has merged the upstream or SaladDay branch fix. If you are on an official build that has not been updated, try a build containing this fix (the SaladDay branch, for example).

  2. If you cannot change build, make sure the API key in your Anthropic config is set correctly as a workaround, and be aware that Fetch Models by hand may still fail, so enter model names manually.

ToolClaude Code / Codex
Version3.14.1
PlatformsWindowsmacOSLinux
I configured a local proxy address — why do I still get 401?
Issue #2514 mentions a user configuring a local CPA reverse proxy address while the error pointed at the official OpenAI address. That usually means cc-switch did not apply the custom baseUrl config correctly, or the proxy itself does not pass authentication through properly. Check baseUrl is set correctly in the config file, and that the proxy forwards the specific headers Anthropic needs (x-api-key and so on).
How do I specify a model by hand to avoid Fetch Models failing?
When fetch_models fails with a 401, enter the model name directly in the cc-switch config screen or config file ('claude-sonnet-4-20250514', for example), with no need for the automatic fetch.

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.