← Catalog

pi-dent-purse

A pi extension that collects per-provider LLM billing state and serves it to other extensions and the user

Extension

Install

Install with PiG

pig install npm:pi-dent-purse

Install with Pi

pi install npm:pi-dent-purse
Review before installing

Packages 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, never 0 — a failed capture cannot read as free.
  • Failures back off instead of retrying at once; PURSE_OFFLINE=1 stops 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_start of 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 provider exa), 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). For anthropic and amd it 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, with statusLine on, a status line for the current model's provider; specs/user-interface.md owns both.
  • Other extensions read provider entries on purse:query:v1, hear purse:changed:v1, and contribute header observations on purse: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

DocumentRead it when you …
docs/development.mdwork on this repository.
specs/adapter-contract.mdchange or add an adapter.
specs/billing-state.mdchange the provider entry shape.
specs/config-file.mdchange configuration keys or environment.
specs/prices.mdchange how prices are derived.
specs/query-protocol.mdwrite an extension that reads billing state.
specs/refresh.mdchange refresh, caching, or backoff.
specs/user-interface.mdchange /purse or the status line.

License

MIT