Skip to content

OAuth multi-account rotation and account management - #9651

Closed
jroth1111 wants to merge 4 commits into
openai:mainfrom
jroth1111:oauth-marathon
Closed

jroth1111 wants to merge 4 commits into
openai:mainfrom
jroth1111:oauth-marathon

Conversation

@jroth1111

Copy link
Copy Markdown

OAuth Marathon 🏃 — Keep running when you hit the wall. Automatic credential rotation for Codex OAuth: when one account hits rate limits or auth errors, Codex seamlessly switches to your next available ChatGPT credential.

The Problem

Codex currently stores a single ChatGPT OAuth credential. When that account hits rate limits or encounters auth refresh failures, long sessions are interrupted and require manual re-login or switching to an API key.

Proposed Solution

  • Persist multiple ChatGPT OAuth accounts in a versioned auth store.
  • Add automatic rotation for OpenAI + ChatGPT auth that:
    • skips accounts in cooldown/exhausted states,
    • refreshes once on 401/403 and retries the same account,
    • honors Retry-After on 429 before moving to the next account,
    • retries network/timeout/build errors on the same account before rotating.
  • Provide CLI flows to list and remove accounts.
  • Surface a compact rotation summary in the TUI status view.
  • Allow tuning via config for cooldowns, retries, and max attempts.

How to Add Multiple Accounts

  1. Log in multiple times (each login adds a new OAuth record):
codex login
  1. List stored accounts:
codex login accounts
  1. Remove a single account by id/email/label:
codex logout --account <id|email|label>
  1. Remove all OAuth accounts (keeps API key):
codex logout --all-accounts

Architecture Overview

graph TD
  A[Codex Client Request] --> B{OpenAI + ChatGPT auth?}
  B -- no --> Z[Use existing auth path]
  B -- yes --> C[OAuthRotationPlan]
  C --> D[Auth Store v2]
  D --> E[Ordered OAuth Records]
  E --> F{Pick Next Candidate}
  F -->|Ready| G[Send Request]
  G --> H{Response}
  H -->|200| I[Record Success]
  H -->|401/403| J[Refresh Once + Retry]
  H -->|429| K[Cooldown by Retry-After]
  H -->|402/other| L[Cooldown / Exhaust]
  H -->|Network/Timeout| M[Retry Same Account]
  J --> N{Retry Result}
  N -->|OK| I
  N -->|Fail| O[Rotate + Mark]
  K --> O
  L --> O
  M --> O
  O --> F
Loading

Use Cases

  • Long-running sessions that hit rate limits mid-stream.
  • Users with multiple ChatGPT workspaces/accounts who want reliability without API keys.
  • Recovery from transient auth refresh failures without interrupting workflows.

Demo

  • CLI list view: codex login accounts
  • Rotation summary in status: see TUI “OAuth rotation” line.
  • End-to-end rotation behaviors are exercised in core/tests/suite/oauth_rotation.rs.

Why

Refs #9648.

Tests

  • just fmt
  • just fix -p codex-core
  • just fix -p codex-cli
  • just write-config-schema
  • PATH=/bin:/usr/bin:/usr/local/bin:/opt/homebrew/bin cargo test -p codex-core
  • cargo test -p codex-cli

@github-actions

github-actions Bot commented Jan 22, 2026 •

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@jroth1111

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Jan 22, 2026
@etraut-openai

Copy link
Copy Markdown
Contributor

Our contribution guidelines state that we're not accepting feature contributions at this time. We need to make sure that all new features are well designed, compose well with both existing and upcoming features, fit into our roadmap, and are consistent across all Codex surfaces (CLI, IDE extension, web). If you would like to propose a new feature, please file or upvote an enhancement request in the issue tracker. We will generally prioritize new features based on community feedback.

@jroth1111

Copy link
Copy Markdown
Author

Thanks for the clarification. I’m disappointed that’s the current approach, but I understand the policy. I’ll move the details to the enhancement issue and add any extra context there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants