Respect Codex credits when rotating accounts#24
Open
ibakaidov wants to merge 5 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes account rotation when every account has exhausted included Codex usage limits, but one account has purchased Codex credits available.
The plugin already reads
/codex/usage, including itscreditsobject, but the credit state was discarded. As a result,rateLimitedUntilfrom exhausted included usage windows could keep an account out of rotation even though Codex should continue by drawing from the account's credit balance.This also adds an explicit paid-credit allowlist so users can choose which aliases may spend credits:
OPENCODE_MULTI_AUTH_CREDIT_ACCOUNT_ALIASES: existing behavior, all aliases may use creditsOPENCODE_MULTI_AUTH_CREDIT_ACCOUNT_ALIASES=personal,work: only those aliases may use creditsOPENCODE_MULTI_AUTH_CREDIT_ACCOUNT_ALIASES=none: disable paid-credit fallbackOPENCODE_MULTI_AUTH_CREDIT_ACCOUNT_ALIASES=allor*: allow all aliasesCredit-enabled aliases are only a fallback pool. Accounts that still have included usage available are tried first; paid-credit accounts are tried only when no included-limit account is available.
OpenAI's current help docs describe the relevant behavior: included plan usage is consumed first, then usage draws from the credit balance after plan limits are reached. The Codex rate card also documents that users can view remaining credit and purchase/manage credit in Codex settings.
Refs:
What changed
OPENCODE_MULTI_AUTH_CREDIT_ACCOUNT_ALIASESand persistedcreditAccountAliasessupport./codex/usagereports a positive credit balance.rateLimitedUntilonly when usage refresh confirms an account is not blocked under the current credit policy./codex/usageafter a backend429for credit-allowed aliases, so a transient/stale 429 does not leave cached credits cleared until manual refresh.OPENCODE_MULTI_AUTH_DEBUG=1account-filter diagnostics without logging tokens or secrets.Auth invalidation, disabled accounts, unsupported models, and deactivated workspaces remain terminal blockers.
Validation
npm run lintnpm run buildnpm run test:unit -- --runInBand tests/unit/rotation-strategy.test.tsenv NO_PROXY=127.0.0.1,localhost no_proxy=127.0.0.1,localhost HTTP_PROXY= HTTPS_PROXY= ALL_PROXY= http_proxy= https_proxy= all_proxy= npm test -- --runInBandf52a2e4.opencode run --model openai/gpt-5.5 "Reply with exactly: ok"returnsok.