Skip to content

unexpected status 401 Unauthorized Codex

Quick fix

Use the built-in DeepSeek template instead of a hand-built config, or add http_headers to the config file by hand to pass the API Key.

Error output
unexpected status 401 Unauthorized: Incorrect API key provided: 123456. You can find your API key at https://platform.openai.com/account/api-keys., url: https://api.openai.com/v1/responses, cf-ray: a1ffe910ba36683c-NRT, request id: f56e5cc5-be53-4a44-aa57-efacc1869ac0

Switching Codex to a third-party provider such as DeepSeek in cc-switch with a hand-built configuration, key settings may not be written completely or the routing override may be partial, so Codex still sends requests to the official OpenAI address carrying the wrong auth information — hence the 401. Codex has also become stricter about the configuration format since its update, and a hand-built config easily misses a required field.

  1. Use the DeepSeek Codex template config file built into cc-switch instead of a hand-built provider configuration, so all the key parameters are present.

  2. If the problem persists, add the http_headers field to the config file by hand to force the correct API Key format.

ToolCodex
Version3.16.3 - 3.17.0
PlatformsmacOSWindows
Why does the speed test in cc-switch pass while Codex reports 401?
A passing speed test only proves the network path from cc-switch to the provider works and the Key is valid. The Codex client may not read the auth header cc-switch injects, or may still send requests to the official OpenAI address — add http_headers to the configuration by hand.
My Codex sidebar chat history disappeared after switching provider. What now?
That is a known effect of enabling model_provider="cc-switch": the old history is hidden in the sidebar but still findable by search. Removing the provider config brings the history back but makes DeepSeek return 401 again, so getting the model working should come first.

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.