@narumitw/pi-usage 0.58.0 → 0.60.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 CHANGED
@@ -3,7 +3,6 @@
3
3
  [![npm](https://img.shields.io/npm/v/@narumitw/pi-usage)](https://www.npmjs.com/package/@narumitw/pi-usage) [![Pi extension](https://img.shields.io/badge/Pi-extension-blue)](https://pi.dev) [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](./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
-
7
6
  The extension keeps each provider's native quota, allowance, and spending semantics instead of treating unlike values as equivalent.
8
7
  xAI OAuth subscription reporting follows the reviewed Grok Build contract and runs only after an explicit `/usage` action.
9
8
 
@@ -12,10 +11,14 @@ xAI OAuth subscription reporting follows the reviewed Grok Build contract and ru
12
11
  - Shows active-account usage and next actions through `/usage`.
13
12
  - Reports OpenAI Codex subscription windows, credits, resets, and model-specific buckets.
14
13
  - Reports Kimi For Coding plan windows, resets, and separately labeled booster-wallet currency.
14
+ - Reports Moonshot AI Global and China API account balances in their native currencies.
15
+ - Reports MiniMax Global and China Token Plan windows or pay-as-you-go API balance.
15
16
  - Reports GitHub Copilot allowances and OpenRouter per-key limits and spending windows.
16
17
  - Reports exact DeepSeek API balances with separate CNY and USD values.
17
18
  - Reports OpenCode Go plan windows and Z.AI Coding Plan quotas.
18
19
  - Reports Fireworks rated API spend for the last 30 days with per-series subtotals.
20
+ - Reports Vercel AI Gateway credit balance and lifetime spend.
21
+ - Reports Baseten organization Model APIs spend after credits for the last 30 days.
19
22
  - Reports xAI OAuth subscription allowances and credits.
20
23
  - Toggles persistent Codex Fast routing through `/fast` or the usage menu.
21
24
  - Redeems eligible Codex resets only after fresh account matching and explicit confirmation.
@@ -118,7 +121,6 @@ Submit a blank value from the TUI input, or remove the JSON field and run `/relo
118
121
  ### Codex Fast mode
119
122
 
120
123
  Run `/fast` without arguments to toggle Fast for the active supported Codex model, or use **Turn Fast mode on/off** in `/usage`.
121
-
122
124
  Fast is about 1.5× faster and uses more of your plan allowance.
123
125
  The `codexFastMode` preference defaults to Off.
124
126
 
@@ -134,7 +136,6 @@ Repair or remove an invalid file, then run `/reload` before trying the toggle ag
134
136
  ### Codex statusline reset countdown
135
137
 
136
138
  The `codexStatusResetCountdown` preference defaults to `true`. It replaces the window labels with the time remaining until each returned limit resets.
137
-
138
139
  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:
139
140
 
140
141
  ```json
@@ -188,6 +189,41 @@ It was also revalidated against [Kimi Code `676e4d82240855044fe809fea89ce1dbe8e5
188
189
  The pinned Pi source at `e86823096c5bad39e1ca282ec24bc5eb9bec745b` has no changes in either reviewed Kimi file at the selected revision.
189
190
  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.
190
191
 
192
+ ### Moonshot AI API balance
193
+
194
+ - Provider IDs: `moonshotai` and `moonshotai-cn`
195
+ - Semantics: current API account balance, not Kimi For Coding subscription usage
196
+ - Global source: `GET https://api.moonshot.ai/v1/users/me/balance`
197
+ - China source: `GET https://api.moonshot.cn/v1/users/me/balance`
198
+ - Displayed data: available, voucher, and cash balance in USD for Global or CNY for China
199
+ - Statusline examples: `moonshot USD 49.58894` or `moonshot CNY 49.58894`
200
+
201
+ Each endpoint uses Pi's resolved inference Bearer key for the matching region.
202
+ Pi maps both built-in providers to `MOONSHOT_API_KEY`, so that shared environment credential is eligible only for the currently selected region.
203
+ Querying the sibling region requires a provider-specific stored, runtime, or `models.json` credential.
204
+ The extension rejects custom, proxy, and cross-region origins before network access and refuses redirects.
205
+ Available and voucher balances must be nonnegative, while cash balance may be negative when the account owes money.
206
+ The endpoint does not provide historical spend, token totals, quota windows, or reset times.
207
+ These API-platform balances are independent from the `kimi-coding` subscription and booster wallet.
208
+
209
+ The contracts were verified on 2026-08-30 against the official [Global balance reference](https://platform.kimi.ai/docs/api/balance), [China balance reference](https://platform.moonshot.cn/docs/api/balance), and first-party [`MoonshotAI-Cookbook` balance client and DTO](https://github.com/MoonshotAI/MoonshotAI-Cookbook/tree/25a9e46d2391dd4817d28ab980dac69eb59b582c/examples/golang_demo).
210
+ ### MiniMax Token Plan and API balance
211
+
212
+ - Provider IDs: `minimax` and `minimax-cn`
213
+ - Token Plan source: `GET {region-api-root}/v1/token_plan/remains`
214
+ - Pay-as-you-go source: `GET {region-api-root}/account/query_balance`
215
+ - Region API roots: `https://api.minimax.io` and `https://api.minimaxi.com`
216
+ - Statusline examples: `minimax 15% 5h 80% wk` or `minimax USD 98.00001`
217
+
218
+ Pi's resolved MiniMax API key selects exactly one endpoint before network access.
219
+ Keys with the first-party `sk-api-` prefix query pay-as-you-go balance; other MiniMax API keys query Token Plan quota.
220
+ The extension never probes both endpoints with one credential.
221
+ Token Plan reports preserve provider rows, rolling and weekly windows, counts, reset times, unlimited status, and first-party handling for legacy versus current `*_usage_count` semantics.
222
+ Pay-as-you-go reports keep available, cash, voucher, credit, and owed amounts separate in USD for Global or CNY for China.
223
+ Custom, proxy, and cross-region origins fail before network access, and redirects are rejected.
224
+
225
+ The contract was verified on 2026-08-30 against MiniMax's [Token Plan FAQ](https://platform.minimax.io/docs/token-plan/faq#how-to-check-token-plan-usage) and the first-party [`MiniMax-AI/cli`](https://github.com/MiniMax-AI/cli/tree/b78eccea80a0f9692e186d98906cff26931464f3), including endpoint selection, response types, quota normalization, and SDK tests.
226
+
191
227
  ### GitHub Copilot
192
228
 
193
229
  - Provider ID: `github-copilot`
@@ -250,6 +286,37 @@ Rated line items may differ from the final invoice once credits or adjustments a
250
286
 
251
287
  The contract was verified on 2026-07-31 against Fireworks' [Usage & Cost Breakdown](https://docs.fireworks.ai/accounts/exporting-usage-and-costs), [Get billing summary](https://docs.fireworks.ai/api-reference/get-billing-summary), and [List Accounts](https://docs.fireworks.ai/api-reference/list-accounts) API references.
252
288
 
289
+ ### Vercel AI Gateway credits
290
+
291
+ - Provider ID: `vercel-ai-gateway`
292
+ - Semantics: current team credit balance and lifetime spend, not rate-limit quota
293
+ - Source: documented `GET https://ai-gateway.vercel.sh/v1/credits` using Pi's resolved AI Gateway API key
294
+ - Displayed data: exact decimal-string credit balance and lifetime spend in USD
295
+ - Statusline example: `vercel USD 95.50 left`
296
+
297
+ The extension queries the fixed endpoint only when the selected model origin and any resolved-auth origin are `https://ai-gateway.vercel.sh`.
298
+ Custom and proxy origins fail before network access, redirects are rejected, and only the resolved Bearer credential is forwarded.
299
+ The credits endpoint does not provide reset times, request-rate counters, or date-window usage, so `pi-usage` does not claim those capabilities.
300
+ Vercel's separate Custom Reporting API is limited to eligible paid plans and is intentionally outside this first integration.
301
+
302
+ The contract was verified on 2026-08-30 against Vercel's [REST API Reference](https://vercel.com/docs/ai-gateway/sdks-and-apis/rest-api#check-credit-balance) and the first-party [`vercel/ai` Gateway implementation](https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/gateway/src/gateway-fetch-metadata.ts).
303
+
304
+ ### Baseten Model APIs spend
305
+
306
+ - Provider ID: `baseten`
307
+ - Semantics: organization-wide Model APIs spend, not per-key quota or account balance
308
+ - Source: `GET https://api.baseten.co/v1/billing/usage_summary` using Pi's resolved Baseten API key
309
+ - Displayed data: trailing 30-day gross usage, credits used, and net subtotal in USD
310
+ - Statusline example: `baseten USD 166.15 net`
311
+
312
+ The extension intentionally ignores Dedicated deployment and Training categories because they do not represent Pi's Model APIs provider usage.
313
+ The query window is a precise trailing 30 days and stays below the endpoint's 31-day maximum.
314
+ The fixed Management API endpoint is queried only for an official `https://inference.baseten.co` model and an official resolved-auth origin.
315
+ Custom and proxy origins fail before network access, redirects are rejected, and only the resolved Bearer credential is forwarded.
316
+ An empty `model_apis_usage` result is reported as no Model APIs usage rather than zero account-wide spend.
317
+
318
+ The contract was verified on 2026-08-30 against Baseten's [Billing and usage](https://docs.baseten.co/organization/billing#view-usage), [Model APIs usage](https://docs.baseten.co/inference/model-apis/pricing-and-limits#usage), first-party [`baseten-go` Management OpenAPI](https://github.com/basetenlabs/baseten-go/blob/f028e27beb4bde106d984833313c055ddd6fefa4/internal/tools/apigen/specs/management.json), and [`baseten-cli` billing behavior](https://github.com/basetenlabs/baseten-cli/blob/e3d002b465f49a7295ea44b5988dbfeb8197896d/internal/cmd/command.org.go).
319
+
253
320
  ### OpenCode Go (Zen)
254
321
 
255
322
  - Provider ID: `opencode-go`
@@ -304,9 +371,9 @@ xAI identity and billing requests occur only after an explicit current, configur
304
371
 
305
372
  - Provider ID: `zai` and `zai-coding-cn`
306
373
  - Semantics: GLM Coding Plan quota windows—the rolling 5-hour and weekly plan-usage windows plus the monthly MCP allowance
307
- - Source: the undocumented `GET {origin}/api/monitor/usage/quota/limit` endpoint also used by Z.AI's official coding plugin
374
+ - Source: the undocumented `GET {origin}/api/monitor/usage/quota/limit` endpoint also used by Z.AI's official coding plugin, plus the undocumented `GET {origin}/api/biz/subscription/list` plan endpoint
308
375
  - Allowed origins: the model base URL must resolve to `https://api.z.ai` or `https://open.bigmodel.cn`
309
- - Displayed data: explicit used and remaining values, reset times, provider-reported per-tool MCP details, and the reported plan level
376
+ - Displayed data: explicit used and remaining values, reset times, provider-reported per-tool MCP details, and the plan name with its renewal date
310
377
  - Percentage-only windows remain percent-based
311
378
  - Statusline: publishes remaining plan percentages such as `zai 87% 5h 76% wk`; monthly MCP details remain available through `/usage`
312
379
 
@@ -315,6 +382,7 @@ The extension classifies both forms by the provider's window unit and does not l
315
382
  The quota monitor expects a raw API key without a `Bearer` prefix.
316
383
  The extension removes that prefix from resolved authorization before sending it to the monitor endpoint.
317
384
  Fingerprinting and redaction keep using the original resolved credential.
385
+ The plan endpoint only contributes the plan name and renewal date; when it is unavailable or fails, the quota windows remain reported and the plan note falls back to the quota response's plan level.
318
386
  Only the official `api.z.ai` and `open.bigmodel.cn` origins are queried; other origins fail before sending the credential.
319
387
 
320
388
  ## 🧭 Current and configured accounts
@@ -335,6 +403,10 @@ The `usage` status item is active only for selected providers that publish statu
335
403
  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.
336
404
  DeepSeek publishes each returned currency as a separate exact balance segment and reports when the API is unavailable.
337
405
  Fireworks publishes exact per-currency rated spend totals and reports when no rated usage exists.
406
+ Moonshot AI publishes the available balance with its region-native currency.
407
+ Vercel AI Gateway publishes the exact current USD credit balance.
408
+ MiniMax publishes Token Plan window percentages or the regional pay-as-you-go available balance.
409
+ Baseten publishes the exact trailing 30-day Model APIs net subtotal after credits.
338
410
  xAI is always menu-only and never starts a scheduled status refresh.
339
411
  Z.AI statusline usage refreshes every five minutes while the selected model remains on Z.AI.
340
412
 
@@ -367,6 +439,10 @@ The protocol carries no account name or extension identity.
367
439
  Only the selected provider's exact runtime match is used, and secrets are sent only to its validated official origin.
368
440
  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.
369
441
  Fireworks spend requests send only that resolved credential to the official `https://api.fireworks.ai` account-listing and billing-summary endpoints and refuse redirects.
442
+ Moonshot balance requests send only the resolved Bearer credential to the matching official Global or China balance origin and refuse redirects.
443
+ Vercel AI Gateway credit requests send only the resolved Bearer credential to `https://ai-gateway.vercel.sh/v1/credits` and refuse redirects.
444
+ MiniMax usage requests send only the resolved API key to one deterministic endpoint on the matching official Global or China API root and refuse redirects.
445
+ Baseten billing requests send only the resolved Bearer credential to `https://api.baseten.co/v1/billing/usage_summary` for an official Baseten model and refuse redirects.
370
446
  Pi extensions run with the user's process privileges, so the shared event bus is not a security boundary between installed extensions.
371
447
  Install only trusted extensions because they can read user files and process memory.
372
448
  Protocol v1 interoperability is characterized for the repository's supported Pi runtime.
@@ -382,6 +458,10 @@ An absent or incompatible peer preserves standalone fallback and fail-closed mis
382
458
  - Provider reports are snapshots and may themselves be delayed by the provider.
383
459
  - 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.
384
460
  - Fireworks reports rated 30-day spend only; credit balance and spend caps are visible only in the Fireworks web console, and keys that can see several accounts must set `fireworksAccountId` in `pi-usage.json`.
461
+ - Moonshot AI reports current API balance only; it does not expose historical spend, aggregate token usage, quota windows, or reset times through the balance endpoint.
462
+ - Vercel AI Gateway reports current team credits and lifetime spend only; Custom Reporting and request-rate counters are not queried.
463
+ - MiniMax Token Plan field semantics have changed over time; contradictory counts and percentages are reported as unavailable rather than guessed.
464
+ - Baseten reports organization-wide Model APIs spend, not usage attributable only to Pi's current key; Dedicated and Training spend are excluded.
385
465
  - OpenRouter successful inference responses do not expose proactive request-rate counters; `/usage` reports the documented per-key credit/spend fields instead.
386
466
  - A provider may not return a safe human-readable account identity.
387
467
  In that case the provider and runtime credential state remain visible without exposing secrets.
@@ -419,12 +499,11 @@ packages/pi-usage/
419
499
  ```
420
500
 
421
501
  `index.ts` is the Pi entrypoint and forwards the default factory from `usage.ts` while retaining the package's named helper exports; other source modules are internal.
422
-
423
502
  The generated runtime is built from the authoritative `src/index.ts` graph and does not import back into `src`.
424
503
 
425
504
  ## 🔎 Keywords
426
505
 
427
- Pi extension, Pi coding agent, usage, quota, DeepSeek API balance, DeepSeek balance, Fireworks API spend, Fireworks rated spend, 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.
506
+ Pi extension, Pi coding agent, usage, quota, DeepSeek API balance, DeepSeek balance, Fireworks API spend, Fireworks rated spend, Vercel AI Gateway credits, Vercel AI Gateway usage, Baseten Model APIs spend, Baseten usage, OpenAI Codex usage, ChatGPT subscription limits, Kimi For Coding, Kimi Coding Plan usage, Moonshot AI balance, Moonshot API balance, MiniMax Token Plan, MiniMax API balance, 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.
428
507
 
429
508
  ## 📄 License
430
509