Skip to content

Enable user to add API Key while being signed in. #20899

@divyamagrawal06

Description

@divyamagrawal06

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    authIssues related to authentication and accountsenhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions