feat: add multi-account support with automatic rate limit rotation#97
feat: add multi-account support with automatic rate limit rotation#97tiltroom wants to merge 1 commit intonumman-ali:mainfrom
Conversation
Implement multi-account management allowing users to authenticate multiple ChatGPT accounts during initial OAuth flow and automatically rotate between them when rate limits are encountered. Key changes: - Add AccountManager class for managing multiple accounts with rate limit tracking - Extend OAuth flow to prompt for additional accounts (up to 10) - Add persistent account storage in ~/.opencode/openai-codex-accounts.json - Implement automatic account rotation on 429 responses - Add CLI tool 'codex-accounts' for account management (add/list/remove) - Add new types for multi-account support (ManagedAccount, AccountStorage, etc.) - Add comprehensive test coverage for account management logic
|
Because of expiring refresh tokens, the rotation could happen in certain intervals, e.g. 5% weekly used, as an idea |
Keep in mind that every time we get a 429 it will switch to the next account. I expect pretty much a sort of round robin distribution and "organic" refreshes. |
|
here u go i hope it helps |
Yes but sometimes you leave the other accounts bare for whatever reason. |
|
He's taking his time. |
Summary
codex-accountscommand for add/list/remove operations outside OAuth flowProblem
Heavy users of the Codex plugin frequently hit ChatGPT's rate limits, causing interruptions. Users with multiple ChatGPT subscriptions (personal, work, etc.) have no way to leverage them for increased throughput.
Solution
This PR implements multi-account management that:
Changes
lib/accounts/manager.tsAccountManagerclass with round-robin rotation, rate limit trackinglib/accounts/storage.ts~/.opencode/openai-codex-accounts.jsonlib/accounts/cli.tsscripts/manage-accounts.jscodex-accounts add/list/remove)lib/types.tsManagedAccount,AccountStorage,OAuthAuthDetails,RateLimitStatelib/constants.tsMAX_ACCOUNTS = 10lib/auth/auth.tsisOAuthAuth()andaccessTokenExpired()helpersindex.tstest/accounts.test.tspackage.jsoncodex-accountsbin entryHow It Works
Authentication Flow
Refresh Token Format
Multiple accounts are encoded in the refresh token field:
Rate Limit Handling
Retry-AfterheaderCLI Management
Storage Locations
~/.local/share/opencode/openai-codex-accounts.json~/.local/share/opencode/openai-codex-accounts.json%APPDATA%/opencode/openai-codex-accounts.jsonTesting
Added comprehensive test suite in
test/accounts.test.tscovering:Backwards Compatibility