@bacnh85/pi-sub
v0.1.14
Published
Pi extension showing subscription usage for supported model providers.
Maintainers
Readme
pi-sub
Pi extension that shows subscription usage for the currently selected supported model provider.
Supports OpenAI Codex (openai-codex) with live usage windows from ChatGPT's usage endpoint, OpenCode Go (opencode-go) with session cost tracking, and Z.ai (zai) with GLM Coding Plan quota monitoring. Displays a subscription footer status after Pi's built-in status/token usage line.
Install
From npm after the package is published:
pi install npm:@bacnh85/pi-subFrom this repository checkout:
pi install ./pi-sub
# or test directly
pi -e ./pi-subWhat it shows
OpenAI Codex
The footer status appears after Pi's built-in status/token usage line and includes:
- active account email/account label;
- subscription plan, such as
Plusin/subdetails; - 5-hour remaining quota and reset countdown;
- weekly remaining quota and reset countdown.
Example subscription line:
([email protected]) R:15%/2H W:20%/3D 42 tok/sOpenCode Go
OpenCode Go does not expose a public usage-window API, so the footer shows the active account/key label, accumulated session cost, and last response speed:
OpenCode Go (OpenCode Go key#1a2b3c4d) $0.23 42 tok/sZ.ai
Z.ai (GLM Coding Plan) shows the active account/key label, 5-hour rolling and weekly remaining quota with reset countdowns, and last response speed:
(Z.ai key#1a2b3c4d) R:55%/2H W:80%/3D 42 tok/sTokens per second
pi-sub tracks each response's tokens-per-second (tok/s) speed by measuring the time from provider request to message completion against the response's output token count. The last response's speed is shown in the footer next to usage data. The /sub detail view shows both the last response speed and the session-wide average.
When the current model provider is not supported, pi-sub clears its subscription line and does not refresh subscription data.
Commands
| Command | Description |
| --- | --- |
| /sub | Show detailed subscription usage for the current supported provider. |
| /sub status | Same as /sub. |
| /sub refresh | Force a usage refresh, then show details. |
When Pi OpenAI Codex auth is available, /sub shows the active account usage and speed:
Provider: Codex · Model: o4-mini · Fetched: 14:23
Session cost: $0.12
Last response: 42 tok/s · Session avg: 39 tok/s
ACCOUNT PLAN ROLLING WEEKLY LAST ACTIVITY
* [email protected] Plus 15%/2H 20%/3D NowFor OpenCode Go, /sub shows the provider/model, active account/key label, session cost, and speed:
Provider: OpenCode Go · Model: kimi-k2.6 · Fetched: 14:23
Session cost: $0.23
Last response: 42 tok/s · Session avg: 39 tok/s
ACCOUNT PLAN LAST ACTIVITY
------------------------------------------------------
* OpenCode Go key#1a2b3c4d Go Now
OpenCode Go does not expose usage windows.For Z.ai, /sub shows the rolling and weekly quota windows and speed:
Provider: Z.ai · Model: glm-5.2 · Fetched: 14:23
Session cost: $0.05
Last response: 42 tok/s · Session avg: 39 tok/s
ACCOUNT PLAN ROLLING WEEKLY LAST ACTIVITY
------------------------------------------------------------------------
* Z.ai key#1a2b3c4d Pro 55%/2H 80%/3D NowRefresh behavior
pi-sub refreshes usage data:
- when a session starts on a supported provider;
- when switching into a supported provider;
- after provider responses, debounced;
- periodically while a supported provider remains active;
- when
/sub refreshis run.
pi-sub reads the openai-codex OAuth entry from Pi's auth file and refreshes live usage directly against ChatGPT's usage endpoint. It does not execute the codex-auth CLI and does not assume a separate Codex CLI installation exists.
Refreshes are cached briefly to avoid excessive usage endpoint calls.
Requirements and troubleshooting
- OpenAI Codex: Pi auth must contain an
openai-codexOAuth entry in~/.pi/agent/auth.jsonor$PI_CODING_AGENT_DIR/auth.json. The entry must includeaccessandaccountIdfields. - OpenCode Go: Pi auth must contain an
opencode-goAPI key entry (via/loginor env var). The entry must have akeyfield or anaccountIdfield. OpenCode Go/Zen usage windows and Zen balance are not shown because no public API is currently documented for those values. - Z.ai: Pi auth must contain a
zaientry inauth.jsonwith akeyfield (the same API key used for Z.ai model access via@czottmann/pi-zai-api). The Z.ai provider must be registered (e.g.,pi install npm:@czottmann/pi-zai-api). - For API-key-only providers, account labels come from stored auth metadata (
email,label,name, oraccountId) when available; otherwisepi-subdisplays a non-secret SHA-256 key fingerprint such asZ.ai key#1a2b3c4d. pi-subredacts auth/token-related errors and never prints credentials.
Design notes
The extension is named pi-sub rather than pi-codex-usage so future subscription providers can be added as separate adapters. Supports OpenAI Codex (live usage API) and OpenCode Go (session cost only).
