@narumitw/pi-usage 0.57.0 → 0.59.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
@@ -12,9 +12,14 @@ xAI OAuth subscription reporting follows the reviewed Grok Build contract and ru
12
12
  - Shows active-account usage and next actions through `/usage`.
13
13
  - Reports OpenAI Codex subscription windows, credits, resets, and model-specific buckets.
14
14
  - Reports Kimi For Coding plan windows, resets, and separately labeled booster-wallet currency.
15
+ - Reports Moonshot AI Global and China API account balances in their native currencies.
16
+ - Reports MiniMax Global and China Token Plan windows or pay-as-you-go API balance.
15
17
  - Reports GitHub Copilot allowances and OpenRouter per-key limits and spending windows.
16
18
  - Reports exact DeepSeek API balances with separate CNY and USD values.
17
19
  - Reports OpenCode Go plan windows and Z.AI Coding Plan quotas.
20
+ - Reports Fireworks rated API spend for the last 30 days with per-series subtotals.
21
+ - Reports Vercel AI Gateway credit balance and lifetime spend.
22
+ - Reports Baseten organization Model APIs spend after credits for the last 30 days.
18
23
  - Reports xAI OAuth subscription allowances and credits.
19
24
  - Toggles persistent Codex Fast routing through `/fast` or the usage menu.
20
25
  - Redeems eligible Codex resets only after fresh account matching and explicit confirmation.
@@ -89,7 +94,7 @@ Successful, already-completed, not-needed, and no-credit outcomes are reported s
89
94
 
90
95
  ## ⚙️ Settings
91
96
 
92
- Choose **Settings** in `/usage` to edit Codex Fast mode and the Codex reset countdown through Pi's settings-list interaction in TUI mode.
97
+ Choose **Settings** in `/usage` to edit Codex Fast mode, the Codex reset countdown, and the Fireworks account selector through Pi's settings-list interaction in TUI mode.
93
98
  RPC mode reports the active manual settings path instead of opening terminal UI.
94
99
 
95
100
  These preferences live in `pi-usage.json` under Pi's user agent directory, normally `~/.pi/agent/pi-usage.json`.
@@ -100,6 +105,20 @@ Malformed or invalid files remain untouched.
100
105
  A failed save restores the prior displayed and effective value, while shutdown waits for queued writes.
101
106
  Separate Pi processes are not mutually locked.
102
107
 
108
+ ### Fireworks account
109
+
110
+ A Fireworks key that can see one account needs no setting.
111
+ For a key that can see several accounts, choose **Fireworks account** in the TUI Settings screen, or set the exact visible account slug in `pi-usage.json` and run `/reload`:
112
+
113
+ ```json
114
+ {
115
+ "fireworksAccountId": "acme"
116
+ }
117
+ ```
118
+
119
+ The `fireworksAccountId` setting is validated as a URL-safe account slug and then checked against the official account listing before billing data is requested.
120
+ Submit a blank value from the TUI input, or remove the JSON field and run `/reload`, to restore single-account auto-selection.
121
+
103
122
  ### Codex Fast mode
104
123
 
105
124
  Run `/fast` without arguments to toggle Fast for the active supported Codex model, or use **Turn Fast mode on/off** in `/usage`.
