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.
Symptom
Section titled “Symptom”供应商 A 和 B 的 API Key 在重启/切换后互相覆盖。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.
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.
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.
Affected Versions
Section titled “Affected Versions”Source Issues
Section titled “Source Issues”This page is distilled from 6 real issues
- #3646Bug: 编辑第三方 Codex provider 时 API Key 字段显示陈年旧值(来自 auth.json)
- #4849供应商 API Key 保存后不写 auth.json,重启时被反向覆盖
- #5691Codex: 启用自定义供应商时,Live 配置被回填到新供应商的 DB 记录,覆盖已保存的 API Key 和参数
- #5946供应商切换时第三方 Key 被官方登录态覆盖的问题
- #6236[macOS] v3.19.2 切换 Codex 供应商不写入 ~/.codex/config.toml 与 auth.json,配置不生效
- #6384Switching from routing-enabled provider to official provider leaves stale API key in auth.json
- 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.
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.