Enable user to add API Key while being signed in.

Resolved 💬 2 comments Opened May 3, 2026 by divyamagrawal06 Closed May 3, 2026
💡 Likely answer: A maintainer (etraut-openai, contributor) responded on this thread — see the highlighted reply below.

What variant of Codex are you using?

CLI, App

What feature would you like to see?

/add-api-key while being signed in with a ChatGPT account.

  • Fallback API key in cred store
  • User uses codex as normal
  • When limits run out, just switches to API key
  • This feature can be extended to the App and it benefits app users as well.

Why?

  • People using codex with an API key will likely have a ChatGPT account that they would prefer using before using API.
  • This is a big pain point as it means having to constantly log out and log in. Often, it means having to generate a new key as you would copy/paste the key only once.

Additional information

Proposed Solution

  1. New fallback API key in the cred store

Extend AuthDotJson (in codex-rs/login/src/auth/) to optionally store a secondary fallback_openai_api_key field alongside ChatGPT tokens. only used when the primary ChatGPT session hits a rate/usage limit.

  1. New TUI slash command: /add-api-key <sk-…>

Add SlashCommand::AddApiKey to codex-rs/tui/src/slash_command.rs with supports_inline_args() = true. The dispatch arm in codex-rs/tui/src/chatwidget/slash_dispatch.rs would call a new AppEvent::AddFallbackApiKey { key }.

  1. New app-server method: account/addFallbackApiKey

Add a new method to the app-server protocol (codex-rs/app-server-protocol/src/protocol/v2.rs) that stores the fallback key without touching the active ChatGPT session. distinct from account/login/start { type: "apiKey" }, as that replaces the session.

  1. Automatic fallback in the model client

In codex-rs/protocol/src/error.rs (or the model client layer), when a UsageLimitReachedError is detected and a fallback API key is stored, the session should swap the active CodexAuth in-memory (without writing to disk) to CodexAuth::ApiKey for the remainder of the session

View original on GitHub ↗

2 Comments

etraut-openai contributor · 3 months ago

I think it's unlikely that we would implement a solution like the one you've outlined above. We don't recommend switching between accounts, so this isn't something we'd want to encourage.

If you need to purchase additional usage when you run low on your ChatGPT subscription, you can purchase additional credits that are associated with your main account. For details, refer to this documentation. Using this approach, you don't need to switch accounts.

divyamagrawal06 · 3 months ago

@etraut-openai You're right about purchasing credits at chatgpt.com/codex/settings/usage.

But my original request is about a different scenario: someone having prepaid API credits on platform.openai.com (tied to the same OpenAI/ChatGPT account) and wants to use _that_ when the sub limit is hit, (without logging out.)

Currently the code explicitly blocks adding an API key while ChatGPT auth is active. So even though both billing systems share the same underlying account, there is no way to use API platform credits as a fallback. The user must log out, switch to API key mode, and lose their ChatGPT session.