codex - 💡(How to fix) Fix Enable user to add API Key while being signed in. [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openai/codex#20899Fetched 2026-05-04 05:08:22
View on GitHub
Comments
1
Participants
2
Timeline
10
Reactions
0
Timeline (top)
labeled ×5unlabeled ×3closed ×1commented ×1

Error Message

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

Fix Action

Fix / Workaround

  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 }.
RAW_BUFFERClick to expand / collapse

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.

  2. 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 }.

  3. 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.

  4. 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

extent analysis

TL;DR

Implement a fallback API key feature that allows users to seamlessly switch to an API key when their ChatGPT account hits a rate or usage limit.

Guidance

  • To implement the fallback API key feature, extend the AuthDotJson struct to store a secondary fallback_openai_api_key field alongside ChatGPT tokens.
  • Add a new TUI slash command /add-api-key <sk-…> that calls the AppEvent::AddFallbackApiKey event to store the fallback key.
  • Create a new app-server method account/addFallbackApiKey to store the fallback key without replacing the active ChatGPT session.
  • Modify the model client layer to automatically swap to the fallback API key when a UsageLimitReachedError is detected.

Example

// Extend AuthDotJson to store fallback API key
struct AuthDotJson {
    // ...
    fallback_openai_api_key: Option<String>,
}

// Add new TUI slash command
enum SlashCommand {
    // ...
    AddApiKey { key: String },
}

// Create new app-server method
enum AppEvent {
    // ...
    AddFallbackApiKey { key: String },
}

Notes

The implementation details may vary depending on the specific requirements and constraints of the Codex project. This guidance provides a general outline of the steps needed to implement the fallback API key feature.

Recommendation

Apply workaround by implementing the proposed solution, as it addresses the pain point of having to constantly log out and log in when switching between ChatGPT accounts and API keys.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

codex - 💡(How to fix) Fix Enable user to add API Key while being signed in. [1 comments, 2 participants]