Standalone Go utility to automatically inspect account quotas on CLIProxyAPI and rotate active account prefixes with reserve accounts when rate limits are approached, with manual switch capabilities. Supports both Antigravity and Codex providers.
-
Providers Supported:
-
antigravity: Activeagy, Reservesagy_*(e.g.agy_1,agy_2). -
codex: Activecodex, Reservescodex_*(e.g.codex_1,codex_2). - By default, evaluates
allconfigured providers.
-
-
Hierarchical Profile-Based Pools:
- Dynamic automatic detection of profiles from prefixes for both
antigravityandcodex. -
Default / Root Pool (empty profile):
- Active prefix:
agyorcodex - Reserve prefixes:
agy_<index>(e.g.agy_1,agy_2) orcodex_<index>(e.g.codex_1)
- Active prefix:
-
Profile Pool P (e.g.
p1,team_a):- Active prefix:
<provider>_<profile>(e.g.agy_p1,codex_p1,agy_team_a) - Reserve prefixes:
<provider>_<profile>_<index>(e.g.agy_p1_1,agy_p1_2,codex_p1_1)
- Active prefix:
-
Profile Isolation: Each profile pool evaluates and rotates independently. When an active account in profile
p1reaches quota limits, it is swapped with the best reserve withinp1, leaving the default pool and all other profiles completely unaffected.
- Dynamic automatic detection of profiles from prefixes for both
-
Rotation Triggers:
- 5-Hour limit consumed
$\ge 90%$ , OR - Weekly limit consumed
$\ge 95%$ .
- 5-Hour limit consumed
-
Window Handling (Policy 1A):
- If an upstream provider returns only the
Weeklywindow (or single window), the 5-hour requirement is gracefully omitted and only the available window is evaluated.
- If an upstream provider returns only the
-
Multi-Group Aggregation (Policy 2A):
- When quota responses contain multiple model groups, the worst-case limit (lowest remaining capacity) across all groups is evaluated.
-
Active-first quota checks:
- Metadata is refreshed on each run to detect external prefix changes. Routine rotation checks query the active account first; reserves in the same provider/profile pool are queried only after the active reaches a rotation threshold.
- A known problem active is not queried again; its cache identity is removed and healthy same-provider/profile reserves are evaluated for replacement. Newly detected account-local auth/quota failures follow the same path.
-listremains an explicit quota view, while--reviewretries recorded problem accounts and can restore cache eligibility after resolution. - Provisionally, an outer HTTP 400 from the per-account quota
api-callrequest is treated as account-local so healthy accounts and profiles can continue; other management statuses, transport failures, and discovery/metadata errors remain fatal. Safe typed failure reasons and status codes are stored per account instate.json; response bodies and arbitrary error text are not persisted.
-
Reserve Account Selection (Policy 3B):
- The reserve account with the highest minimum remaining quota across its available windows is selected as the replacement.
-
Direct Prefix Swap (Policy 4A):
- Swaps prefixes directly (
active$\leftrightarrow$ candidate reserve prefix) promoting the reserve first to avoid request routing downtime.
- Swaps prefixes directly (
-
Credential Storage:
- Credentials and endpoint are stored under
~/.local/share/cpamc-auto-switcher/config.jsonwith strict directory (0700) and file (0600) permissions.
- Credentials and endpoint are stored under
cd cpamc-auto-switcher
go install ./cmd/cpamc-auto-switcherRun interactive setup to configure the endpoint URL, management key, and quota thresholds:
cpamc-auto-switcher -initThe interactive wizard supports both initial setup and updating existing configurations:
- Endpoint URL: Displays the current endpoint (or
http://localhost:8317by default). Pressing Enter retains the current endpoint. - Management Key: If a key is already saved, displays
[leave blank to keep current]; pressing Enter keeps the existing key. On first-time setup, a non-empty key is required. - 5-Hour Threshold: Displays the current or default percentage (default
90.0). Pressing Enter keeps the default, or enter a custom float. - Weekly Threshold: Displays the current or default percentage (default
95.0). Pressing Enter keeps the default, or enter a custom float. - Preserved Settings: Existing configuration settings including
provider,active_prefix,reserve_prefix_prefix, andcooldown_minutesare safely preserved when updating.
Default config file location:
~/.local/share/cpamc-auto-switcher/config.json (or supply custom path via -config <path>)
Example configuration:
{
"endpoint": "http://localhost:8317",
"management_key": "YOUR_MANAGEMENT_KEY",
"provider": "antigravity",
"active_prefix": "agy",
"reserve_prefix_prefix": "agy_",
"five_hour_threshold": 90.0,
"weekly_threshold": 95.0
}List all configured accounts for all providers (or a specific provider and profile), their current prefix status, and consumption metrics (includes a PROFILE column):
# List all providers (antigravity and codex) and all profiles:
cpamc-auto-switcher -list
# Filter by provider:
cpamc-auto-switcher -list -provider codex
cpamc-auto-switcher -list -provider antigravity
# Filter by profile (e.g. p1 or default root pool):
cpamc-auto-switcher -list -profile p1
cpamc-auto-switcher -list -profile defaultManually promote a specific account (by prefix, ID, filename, or email) to be the active account for its provider and profile pool. The previous active account for that pool is safely demoted to a reserve prefix:
# Switch Antigravity default pool:
cpamc-auto-switcher -switch "agy_1"
# Switch Antigravity profile p1:
cpamc-auto-switcher -switch "agy_p1_1"
# Switch Codex profile dev:
cpamc-auto-switcher -switch "codex_dev_1"
# Switch Codex default pool:
cpamc-auto-switcher -switch "codex_1"
# By email or filename:
cpamc-auto-switcher -switch "user@example.com.json"
# Or simulate with dry-run:
cpamc-auto-switcher -switch "agy_p1_2" -dry-runCheck quotas and simulate whether an automatic rotation would take place without altering account prefixes:
cpamc-auto-switcher -check
# or filter by provider and profile:
cpamc-auto-switcher -check -provider antigravity -profile p1Routine quota checks skip accounts whose individual quota query failed and print one concise hint. Retry every recorded account, regardless of provider/profile filters, without rotating prefixes:
cpamc-auto-switcher --reviewSuccessfully parsed quota checks with at least one usable quota window remove accounts from the review list. Missing or disabled accounts remain explicitly marked unresolved until available for review. Review status is stored in the private state.json beside the config; service-wide management errors are not treated as individual account failures.
Inspect accounts, fetch live quotas, and perform a prefix swap if limits are exceeded. Evaluates each profile pool independently. A 5-minute cooldown is enforced between quota checks by default:
# Evaluate and rotate all providers across all discovered profiles:
cpamc-auto-switcher
# Target a specific provider:
cpamc-auto-switcher -provider codex
# Target a specific profile within provider(s):
cpamc-auto-switcher -profile p1Bypass the cooldown period and query limits immediately:
cpamc-auto-switcher -forceSpecify a custom cooldown interval (e.g. 1m, 10m):
cpamc-auto-switcher -cooldown 10mDisplay detailed evaluation logs (including remaining cooldown time if active):
cpamc-auto-switcher -verboseOverride the quota consumption trigger thresholds via CLI flags for the current run without modifying config.json:
-five-hour-threshold <float>: Override the 5-hour consumption threshold percentage.-5h-threshold <float>: Short alias for-five-hour-threshold.-weekly-threshold <float>: Override the weekly consumption threshold percentage.
# Override 5-hour threshold (e.g. rotate when >= 80% consumed):
cpamc-auto-switcher -five-hour-threshold 80.0
# Using the short alias for 5-hour threshold:
cpamc-auto-switcher -5h-threshold 80.0
# Override weekly threshold (e.g. rotate when >= 90% consumed):
cpamc-auto-switcher -weekly-threshold 90.0
# Combine threshold overrides with dry-run check or automatic rotation:
cpamc-auto-switcher -check -5h-threshold 85.0 -weekly-threshold 92.0
cpamc-auto-switcher -profile p1 -5h-threshold 80.0 -weekly-threshold 90.0