pi-ultraswitch0.3.0
Loop through the usage limits of the coding plans of the OSS models — GLM (Z.AI) Coding Plan multi-account key rotation for the Pi coding agent: balanced quota usage, live usage in the status bar, auto-failover.
Untested on omp
This is a pi package. No one has reported whether it works on omp yet. If you try it, add your result below.
Reports 0
No reports yet.
Readme
pi-ultraswitch
Loop through the usage windows of your coding-plan subscriptions (Z.AI GLM, Kimi for Coding) in the Pi coding agent: switch only when requests actually fail (429) — no restarts, live usage in the status bar.
Install
pi install git:github.com/KonstantinMirin/pi-ultraswitch
Add the key commands to
~/.pi/agent/models.json:{ "providers": { "zai": { "apiKey": "!cat ~/.pi/zai-keys/current" }, "kimi-coding": { "apiKey": "!cat ~/.pi/kimi-keys/current" } } }Add keys (mode 600, one per line per subscription):
mkdir -p ~/.pi/zai-keys/keys ~/.pi/kimi-keys/keys (umask 077; pbpaste > ~/.pi/zai-keys/keys/work) # Z.AI key from clipboard ln -sfn keys/work ~/.pi/zai-keys/current (umask 077; pbpaste > ~/.pi/kimi-keys/keys/main) # Kimi key from clipboard ln -sfn keys/main ~/.pi/kimi-keys/current/reloadin each running session (new sessions pick everything up).
Use
- Status bar shows your session's account and each provider's headroom,
refreshed every 90 s:
⇄ zai/work · 28%/5h · 5%/wk · reset 01:41 | kimi-coding 0%/5h /model— pick any model; the extension keeps the provider behind it healthy. Your choice affects only this session.- Switching is 429-driven only: the extension never rotates keys or crosses providers based on usage percentages. When requests fail with sustained 429s, it switches to a working key (same provider first, then cross). No balancing, no cross-back — just failure-driven failover.
/uswitch— interactive status table (selecting an account switches to it), plus:/uswitch next— best available account other than the current one/uswitch use <label>or<model id>— e.g.use work,use glm-5.3,use k3; bare/uswitch glm-5.3works too/uswitch add— register a new key (validated before saving)
zswap— shell CLI for the zai store:zswap,zswap <label>,zswap status
Model mapping
Where your session lands when it crosses providers (bidirectional,
overridable in ~/.pi/ultraswitch/config.json):
| zai | kimi-coding |
|---|---|
glm-5.2 |
k3 |
glm-5.3 |
k3.1-pro |
glm-5.2-highspeed |
kimi-k2.7-code-highspeed |
glm-5.3-flash |
k3-256k |
Config (optional)
~/.pi/ultraswitch/config.json:
{
"accounts": { "zai/work": { "max5hPct": 50 } },
"mappings": { "zai/glm-5.2": "kimi-coding/k3" },
"crossBalance": false,
"policy": { "crossMinIntervalMs": 1800000 }
}
max5hPct— cap an account's 5-hour window (benched at the cap until reset)mappings— extra model equivalence pairscrossBalance— also switch providers on usage gaps (default: only on exhaustion)policy— override policy constants (e.g. the cross cooldown)
How it works, in principle
Each provider's key is resolved per request by the !cat command above, so
flipping the current symlink moves every session at once, instantly.
Within a provider, keys are kept within 8 points of each other
(invisible — same model). When your provider has no usable account left,
your session — and only your session — switches to the mapped model on the
other provider, and returns home when it recovers. Usage percentages come
from each provider's own usage API, polled every 90 seconds.
Full details: docs/architecture.md.