@@ -173,6 +192,41 @@ It was also revalidated against [Kimi Code `676e4d82240855044fe809fea89ce1dbe8e5
173
192
  The pinned Pi source at `e86823096c5bad39e1ca282ec24bc5eb9bec745b` has no changes in either reviewed Kimi file at the selected revision.
174
193
  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
194
 
195
+ ### Moonshot AI API balance
196
+
197
+ - Provider IDs: `moonshotai` and `moonshotai-cn`
198
+ - Semantics: current API account balance, not Kimi For Coding subscription usage
199
+ - Global source: `GET https://api.moonshot.ai/v1/users/me/balance`
200
+ - China source: `GET https://api.moonshot.cn/v1/users/me/balance`
201
+ - Displayed data: available, voucher, and cash balance in USD for Global or CNY for China
202
+ - Statusline examples: `moonshot USD 49.58894` or `moonshot CNY 49.58894`
203
+
204
+ Each endpoint uses Pi's resolved inference Bearer key for the matching region.
205
+ Pi maps both built-in providers to `MOONSHOT_API_KEY`, so that shared environment credential is eligible only for the currently selected region.
206
+ Querying the sibling region requires a provider-specific stored, runtime, or `models.json` credential.
207
+ The extension rejects custom, proxy, and cross-region origins before network access and refuses redirects.
208
+ Available and voucher balances must be nonnegative, while cash balance may be negative when the account owes money.
209
+ The endpoint does not provide historical spend, token totals, quota windows, or reset times.
210
+ These API-platform balances are independent from the `kimi-coding` subscription and booster wallet.
211
+
212
+ 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).
213
+ ### MiniMax Token Plan and API balance
214
+
215
+ - Provider IDs: `minimax` and `minimax-cn`
216
+ - Token Plan source: `GET {region-api-root}/v1/token_plan/remains`
217
+ - Pay-as-you-go source: `GET {region-api-root}/account/query_balance`
218
+ - Region API roots: `https://api.minimax.io` and `https://api.minimaxi.com`
219
+ - Statusline examples: `minimax 15% 5h 80% wk` or `minimax USD 98.00001`
220
+
221
+ Pi's resolved MiniMax API key selects exactly one endpoint before network access.
222
+ Keys with the first-party `sk-api-` prefix query pay-as-you-go balance; other MiniMax API keys query Token Plan quota.
223
+ The extension never probes both endpoints with one credential.
224
+ 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.
225
+ Pay-as-you-go reports keep available, cash, voucher, credit, and owed amounts separate in USD for Global or CNY for China.
226
+ Custom, proxy, and cross-region origins fail before network access, and redirects are rejected.
227
+
228
+ 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.
229
+
176
230
  ### GitHub Copilot
177
231
 
178
232
  - Provider ID: `github-copilot`
@@ -219,6 +273,53 @@ The balance endpoint does not provide historical spend, request windows, reset t
219
273
  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
274
  DeepSeek Harness `cd5ef8148158c3a752a658978873241fdf8e2bbc` reports only per-request model token usage and does not provide account balance data.
221
275
 
276
+ ### Fireworks API spend
277
+
278
+ - Provider ID: `fireworks`
279
+ - Semantics: rated 30-day account spend, not credit balance or spend-cap quota
280
+ - Source: documented `GET https://api.fireworks.ai/v1/accounts` account discovery and `GET https://api.fireworks.ai/v1/accounts/{account_id}/billing/summary` rated costs using Pi's resolved inference API key
281
+ - Displayed data: exact rated spend per currency with serverless, dedicated-deployment, and training subtotals for the trailing 30 days
282
+ - Statusline example: `fireworks USD 12.345678901`
283
+
284
+ The extension queries the fixed endpoints only when the selected model origin is `https://api.fireworks.ai` and any resolved-auth origin override, when present, has the same official origin.
285
+ The account slug is discovered through the documented account listing; a key that can see several accounts must set `fireworksAccountId` in `pi-usage.json` to one of the listed account slugs, and the slug must remain visible to the key.
286
+ Monetary `units` and `nanos` values are summed exactly with integer arithmetic and stay exact through display.
287
+ Fireworks does not expose credit balance, spend caps, per-window quota, or reset times through its API, so `pi-usage` does not claim those Fireworks capabilities; the web console remains the authoritative balance source.
288
+ Rated line items may differ from the final invoice once credits or adjustments are applied.
289
+
290
+ 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.
291
+
292
+ ### Vercel AI Gateway credits
293
+
294
+ - Provider ID: `vercel-ai-gateway`
295
+ - Semantics: current team credit balance and lifetime spend, not rate-limit quota
296
+ - Source: documented `GET https://ai-gateway.vercel.sh/v1/credits` using Pi's resolved AI Gateway API key
297
+ - Displayed data: exact decimal-string credit balance and lifetime spend in USD
298
+ - Statusline example: `vercel USD 95.50 left`
299
+
300
+ The extension queries the fixed endpoint only when the selected model origin and any resolved-auth origin are `https://ai-gateway.vercel.sh`.
301
+ Custom and proxy origins fail before network access, redirects are rejected, and only the resolved Bearer credential is forwarded.
302
+ The credits endpoint does not provide reset times, request-rate counters, or date-window usage, so `pi-usage` does not claim those capabilities.
303
+ Vercel's separate Custom Reporting API is limited to eligible paid plans and is intentionally outside this first integration.
304
+
305
+ 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).
306
+
307
+ ### Baseten Model APIs spend
308
+
309
+ - Provider ID: `baseten`
310
+ - Semantics: organization-wide Model APIs spend, not per-key quota or account balance
311
+ - Source: `GET https://api.baseten.co/v1/billing/usage_summary` using Pi's resolved Baseten API key
312
+ - Displayed data: trailing 30-day gross usage, credits used, and net subtotal in USD
313
+ - Statusline example: `baseten USD 166.15 net`
314
+
315
+ The extension intentionally ignores Dedicated deployment and Training categories because they do not represent Pi's Model APIs provider usage.
316
+ The query window is a precise trailing 30 days and stays below the endpoint's 31-day maximum.
317
+ The fixed Management API endpoint is queried only for an official `https://inference.baseten.co` model and an official resolved-auth origin.
318
+ Custom and proxy origins fail before network access, redirects are rejected, and only the resolved Bearer credential is forwarded.
319
+ An empty `model_apis_usage` result is reported as no Model APIs usage rather than zero account-wide spend.
320
+
321
+ 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).
322
+
222
323
  ### OpenCode Go (Zen)
