pi-ollama-usage
Pi extension that shows Ollama Cloud quota usage (monthly) in the footer status line
Package details
Install pi-ollama-usage from npm and Pi will load the resources declared by the package manifest.
$ pi install npm:pi-ollama-usage- Package
pi-ollama-usage- Version
1.2.0- Published
- Nov 1, 2026
- Downloads
- 358/mo · 68/wk
- Author
- moemen
- License
- MIT
- Types
- extension
- Size
- 51.3 KB
- Dependencies
- 0 dependencies · 1 peer
Pi manifest JSON
{
"extensions": [
"./extensions"
]
}Security note
Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.
README
pi-ollama-usage
A Pi extension that shows your Ollama Cloud quota usage in the footer status line:
Mo:$0.72 1.2%
$0.72 is the exact spend of the current calendar month; 1.2% is that
spend as a share of the plan's included credit (the share is omitted while the
plan — and therefore its allowance — is unknown). Labels are dimmed and the
percentage is color-coded by usage stress — green below 70%, yellow from 70%,
red from 90% of the month's credit. Set NO_COLOR to disable colors.
Uses the authenticated GET https://ollama.com/api/usage surface with your Ollama Cloud API key — the same data as the ollama.com/settings dashboard. What that API actually exposes (verified 2026-11-01):
- Exact consumption —
totals.usage_usdin dollars, plusrequest_countand input/cached/output tokens;buckets[]breaks the same numbers down per day. Only three windows exist:range=24h,7d,30d(anything else is rejected withrange must be 24h, 7d, or 30d). - Month-to-date is computed, not reported — the quota resets per calendar
month, but the API only offers rolling windows. The extension sums the daily
buckets whose
fromis on/after the 1st of the current month, which is exact (the 30d window always reaches past it). - The plan —
POST https://ollama.com/api/mereturnsPlan(pro,max,team, …) and nothing else about billing; the olderlimitsblock is gone from/api/usage. So the allowance is the one number the API does not expose: it comes fromPLAN_CREDITSinextensions/index.ts. To calibrate it against the dashboard, readallowance = dollars ÷ dashboard percentage(e.g.$70.71 at 70%→≈ $101) and put that number in the table. - Per-model request counts and 30-day activity cost (via
/ollama-usage).
The indicator only appears while an Ollama Cloud model is active (provider ollama-cloud, or the built-in ollama provider with a :cloud model).
Install
pi install git:github.com/MoemenMostafa/pi-ollama-usage
(An npm package may follow; until then install from git.)
Setup
Works out of the box if you are signed in to the Ollama app/CLI (ollama signin) —
the extension reuses the local daemon's signed identity (~/.ollama/id_ed25519),
the same one used for cloud model requests. No API key needed.
Alternatively, create an API key at ollama.com/settings/keys and make it available in one of these ways (checked in order):
- Pi provider auth —
/login ollamaor anollama-cloudentry from pi-ollama-cloud OLLAMA_API_KEYenvironment variable (e.g. in~/.zshrc:export OLLAMA_API_KEY=...)~/.pi/agent/auth.json→{ "ollama-cloud": { "type": "api-key", "key": "..." } }or the same under"ollama"
Commands
/ollama-usage— one-shot full usage report (monthly window, per-model request counts, 4-week activity cost)/ollama-usage status— show whether the footer indicator is on/off/ollama-usage status on|off— enable/disable the footer indicator (on by default)/ollama-auth— interactive auth TUI:- Test current credential — live check against
ollama.com/api/usage, shows current usage if it works - Set / update API key — paste a key, it is validated live, then saved to
~/.pi/agent/auth.json(file mode tightened to 0600) - Remove stored key — deletes the
ollama/ollama-cloudentries fromauth.json(env vars and Pi provider auth untouched)
- Test current credential — live check against
In non-interactive modes (pi -p, JSON/RPC), /ollama-auth prints the active credential as text instead of opening dialogs.
Footer placement
The indicator is a plain extension status (ctx.ui.setStatus), so it always renders on the
extension-status line below the footer — pi's built-in footer and
pi-open-tui's footer alike. Its colors are kept
by pi-open-tui ≥ 0.4.0, which preserves extension ANSI styles.
It is deliberately not inlined into the host TUI's own stats row. That needed a local
patch of pi-open-tui's footer.ts, and the patch broke the TUI whenever pi-open-tui
touched that file (0.4.0 renamed the status sanitizer, and the stale patch made every
render throw ReferenceError: sanitizeStatus is not defined). No part of pi is patched
any more — see CHANGELOG 1.2.0.
Behavior
- Refreshes on session start, model switch, and after turns — rate-limited to at most once per minute (Ollama answers
429 too many requestsif you poll harder than that). - Output is color-coded by usage stress (footer indicator and
/ollama-usagereport): green below 70%, yellow from 70%, red from 90%.NO_COLORdisables colors. Mo:$x.xxis the exact calendar-month-to-date spend; the percentage is that spend against the plan credit and is hidden when the plan is unknown (the API does not report the allowance).- Hides automatically when you switch away from a cloud model, when no API key is available, or on API errors (footer is cosmetic; errors surface only in
/ollama-usage). - Fetches are bounded: 15s timeout, no redirects, malformed/oversized responses are rejected.
License
MIT