@narumitw/pi-usage 0.53.0 β 0.57.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +171 -45
- package/dist/index.ts +1082 -67
- package/dist/index.ts.map +4 -4
- package/package.json +16 -11
- package/src/format.ts +184 -7
- package/src/index.ts +9 -0
- package/src/providers/deepseek.ts +85 -0
- package/src/providers/kimi-coding.ts +276 -0
- package/src/providers/xai.ts +186 -0
- package/src/query.ts +250 -9
- package/src/settings.ts +12 -0
- package/src/types.ts +28 -2
- package/src/usage-helpers.ts +2 -2
- package/src/usage-settings-ui.ts +127 -0
- package/src/usage.ts +156 -14
package/README.md
CHANGED
|
@@ -1,26 +1,34 @@
|
|
|
1
|
-
# π pi-usage β Check Provider Usage and Codex Fast Mode
|
|
1
|
+
# π pi-usage β Check Provider Usage, API Balance, and Codex Fast Mode
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@narumitw/pi-usage) [](https://pi.dev) [](./LICENSE)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Inspect usage and DeepSeek API balance for Pi's active provider account, query other configured providers, and toggle Fast mode for supported OpenAI Codex models.
|
|
6
6
|
|
|
7
|
-
The extension
|
|
7
|
+
The extension keeps each provider's native quota, allowance, and spending semantics instead of treating unlike values as equivalent.
|
|
8
|
+
xAI OAuth subscription reporting follows the reviewed Grok Build contract and runs only after an explicit `/usage` action.
|
|
8
9
|
|
|
9
10
|
## β¨ Features
|
|
10
11
|
|
|
11
|
-
- Shows
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
12
|
+
- Shows active-account usage and next actions through `/usage`.
|
|
13
|
+
- Reports OpenAI Codex subscription windows, credits, resets, and model-specific buckets.
|
|
14
|
+
- Reports Kimi For Coding plan windows, resets, and separately labeled booster-wallet currency.
|
|
15
|
+
- Reports GitHub Copilot allowances and OpenRouter per-key limits and spending windows.
|
|
16
|
+
- Reports exact DeepSeek API balances with separate CNY and USD values.
|
|
17
|
+
- Reports OpenCode Go plan windows and Z.AI Coding Plan quotas.
|
|
18
|
+
- Reports xAI OAuth subscription allowances and credits.
|
|
19
|
+
- Toggles persistent Codex Fast routing through `/fast` or the usage menu.
|
|
15
20
|
- Redeems eligible Codex resets only after fresh account matching and explicit confirmation.
|
|
16
|
-
- Refreshes one or all configured providers with bounded concurrency
|
|
17
|
-
-
|
|
21
|
+
- Refreshes one or all configured providers with bounded concurrency while preserving partial results.
|
|
22
|
+
- Scopes statusline and cache data to the active provider and runtime account.
|
|
18
23
|
- Resolves credentials through Pi or the process-local OAuth credential-source protocol and validates the effective provider endpoint before sending them.
|
|
19
24
|
|
|
20
25
|
## π¦ Install
|
|
21
26
|
|
|
22
|
-
Requires Pi 0.81.0 or newer
|
|
23
|
-
The v1 credential-source
|
|
27
|
+
Requires Pi 0.81.0 or newer to validate the effective base URL for resolved provider auth before sending credentials to an official usage endpoint.
|
|
28
|
+
The v1 credential-source path is characterized against Pi 0.84.3; other runtimes keep the standalone fallback without its protocol timing guarantee.
|
|
29
|
+
|
|
30
|
+
Like every Pi extension, this package runs with Pi's process permissions.
|
|
31
|
+
Review [Security and privacy](#-security-and-privacy) before installation.
|
|
24
32
|
|
|
25
33
|
```bash
|
|
26
34
|
pi install npm:@narumitw/pi-usage
|
|
@@ -43,21 +51,22 @@ The package declares `dist/index.ts`, so an unbuilt local checkout must run the
|
|
|
43
51
|
|
|
44
52
|
## π Quick start
|
|
45
53
|
|
|
46
|
-
Run `/usage` in TUI or RPC mode to inspect the
|
|
47
|
-
|
|
54
|
+
Run `/usage` in TUI or RPC mode to inspect the active provider, refresh its usage, or choose another configured provider.
|
|
55
|
+
Run `/fast` to toggle Fast mode for a supported active Codex model.
|
|
48
56
|
|
|
49
57
|
## π¬ Commands
|
|
50
58
|
|
|
51
|
-
|
|
59
|
+
Open the manager with:
|
|
52
60
|
|
|
53
61
|
```text
|
|
54
62
|
/usage
|
|
55
63
|
```
|
|
56
64
|
|
|
57
|
-
In TUI or RPC mode, the
|
|
65
|
+
In TUI or RPC mode, the menu first queries the active model provider and then offers these actions:
|
|
58
66
|
|
|
59
67
|
```text
|
|
60
68
|
Refresh current usage
|
|
69
|
+
Settings
|
|
61
70
|
Turn Fast mode on/off # Supported current Codex models only
|
|
62
71
|
Redeem usage limit reset⦠# Current Codex OAuth accounts only
|
|
63
72
|
View another configured providerβ¦
|
|
@@ -65,13 +74,14 @@ View all configured providersβ¦
|
|
|
65
74
|
Close
|
|
66
75
|
```
|
|
67
76
|
|
|
68
|
-
|
|
69
|
-
Cross-provider
|
|
70
|
-
Escape returns from provider selection
|
|
71
|
-
Print and JSON modes reject `/usage`
|
|
72
|
-
The cancellable live-query progress view
|
|
77
|
+
`/usage` accepts no arguments, including `--refresh`, a provider ID, or `--all`.
|
|
78
|
+
Cross-provider requests require an explicit interactive choice.
|
|
79
|
+
Escape returns from provider selection or closes the root menu.
|
|
80
|
+
Print and JSON modes reject `/usage` because they cannot host the interactive flow.
|
|
81
|
+
The extension owns the cancellable live-query progress view because it streams provider work and supports in-flight abort.
|
|
73
82
|
|
|
74
|
-
For the current OpenAI Codex provider, **Redeem usage limit resetβ¦** checks fresh earned-reset details
|
|
83
|
+
For the current OpenAI Codex provider, **Redeem usage limit resetβ¦** first checks fresh earned-reset details.
|
|
84
|
+
When details are available, you select a reset and review its exact effect before confirmation.
|
|
75
85
|
**No, go back** is the safe default and cancellation before confirmation sends no mutation.
|
|
76
86
|
After confirmation, the reset operation cannot be cancelled from its progress view; session replacement or shutdown still aborts owned work.
|
|
77
87
|
A transport failure offers **Try again** with the same redemption request ID so the backend can treat an uncertain retry idempotently.
|
|
@@ -79,25 +89,45 @@ Successful, already-completed, not-needed, and no-credit outcomes are reported s
|
|
|
79
89
|
|
|
80
90
|
## βοΈ Settings
|
|
81
91
|
|
|
92
|
+
Choose **Settings** in `/usage` to edit Codex Fast mode and the Codex reset countdown through Pi's settings-list interaction in TUI mode.
|
|
93
|
+
RPC mode reports the active manual settings path instead of opening terminal UI.
|
|
94
|
+
|
|
95
|
+
These preferences live in `pi-usage.json` under Pi's user agent directory, normally `~/.pi/agent/pi-usage.json`.
|
|
96
|
+
The extension reloads this file at every session start and does not create it until the first successful save.
|
|
97
|
+
Within one Pi process, changes save immediately in invocation order.
|
|
98
|
+
Saves preserve unknown JSON fields and publish through a private temporary file plus rename.
|
|
99
|
+
Malformed or invalid files remain untouched.
|
|
100
|
+
A failed save restores the prior displayed and effective value, while shutdown waits for queued writes.
|
|
101
|
+
Separate Pi processes are not mutually locked.
|
|
102
|
+
|
|
82
103
|
### Codex Fast mode
|
|
83
104
|
|
|
84
|
-
Run
|
|
105
|
+
Run `/fast` without arguments to toggle Fast for the active supported Codex model, or use **Turn Fast mode on/off** in `/usage`.
|
|
85
106
|
|
|
86
107
|
Fast is about 1.5Γ faster and uses more of your plan allowance.
|
|
87
|
-
The preference defaults to Off
|
|
88
|
-
The extension reloads this file at every session start and does not create it until the first successful toggle.
|
|
108
|
+
The `codexFastMode` preference defaults to Off.
|
|
89
109
|
|
|
90
110
|
Fast currently applies only to official `openai-codex-responses` requests for `gpt-5.4`, `gpt-5.5`, `gpt-5.6-sol`, `gpt-5.6-terra`, and `gpt-5.6-luna` at `https://chatgpt.com`.
|
|
91
111
|
It sends `service_tier: "priority"` while enabled and explicit `service_tier: "default"` otherwise.
|
|
92
|
-
The statusline adds `fast` only while the preference is effective, for example `codex fast 59%
|
|
112
|
+
The statusline adds `fast` only while the preference is effective, for example `codex fast 59% β» 2h30m` with the default reset countdown.
|
|
93
113
|
Unsupported models and custom or proxy origins are left unchanged.
|
|
94
114
|
|
|
95
115
|
`/fast` supports TUI and RPC mode, accepts no arguments, and rejects print or JSON mode before mutation.
|
|
96
116
|
A toggle affects provider requests whose payload hook starts after the save; a request already sent is unchanged.
|
|
97
|
-
Settings operations are serialized inside one Pi process, but separate Pi processes are not mutually locked.
|
|
98
|
-
Unknown JSON fields are preserved, writes use a private temporary file plus rename, and a malformed or invalid file is never overwritten.
|
|
99
117
|
Repair or remove an invalid file, then run `/reload` before trying the toggle again.
|
|
100
118
|
|
|
119
|
+
### Codex statusline reset countdown
|
|
120
|
+
|
|
121
|
+
The `codexStatusResetCountdown` preference defaults to `true`. It replaces the window labels with the time remaining until each returned limit resets.
|
|
122
|
+
|
|
123
|
+
Turn **Codex reset countdown** Off in the TUI Settings screen, or set it to `false` in `pi-usage.json` and run `/reload`, to restore the legacy `5h` and `wk` labels:
|
|
124
|
+
|
|
125
|
+
```json
|
|
126
|
+
{
|
|
127
|
+
"codexStatusResetCountdown": false
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
101
131
|
## π Provider semantics
|
|
102
132
|
|
|
103
133
|
### OpenAI Codex
|
|
@@ -107,21 +137,47 @@ Repair or remove an invalid file, then run `/reload` before trying the toggle ag
|
|
|
107
137
|
- Source: the Codex usage and earned-reset endpoints using Pi's resolved runtime authorization
|
|
108
138
|
- Displayed data: returned duration-based windows, resets, credits, earned usage-limit resets, and additional model buckets
|
|
109
139
|
- Reset mutation: `POST /wham/rate-limit-reset-credits/consume` with a unique redemption request ID and, when available, the selected opaque credit ID
|
|
110
|
-
- Statusline examples: `codex 59%
|
|
140
|
+
- Statusline examples: `codex 59% β» 2h30m 61% β» 2d15m`, `codex fast 59% β» 2h30m`, or `codex spark 100% β» 2h30m`. Set `codexStatusResetCountdown` to `false` for the legacy `5h` and `wk` labels.
|
|
111
141
|
|
|
112
142
|
The statusline selects a returned bucket that matches the current Codex model when one is available.
|
|
113
143
|
Unlike `pi-codex-usage`, this successor intentionally has no Codex CLI fallback because the CLI may be logged into a different account than Pi's active runtime account.
|
|
114
144
|
|
|
115
|
-
Reset redemption is available only when Codex is the current provider
|
|
145
|
+
Reset redemption is available only when Codex is the current provider.
|
|
146
|
+
Pi's freshly resolved access token must exactly match an OAuth credential from Pi's stored login or a compatible credential source.
|
|
116
147
|
`pi-usage` forwards only the bearer authorization and matching `chatgpt-account-id` to the official ChatGPT origin.
|
|
117
148
|
API-key credentials, configured-but-not-current Codex accounts, account changes during the flow, and custom/proxy origins fail before mutation.
|
|
118
149
|
Backend-provided titles and descriptions are sanitized for terminal display.
|
|
119
150
|
Opaque credit and account IDs are never shown or persisted by the extension.
|
|
120
151
|
|
|
152
|
+
### Kimi For Coding
|
|
153
|
+
|
|
154
|
+
- Provider ID: `kimi-coding`
|
|
155
|
+
- Semantics: Kimi Coding Plan request windows plus a separate Extra Usage booster wallet
|
|
156
|
+
- Source: `GET https://api.kimi.com/coding/v1/usages` using Pi's freshly resolved runtime Bearer credential
|
|
157
|
+
- Displayed plan data: the weekly summary, returned sub-windows, used and remaining request percentages, and valid reset times
|
|
158
|
+
- Displayed wallet data: balance, monthly spend, and monthly charge limit
|
|
159
|
+
- Statusline examples: `kimi 99% 5h 96% wk` or `kimi 95% 1d`
|
|
160
|
+
|
|
161
|
+
Both Pi API-key credentials and Pi OAuth credentials are accepted because current Pi resolves each form as Bearer authorization for the same official Kimi inference origin.
|
|
162
|
+
The extension queries the fixed usage endpoint only when both the selected model origin and the effective resolved-auth origin are `https://api.kimi.com`.
|
|
163
|
+
Custom and proxy origins fail before network access, redirects are rejected, and the credential is never sent to an override from Kimi Code's environment-specific development path.
|
|
164
|
+
|
|
165
|
+
Plan buckets remain integer request counts and are rendered with their source-defined windows.
|
|
166
|
+
Unknown units, duplicate windows, missing counts, invalid timestamps, and malformed rows remain unavailable rather than receiving guessed semantics.
|
|
167
|
+
Booster-wallet `amount` and `amountLeft` values use Kimi's first-party conversion of 1,000,000 fixed-point units per cent, while monthly values already arrive in cents.
|
|
168
|
+
Wallet values retain their currency and stay separate from plan requests and percentages in reports and the statusline.
|
|
169
|
+
Wallet fields remain unavailable unless the response supplies one consistent currency; missing monthly values are omitted, and an enabled zero cap is shown as zero.
|
|
170
|
+
|
|
171
|
+
The contract was revalidated on 2026-08-27 against [Pi `c49906ec77788625aacbdc53ebca6fbe65bd20f5`](https://github.com/earendil-works/pi/tree/c49906ec77788625aacbdc53ebca6fbe65bd20f5), including [`kimi-coding.ts`](https://github.com/earendil-works/pi/blob/c49906ec77788625aacbdc53ebca6fbe65bd20f5/packages/ai/src/providers/kimi-coding.ts) and [`auth/oauth/kimi-coding.ts`](https://github.com/earendil-works/pi/blob/c49906ec77788625aacbdc53ebca6fbe65bd20f5/packages/ai/src/auth/oauth/kimi-coding.ts).
|
|
172
|
+
It was also revalidated against [Kimi Code `676e4d82240855044fe809fea89ce1dbe8e512cf`](https://github.com/MoonshotAI/kimi-code/tree/676e4d82240855044fe809fea89ce1dbe8e512cf), including [`managed-usage.ts`](https://github.com/MoonshotAI/kimi-code/blob/676e4d82240855044fe809fea89ce1dbe8e512cf/packages/oauth/src/managed-usage.ts) and its [tests](https://github.com/MoonshotAI/kimi-code/blob/676e4d82240855044fe809fea89ce1dbe8e512cf/packages/oauth/test/managed-usage.test.ts).
|
|
173
|
+
The pinned Pi source at `e86823096c5bad39e1ca282ec24bc5eb9bec745b` has no changes in either reviewed Kimi file at the selected revision.
|
|
174
|
+
The pinned Kimi managed-usage source at `cd7c97b377a77f7ae1b9d541cafe314e986ec074` is an ancestor of that selected revision and has no changes in the reviewed source or tests.
|
|
175
|
+
|
|
121
176
|
### GitHub Copilot
|
|
122
177
|
|
|
123
178
|
- Provider ID: `github-copilot`
|
|
124
|
-
- Semantics: the allowance reported for the active Copilot plan
|
|
179
|
+
- Semantics: the allowance reported for the active Copilot plan
|
|
180
|
+
- Allowance labels: AI credits for usage-based billing, premium requests for legacy annual billing, or chat requests for Copilot Free
|
|
125
181
|
- Source: GitHub's undocumented `GET /copilot_internal/user` endpoint
|
|
126
182
|
- Displayed data: entitlement, remaining allowance, percentage, reset time, plan, and any additional usage beyond the included allowance
|
|
127
183
|
- Statusline examples: `copilot credits 1200/1500 80%`, `copilot 245/300 82%`, or `copilot chat 40/50 80%`
|
|
@@ -131,7 +187,8 @@ GitHub's quota endpoint requires the original GitHub OAuth token rather than the
|
|
|
131
187
|
It uses a candidate only when its short-lived access token exactly matches the freshly resolved active runtime credential.
|
|
132
188
|
Duplicate equivalent candidates are harmless, while conflicting matches fail closed without choosing by extension load order.
|
|
133
189
|
API-key credentials, account mismatches, GitHub Enterprise accounts, and proxy/custom provider origins fail closed.
|
|
134
|
-
The detailed report follows the endpoint's `token_based_billing` marker so AI credits are not mislabeled as legacy premium requests
|
|
190
|
+
The detailed report follows the endpoint's `token_based_billing` marker so AI credits are not mislabeled as legacy premium requests.
|
|
191
|
+
It reports overage without treating a negative included balance as malformed.
|
|
135
192
|
|
|
136
193
|
### OpenRouter
|
|
137
194
|
|
|
@@ -144,34 +201,95 @@ The detailed report follows the endpoint's `token_based_billing` marker so AI cr
|
|
|
144
201
|
The extension does not call OpenRouter's account-level `/credits` endpoint because that operation requires a separate management key.
|
|
145
202
|
OpenRouter documents the distinction between credit and rate limits in its [API limits guide](https://openrouter.ai/docs/api_reference/limits).
|
|
146
203
|
|
|
204
|
+
### DeepSeek API balance
|
|
205
|
+
|
|
206
|
+
- Provider ID: `deepseek`
|
|
207
|
+
- Semantics: current API account balance, not historical usage or quota
|
|
208
|
+
- Source: documented `GET https://api.deepseek.com/user/balance` using Pi's freshly resolved runtime API key
|
|
209
|
+
- Displayed data: whether API calls are available plus separate total, granted, and topped-up balances for each returned CNY or USD currency
|
|
210
|
+
- Statusline examples: `deepseek CNY 110.00` or `deepseek CNY 110.00 Β· USD 20.00`
|
|
211
|
+
|
|
212
|
+
The extension queries the fixed balance endpoint only when the selected model origin is `https://api.deepseek.com` and any resolved-auth origin override, when present, has the same official origin.
|
|
213
|
+
Pi's built-in DeepSeek API-key resolver does not attach a redundant auth origin, so the validated model origin remains authoritative when no override exists.
|
|
214
|
+
Custom and proxy origins fail before network access, redirects are rejected, and only the resolved Bearer credential is forwarded from Pi's runtime auth.
|
|
215
|
+
Monetary decimal strings remain exact from the response through display.
|
|
216
|
+
CNY and USD stay separate and are never converted or added together.
|
|
217
|
+
The balance endpoint does not provide historical spend, request windows, reset times, or aggregate token usage, so `pi-usage` does not claim those DeepSeek capabilities.
|
|
218
|
+
|
|
219
|
+
The contract was verified on 2026-08-28 against [DeepSeek's Get User Balance documentation](https://api-docs.deepseek.com/api/get-user-balance) and Pi's [`deepseek.ts`](https://github.com/earendil-works/pi/blob/c49906ec77788625aacbdc53ebca6fbe65bd20f5/packages/ai/src/providers/deepseek.ts) at `c49906ec77788625aacbdc53ebca6fbe65bd20f5`.
|
|
220
|
+
DeepSeek Harness `cd5ef8148158c3a752a658978873241fdf8e2bbc` reports only per-request model token usage and does not provide account balance data.
|
|
221
|
+
|
|
147
222
|
### OpenCode Go (Zen)
|
|
148
223
|
|
|
149
224
|
- Provider ID: `opencode-go`
|
|
150
225
|
- Semantics: OpenCode Zen plan usage windowsβrolling, weekly, and monthly
|
|
151
226
|
- Source: `GET https://opencode.ai/zen/go/v1/usage` using Pi's resolved inference API key
|
|
152
|
-
- Displayed data: used percentage and reset time for each window
|
|
227
|
+
- Displayed data: used percentage and reset time for each window
|
|
228
|
+
- Status handling: `rate-limited` windows remain visible, while unknown statuses become unavailable notes
|
|
153
229
|
- Statusline examples: `zen 0% r 4% w 2% m`
|
|
154
230
|
|
|
155
|
-
The fixed endpoint is queried only when the
|
|
231
|
+
The fixed endpoint is queried only when the OpenCode Go model uses the official `https://opencode.ai` origin.
|
|
232
|
+
When resolved provider auth includes a base URL, that URL must use the same origin.
|
|
233
|
+
Other origins fail before the credential is sent.
|
|
234
|
+
|
|
235
|
+
### xAI consumer subscriptions
|
|
236
|
+
|
|
237
|
+
- Provider ID: `xai`
|
|
238
|
+
- Semantics: consumer subscription allowance and credits, not xAI API-team billing
|
|
239
|
+
- Identity route: `GET https://cli-chat-proxy.grok.com/v1/user?include=subscription`
|
|
240
|
+
- Billing route: `GET https://cli-chat-proxy.grok.com/v1/billing?format=credits`
|
|
241
|
+
- Displayed data: included allowance or legacy monetary limit, period and reset, on-demand spend and cap, prepaid balance, and a sanitized optional plan tier
|
|
242
|
+
- Statusline: not published; xAI is queried only through an explicit `/usage` action
|
|
243
|
+
|
|
244
|
+
The adapter accepts only the official Pi inference origin `https://api.x.ai` and a freshly resolved bearer that exactly matches one complete Pi OAuth credential.
|
|
245
|
+
Pi's reviewed OAuth scope is `openid profile email offline_access grok-cli:access api:access`.
|
|
246
|
+
The adapter rejects `XAI_API_KEY`, duplicate or conflicting OAuth candidates, account mismatches, and incomplete OAuth records.
|
|
247
|
+
It also rejects custom or proxy-resolved origins before consumer-proxy access.
|
|
248
|
+
API-key users can review API-team spend through [console.x.ai](https://console.x.ai/) instead.
|
|
249
|
+
The public Management API requires a separate management key and team ID and is intentionally outside this runtime-credential integration.
|
|
250
|
+
|
|
251
|
+
The identity response supplies a transient proxy-canonical `userId` that is validated and sent as `x-userid` only on the billing request.
|
|
252
|
+
The extension sends the matched bearer as `Authorization` plus Grok Build's source-defined non-secret `X-XAI-Token-Auth`, client-version, and interactive client-mode headers.
|
|
253
|
+
It does not read Grok Build files, device state, names, email, or other profile fields.
|
|
254
|
+
Responses are body-bounded, redirects are rejected, raw identity and billing payloads are not retained, and secrets are redacted from errors.
|
|
255
|
+
Included allowance, on-demand usage, and prepaid balance remain distinct because they represent different billing concepts.
|
|
256
|
+
|
|
257
|
+
The current official Grok Build implementation is the ground truth for the xAI integration contract.
|
|
258
|
+
The implementation contract was verified against these first-party revisions:
|
|
259
|
+
|
|
260
|
+
- Pi [`providers/xai.ts`](https://github.com/earendil-works/pi/blob/e86823096c5bad39e1ca282ec24bc5eb9bec745b/packages/ai/src/providers/xai.ts) and [`auth/oauth/xai.ts`](https://github.com/earendil-works/pi/blob/e86823096c5bad39e1ca282ec24bc5eb9bec745b/packages/ai/src/auth/oauth/xai.ts) at `e868230`, revalidated byte-for-byte for those files at [`ccfe79e`](https://github.com/earendil-works/pi/tree/ccfe79ed238674f760c986e3a61493aab794000a).
|
|
261
|
+
- Grok Build [`UserInfo`](https://github.com/xai-org/grok-build/blob/9684fa3cdbf2995e30ea8b9b637f1db008f144fc/crates/codegen/xai-grok-shell/src/auth/model.rs), [`subscription_check.rs`](https://github.com/xai-org/grok-build/blob/9684fa3cdbf2995e30ea8b9b637f1db008f144fc/crates/codegen/xai-grok-shell/src/agent/subscription_check.rs), [`billing.rs`](https://github.com/xai-org/grok-build/blob/9684fa3cdbf2995e30ea8b9b637f1db008f144fc/crates/codegen/xai-grok-shell/src/extensions/billing.rs), [`auth/config.rs`](https://github.com/xai-org/grok-build/blob/9684fa3cdbf2995e30ea8b9b637f1db008f144fc/crates/codegen/xai-grok-shell/src/auth/config.rs), [`xai-grok-http`](https://github.com/xai-org/grok-build/blob/9684fa3cdbf2995e30ea8b9b637f1db008f144fc/crates/codegen/xai-grok-http/src/lib.rs), and [`xai-grok-version`](https://github.com/xai-org/grok-build/blob/9684fa3cdbf2995e30ea8b9b637f1db008f144fc/crates/codegen/xai-grok-version/Cargo.toml) at `9684fa3`.
|
|
262
|
+
- [xAI Management API team billing boundary at `723dd2a`](https://github.com/xai-org/xai-proto/blob/723dd2aa22d17be35617463837dc47cda008d90e/proto/xai/management_api/v1/billing.proto).
|
|
263
|
+
|
|
264
|
+
The approved 2026-08-27 protocol smoke used only Pi's OAuth bearer and read no Grok-local files.
|
|
265
|
+
A disposable or maintainer account received HTTP 200 without redirects from both routes.
|
|
266
|
+
The implementation also sends the non-secret client headers present on both routes in current Grok Build source, with `x-userid` added only for billing.
|
|
267
|
+
The sanitized identity shape contained a string `userId` and nullable `subscriptionTier`.
|
|
268
|
+
The billing shape contained a `config` object with period and distinct on-demand and prepaid wrappers, without retaining field values.
|
|
269
|
+
|
|
270
|
+
xAI identity and billing requests occur only after an explicit current, configured-provider, or all-provider `/usage` action.
|
|
156
271
|
|
|
157
272
|
### Z.AI (GLM Coding Plan)
|
|
158
273
|
|
|
159
274
|
- Provider ID: `zai` and `zai-coding-cn`
|
|
160
275
|
- Semantics: GLM Coding Plan quota windowsβthe rolling 5-hour and weekly plan-usage windows plus the monthly MCP allowance
|
|
161
|
-
- Source:
|
|
162
|
-
-
|
|
163
|
-
-
|
|
276
|
+
- Source: the undocumented `GET {origin}/api/monitor/usage/quota/limit` endpoint also used by Z.AI's official coding plugin
|
|
277
|
+
- Allowed origins: the model base URL must resolve to `https://api.z.ai` or `https://open.bigmodel.cn`
|
|
278
|
+
- Displayed data: explicit used and remaining values, reset times, provider-reported per-tool MCP details, and the reported plan level
|
|
279
|
+
- Percentage-only windows remain percent-based
|
|
280
|
+
- Statusline: publishes remaining plan percentages such as `zai 87% 5h 76% wk`; monthly MCP details remain available through `/usage`
|
|
164
281
|
|
|
165
282
|
The monitor endpoint is not a published API contract and may return legacy `TOKENS_LIMIT` or newer `CREDIT_LIMIT` window names.
|
|
166
283
|
The extension classifies both forms by the provider's window unit and does not label provider-reported counts as tokens or calls.
|
|
167
|
-
The quota monitor expects
|
|
284
|
+
The quota monitor expects a raw API key without a `Bearer` prefix.
|
|
285
|
+
The extension removes that prefix from resolved authorization before sending it to the monitor endpoint.
|
|
168
286
|
Fingerprinting and redaction keep using the original resolved credential.
|
|
169
287
|
Only the official `api.z.ai` and `open.bigmodel.cn` origins are queried; other origins fail before sending the credential.
|
|
170
288
|
|
|
171
289
|
## π§ Current and configured accounts
|
|
172
290
|
|
|
173
|
-
`Current`
|
|
174
|
-
`Configured`
|
|
291
|
+
`Current` identifies the provider and credential used by Pi's selected model.
|
|
292
|
+
`Configured` identifies runtime auth for another supported provider, not an active provider.
|
|
175
293
|
|
|
176
294
|
The extension does not enumerate multiple accounts inside one provider and does not switch accounts.
|
|
177
295
|
Account selection remains owned by Pi or an account-management extension.
|
|
@@ -184,8 +302,11 @@ After the active runtime credential changes, the next command, turn, or schedule
|
|
|
184
302
|
|
|
185
303
|
The `usage` status item is active only for selected providers that publish statusline usage.
|
|
186
304
|
It refreshes every five minutes while the session remains on such a provider and is cleared when the model changes to an unsupported or menu-only provider.
|
|
305
|
+
DeepSeek publishes each returned currency as a separate exact balance segment and reports when the API is unavailable.
|
|
306
|
+
xAI is always menu-only and never starts a scheduled status refresh.
|
|
307
|
+
Z.AI statusline usage refreshes every five minutes while the selected model remains on Z.AI.
|
|
187
308
|
|
|
188
|
-
|
|
309
|
+
Queries for another provider or all providers never publish their results to the statusline.
|
|
189
310
|
`@narumitw/pi-statusline` supplies the default `π` icon; `pi-usage` publishes text-only values.
|
|
190
311
|
|
|
191
312
|
## π Migrating from pi-codex-usage
|
|
@@ -211,18 +332,22 @@ Behavior changes:
|
|
|
211
332
|
|
|
212
333
|
Credential candidates are collected synchronously in memory and are not cached, persisted, logged, formatted, or appended to the Pi session.
|
|
213
334
|
The protocol carries no account name or extension identity.
|
|
214
|
-
Only the selected provider's exact runtime match is used, and secrets are sent only to
|
|
335
|
+
Only the selected provider's exact runtime match is used, and secrets are sent only to its validated official origin.
|
|
336
|
+
DeepSeek balance requests require Bearer authentication, send only that resolved credential from Pi's runtime auth to `https://api.deepseek.com/user/balance`, and refuse redirects.
|
|
215
337
|
Pi extensions run with the user's process privileges, so the shared event bus is not a security boundary between installed extensions.
|
|
216
|
-
Install only trusted extensions because
|
|
217
|
-
Protocol v1 interoperability is characterized for the repository's supported Pi runtime
|
|
338
|
+
Install only trusted extensions because they can read user files and process memory.
|
|
339
|
+
Protocol v1 interoperability is characterized for the repository's supported Pi runtime.
|
|
340
|
+
An absent or incompatible peer preserves standalone fallback and fail-closed mismatch behavior.
|
|
218
341
|
|
|
219
342
|
## π§ Limitations
|
|
220
343
|
|
|
221
344
|
- Only providers with a meaningful usage source and verifiable Pi runtime auth are supported.
|
|
222
|
-
- GitHub Copilot quota, Z.AI quota, and OpenAI Codex reset redemption
|
|
345
|
+
- GitHub Copilot quota, Kimi managed usage, Z.AI quota, and OpenAI Codex reset redemption rely on provider-owned endpoints that may change without notice.
|
|
223
346
|
- Codex reset redemption requires a current ChatGPT OAuth credential from Pi's login or a compatible credential source; Codex API keys cannot redeem earned subscription resets.
|
|
347
|
+
- xAI usage supports only a uniquely matched Pi OAuth subscription credential; xAI API keys and Management API credentials are unsupported.
|
|
224
348
|
- Credentials resolved for custom provider base URLs are never forwarded to the providers' official usage endpoints; effective auth origin validation requires Pi 0.81.0 or newer.
|
|
225
349
|
- Provider reports are snapshots and may themselves be delayed by the provider.
|
|
350
|
+
- DeepSeek reports current API balance only; it does not expose historical usage, quota windows, reset times, or account-wide token totals through the balance endpoint.
|
|
226
351
|
- OpenRouter successful inference responses do not expose proactive request-rate counters; `/usage` reports the documented per-key credit/spend fields instead.
|
|
227
352
|
- A provider may not return a safe human-readable account identity.
|
|
228
353
|
In that case the provider and runtime credential state remain visible without exposing secrets.
|
|
@@ -240,6 +365,7 @@ packages/pi-usage/
|
|
|
240
365
|
βββ src/
|
|
241
366
|
β βββ index.ts # Pi package entrypoint and helper export barrel
|
|
242
367
|
β βββ usage.ts # Menu, cache, and usage lifecycle orchestration
|
|
368
|
+
β βββ usage-settings-ui.ts # Pi SettingsList interaction and save rollback
|
|
243
369
|
β βββ codex-fast.ts # Fast eligibility, request tier, and cost correction
|
|
244
370
|
β βββ codex-fast-runtime.ts # Fast command, persistence lifecycle, and request hooks
|
|
245
371
|
β βββ settings.ts # Validated user settings and atomic persistence
|
|
@@ -264,7 +390,7 @@ The generated runtime is built from the authoritative `src/index.ts` graph and d
|
|
|
264
390
|
|
|
265
391
|
## π Keywords
|
|
266
392
|
|
|
267
|
-
Pi extension, Pi coding agent, usage, quota, OpenAI Codex usage, ChatGPT subscription limits, GitHub Copilot AI credits, GitHub Copilot premium requests, OpenRouter credits, API-key spend limits, TypeScript Pi package, npm Pi extension.
|
|
393
|
+
Pi extension, Pi coding agent, usage, quota, DeepSeek API balance, DeepSeek balance, OpenAI Codex usage, ChatGPT subscription limits, Kimi For Coding, Kimi Coding Plan usage, GitHub Copilot AI credits, GitHub Copilot premium requests, OpenRouter credits, xAI OAuth usage, Grok subscription allowance, API-key spend limits, TypeScript Pi package, npm Pi extension.
|
|
268
394
|
|
|
269
395
|
## π License
|
|
270
396
|
|