Install
Install with PiG
pig install npm:pi-dent-purseInstall with Pi
pi install npm:pi-dent-pursePackages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.
Pi manifest JSON
The pi field of package.json.
{
"extensions": [
"./index.ts"
]
}README
Written by the package's publisher, shown as published in version 0.2.1 (README.md). PiG does not review it.
pi-dent-purse
A pi extension that collects per-provider LLM billing state — prices, balances, usage limits — and serves it to the user and to other extensions. pi-dent bundles it; a standalone pi can install it on its own.
Why
An agent spread over many LLM providers runs out of balances and into rate windows mid-task. Purse keeps the answer in one place instead of leaving every tool to call provider APIs itself:
- One adapter per provider, fixed by its spec: it contacts only its allowlisted https origins and caps every response body, so a bug cannot send credentials anywhere else.
- Prices are derived from pi's model inventory and the configuration; deriving them never issues a request or runs a command.
- A value no adapter captured is
null, never0— a failed capture cannot read as free. - Failures back off instead of retrying at once;
PURSE_OFFLINE=1stops all refreshes.
It is a separate package on purpose: it reads no pi-dent configuration and depends on no other extension, so pi-dent can bundle it and a bare pi can install it.
How it works
- At the first
session_startof a boot window, pi-dent-purse reads the configuration once, works out the known providers — the providers the session can actually use — and serves that image for the whole window. - For each provider with an adapter (
amd,anthropic,antigravity,deepseek,google,openai-codex,zai, and the tool providerexa), it captures plan, balances, and usage-limit windows into an in-memory cache; nothing is written to disk. Freshness periods and failure backoff decide when an adapter runs again (specs/refresh.md). Foranthropicandamdit also reads the billing headers of the provider's own inference responses, so an ordinary model call doubles as a capture. - The user sees
/purse [all] [refresh] [provider …]and, withstatusLineon, a status line for the current model's provider;specs/user-interface.mdowns both. - Other extensions read provider entries on
purse:query:v1, hearpurse:changed:v1, and contribute header observations onpurse:observe:v1(specs/query-protocol.md). - Unknown keys and values that violate their contract are ignored, one diagnostic each; the
rest still loads (
specs/config-file.md).
Using it
pi install npm:pi-dent-purse # add it to pi's packages
pi-dent bundles it: do not install both. Requires Node 26 or later.
Configuration is optional — the file ~/.pi/purse/purse.conf (JSONC), or the absolute path in
PURSE_CONF:
{
"providers": { "deepseek": { "lowBalance": 5 } },
"statusLine": true,
}
Root keys, provider keys, and the PURSE_* variables are owned by specs/config-file.md.
Documentation
| Document | Read it when you … |
|---|---|
docs/development.md | work on this repository. |
specs/adapter-contract.md | change or add an adapter. |
specs/billing-state.md | change the provider entry shape. |
specs/config-file.md | change configuration keys or environment. |
specs/prices.md | change how prices are derived. |
specs/query-protocol.md | write an extension that reads billing state. |
specs/refresh.md | change refresh, caching, or backoff. |
specs/user-interface.md | change /purse or the status line. |
License
MIT