223
324
 
224
325
  - Provider ID: `opencode-go`
@@ -303,6 +404,11 @@ After the active runtime credential changes, the next command, turn, or schedule
303
404
  The `usage` status item is active only for selected providers that publish statusline usage.
304
405
  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
406
  DeepSeek publishes each returned currency as a separate exact balance segment and reports when the API is unavailable.
407
+ Fireworks publishes exact per-currency rated spend totals and reports when no rated usage exists.
408
+ Moonshot AI publishes the available balance with its region-native currency.
409
+ Vercel AI Gateway publishes the exact current USD credit balance.
410
+ MiniMax publishes Token Plan window percentages or the regional pay-as-you-go available balance.
411
+ Baseten publishes the exact trailing 30-day Model APIs net subtotal after credits.
306
412
  xAI is always menu-only and never starts a scheduled status refresh.
307
413
  Z.AI statusline usage refreshes every five minutes while the selected model remains on Z.AI.
308
414
 
@@ -334,6 +440,11 @@ Credential candidates are collected synchronously in memory and are not cached,
334
440
  The protocol carries no account name or extension identity.
335
441
  Only the selected provider's exact runtime match is used, and secrets are sent only to its validated official origin.
336
442
  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.
443
+ Fireworks spend requests send only that resolved credential to the official `https://api.fireworks.ai` account-listing and billing-summary endpoints and refuse redirects.
444
+ Moonshot balance requests send only the resolved Bearer credential to the matching official Global or China balance origin and refuse redirects.
445
+ Vercel AI Gateway credit requests send only the resolved Bearer credential to `https://ai-gateway.vercel.sh/v1/credits` and refuse redirects.
446
+ 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.
447
+ 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.
337
448
  Pi extensions run with the user's process privileges, so the shared event bus is not a security boundary between installed extensions.
338
449
  Install only trusted extensions because they can read user files and process memory.
339
450
  Protocol v1 interoperability is characterized for the repository's supported Pi runtime.
@@ -348,6 +459,11 @@ An absent or incompatible peer preserves standalone fallback and fail-closed mis
348
459
  - 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.
349
460
  - Provider reports are snapshots and may themselves be delayed by the provider.
350
461
  - 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.
462
+ - 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`.
463
+ - 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.
464
+ - Vercel AI Gateway reports current team credits and lifetime spend only; Custom Reporting and request-rate counters are not queried.
465
+ - MiniMax Token Plan field semantics have changed over time; contradictory counts and percentages are reported as unavailable rather than guessed.
466
+ - Baseten reports organization-wide Model APIs spend, not usage attributable only to Pi's current key; Dedicated and Training spend are excluded.
351
467
  - OpenRouter successful inference responses do not expose proactive request-rate counters; `/usage` reports the documented per-key credit/spend fields instead.
352
468
  - A provider may not return a safe human-readable account identity.
353
469
  In that case the provider and runtime credential state remain visible without exposing secrets.
@@ -390,7 +506,7 @@ The generated runtime is built from the authoritative `src/index.ts` graph and d
390
506
 
391
507
  ## 🔎 Keywords
392
508
 
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.
509
+ 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.
394
510
 
395
511
  ## 📄 License
396
512