Skip to content

Respect Codex credits when rotating accounts#24

Open
ibakaidov wants to merge 5 commits into
floze-the-genius:mainfrom
ibakaidov:fix/codex-credits-eligibility
Open

Respect Codex credits when rotating accounts#24
ibakaidov wants to merge 5 commits into
floze-the-genius:mainfrom
ibakaidov:fix/codex-credits-eligibility

Conversation

@ibakaidov
Copy link
Copy Markdown

@ibakaidov ibakaidov commented May 14, 2026

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 its credits object, but the credit state was discarded. As a result, rateLimitedUntil from 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:

  • unset OPENCODE_MULTI_AUTH_CREDIT_ACCOUNT_ALIASES: existing behavior, all aliases may use credits
  • OPENCODE_MULTI_AUTH_CREDIT_ACCOUNT_ALIASES=personal,work: only those aliases may use credits
  • OPENCODE_MULTI_AUTH_CREDIT_ACCOUNT_ALIASES=none: disable paid-credit fallback
  • OPENCODE_MULTI_AUTH_CREDIT_ACCOUNT_ALIASES=all or *: allow all aliases

Credit-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

  • Persist parsed Codex credit state on accounts.
  • Treat accounts with usable, allowed credits as eligible when the only blocker is exhausted included usage windows.
  • Add OPENCODE_MULTI_AUTH_CREDIT_ACCOUNT_ALIASES and persisted creditAccountAliases support.
  • Keep disallowed credit accounts rate-limited even if /codex/usage reports a positive credit balance.
  • Prefer included-limit accounts before paid-credit accounts, while preserving pro/spark filtering and the configured rotation strategy inside each pool.
  • Clear stale rateLimitedUntil only when usage refresh confirms an account is not blocked under the current credit policy.
  • Add a lightweight usage refresh pass when all accounts appear rate-limited, so a newly credited account can recover without waiting for the old reset timestamp.
  • Try soft rate-limited accounts only when their alias is allowed to spend credits, as a fallback for transient usage API failures.
  • Re-check /codex/usage after a backend 429 for credit-allowed aliases, so a transient/stale 429 does not leave cached credits cleared until manual refresh.
  • Add OPENCODE_MULTI_AUTH_DEBUG=1 account-filter diagnostics without logging tokens or secrets.

Auth invalidation, disabled accounts, unsupported models, and deactivated workspaces remain terminal blockers.

Validation

  • npm run lint
  • npm run build
  • npm run test:unit -- --runInBand tests/unit/rotation-strategy.test.ts
  • env 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 -- --runInBand
  • Installed local OpenCode config dependency and OpenCode cache dependency from commit f52a2e4.
  • Verified installed cache package chooses an included-limit account before a lower-usage paid-credit account.
  • Verified real OpenCode path: opencode run --model openai/gpt-5.5 "Reply with exactly: ok" returns ok.

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.

1 participant