Skip to content

Provider API Key Overwritten: After Codex Restart or Switch

Quick fix

Upgrade to cc-switch v4.0.0 or later to prevent provider keys from overwriting each other and restore the official login state.

Error output
供应商 A 和 B 的 API Key 在重启/切换后互相覆盖。
English translation

Provider A and B’s API Keys overwrite each other after a restart or switch.

The old Codex switching logic backfilled or synchronized API Keys between provider settings in the database and the shared `~/.codex/auth.json`. Because `auth.json` has only one shared `OPENAI_API_KEY`, restarting, switching providers, or enabling a new provider could write another provider’s old key into the current provider record. Other issues included a third-party key remaining after switching back to the official provider, and direct switching on v3.19.2 not writing to the live configuration. These are different behaviors in the same switching flow.

  1. Upgrade to cc-switch v4.0.0 or later. The maintainer said this version rewrites Codex provider switching logic to prevent old live configuration from overwriting provider keys, and restores the saved ChatGPT login state when switching back to the official provider.

  2. If you are still on an old version and the official account login state is affected, the temporary workaround described in the issue is to manually remove `OPENAI_API_KEY` from `~/.codex/auth.json`, then run `codex login` to authenticate again.

ToolCodex
Version3.16.4 - 3.19.2(受影响版本;维护者称 v4.0.0 已修复)
PlatformsWindowsmacOS
Is there a fix? This bug is so annoying; I can’t use the relay anymore.
The maintainer said the switching flow was redone in v4.0.0; upgrade to v4.0.0 or later.
Why does the API Key show an old value when editing a third-party provider?
In older versions, editing the current provider could read the `auth.json` value from the live configuration first, instead of the Key saved for that provider in the database. The maintainer recommended upgrading to v4.0.0.
After switching back to the official provider, the account name shows OpenAI. How can I restore it?
The temporary workaround in the issue is to remove `OPENAI_API_KEY` from `~/.codex/auth.json`, then run `codex login` to authenticate again. The maintainer said v4.0.0 handles third-party keys and restores the saved ChatGPT login.

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.