llm.ledger/v1
Every llm.* call that reaches a provider, and every call a limit refuses, is recorded in the app's ledger: its kind
and model, whom it was for, the tokens and seconds it used and what it cost. This contract reads it: how much of each
limit a user or guest has left, what someone has spent, totals by model, kind, subject or day, and the rows
themselves. A wire contract at /api/_c/llm.ledger/v1 (ledger.go), one provider: the
llm extension, over its _llm_calls collection.
A subject is whom calls were for: user:<collection>/<id>, guest:<id>, guest:ip:<address>, or a name an app's
$llm.onCall handler gave it (team:acme). See llm.WithSubject in
pocketone.dev/ext/contracts/llm.
Use
In page code it's $llm.ledger (bound by the llm extension). These are local reads, not provider calls, so they're
plain. Through $llm.for(ctx), remaining and spent answer about that request's user or guest:
const llm = $llm.for(ctx)
llm.ledger.remaining() // [{ limit: "each guest, $0.10 a day", metric: "cost", used, amount, left, resets }], tightest first
llm.ledger.spent("day") // { calls, refused, input, cached, output, seconds, costMicroUSD }
$llm.ledger.summary({ by: "model", window: "month" }) // [{ key: "vultr/glm-5.3", calls, costMicroUSD, ... }]
$llm.ledger.calls({ subject: "user:users/abc", limit: 20 }) // { calls: [...], more }
Over HTTP:
| Operation | HTTP | Query | Who |
|---|---|---|---|
| Remaining | GET /api/_c/llm.ledger/v1/remaining |
subject (optional) |
anyone signed in: a user (or their API token) gets their own; a superuser (or a superuser's token) any subject |
| Spent | GET /api/_c/llm.ledger/v1/spent |
subject, window (day, month) or since/until, kind, model |
as for Remaining |
| Summary | GET /api/_c/llm.ledger/v1/summary |
by (model, kind, subject, day), the window, subject, kind, model, limit |
a superuser, or a superuser's token with llm:read |
| Calls | GET /api/_c/llm.ledger/v1/calls |
the window, subject, kind, model, status (ok, refused), limit, offset |
a superuser, or a superuser's token with llm:read |
Windows are UTC: day and month are the calendar day and month holding now, the same windows limits count in;
since and until take RFC 3339 or YYYY-MM-DD (until is exclusive). Money is costMicroUSD, millionths of a US
dollar, as in every result's usage. A guest can't ask over HTTP (an operation sees credentials, not the guest
cookie); page code answers guests through $llm.for(ctx).
Errors: bad_request (an unknown window, by or status, a time it can't read), unauthorized (Remaining or Spent
with no credentials), forbidden (a user asking about someone else).
From Go: ledgerv1.Contract.Must(app) (from pocketone.dev/ext/contracts/llm/ledger/v1). Name the subject in the
input, or carry it in the context with llm.WithSubject.
Provide
Implement ledgerv1.Ledger and provide it in Register (ledgerv1.Contract.Provide(app, impl)), over the same record
of calls the provider's limits count from, so remaining agrees with what the next refusal will say. Answer a
non-superuser caller about their own subject only. Sort remaining tightest first (the smallest share left) and
summary costliest first (by day, latest first).
Commands and APIs
Every operation is a REST endpoint, a pocketone command and an MCP tool, all generated from the contract and behind the same token scope check and hooks. See Remote CLI, or the full CLI, Extension APIs and MCP references.
remaining
Is, for each limit in Settings → LLM that counts the subject's calls, how much is used and left in its current window, the tightest first.
| REST | GET /api/_c/llm.ledger/v1/remaining |
| CLI | pocketone remote llm ledger remaining --subject <value> |
| MCP | llm_ledger_remaining |
| Token scope | public |
| Input field | Flag | Type |
|---|---|---|
subject |
--subject |
string |
spent
Is what the subject's calls used in a window.
| REST | GET /api/_c/llm.ledger/v1/spent |
| CLI | pocketone remote llm ledger spent --subject <value> --window <value> --since <value> --until <value> --kind <value> --model <value> |
| MCP | llm_ledger_spent |
| Token scope | public |
| Input field | Flag | Type |
|---|---|---|
subject |
--subject |
string |
window |
--window |
string |
since |
--since |
string |
until |
--until |
string |
kind |
--kind |
string |
model |
--model |
string |
summary
Is what calls used, grouped by model, kind, subject or day.
| REST | GET /api/_c/llm.ledger/v1/summary |
| CLI | pocketone remote llm ledger summary --by <value> --window <value> --since <value> --until <value> --subject <value> --kind <value> --model <value> --limit <n> |
| MCP | llm_ledger_summary |
| Token scope | llm:read |
| Input field | Flag | Type |
|---|---|---|
by |
--by |
string |
window |
--window |
string |
since |
--since |
string |
until |
--until |
string |
subject |
--subject |
string |
kind |
--kind |
string |
model |
--model |
string |
limit |
--limit |
int |
calls
Lists the ledger's rows, newest first.
| REST | GET /api/_c/llm.ledger/v1/calls |
| CLI | pocketone remote llm ledger calls --window <value> --since <value> --until <value> --subject <value> --kind <value> --model <value> --status <value> --limit <n> --offset <n> |
| MCP | llm_ledger_calls |
| Token scope | llm:read |
| Input field | Flag | Type |
|---|---|---|
window |
--window |
string |
since |
--since |
string |
until |
--until |
string |
subject |
--subject |
string |
kind |
--kind |
string |
model |
--model |
string |
status |
--status |
string |
limit |
--limit |
int |
offset |
--offset |
int |
Extensions
| Extension | |
|---|---|
| llm | provides |
License
MIT
Questions and comments
Comments are a GitHub Discussions thread; sign in with GitHub to post.