Expand description
Canonical in-memory representation of “how much have I used my plan”.
Each vendor’s snapshot lives in its own variant — this is deliberate. Anthropic exposes three windows + extra credits; OpenAI Codex exposes two windows + credit balance + message-count ranges; OpenRouter is a single credit-balance number with daily/weekly/monthly totals; Z.AI is a list of token + MCP buckets; DeepSeek is a credit balance; Kimi is a weekly quota plus a 5h rolling rate-limit window. Forcing them into a shared shape would either drop information or paper over genuine differences.
Renderers (widget tooltip, TUI tab) consume a VendorSnapshot directly,
not a flattened shape — so each vendor controls its own presentation while
sharing the pacing math, color thresholds, and Pango primitives.
Structs§
- Anthropic
ApiSnapshot - Anthropic Admin API — month-to-date spend (USD) from the cost report. The
monthly
limitis supplied from config (the API exposes neither the limit nor the remaining prepaid credit balance). - Anthropic
Snapshot - Anthropic-specific snapshot — three rolling windows plus optional pay-as-you-go credit balance.
- Cents
- Money expressed in cents to dodge float roundoff.
- Deepseek
Snapshot - DeepSeek — credit balance from
/user/balance. - Extra
Usage - “Extra usage” pay-as-you-go block (claudebar’s
extra_usage). - Grok
Snapshot - xAI (Grok) — prepaid credit balance in USD, derived from the Management
API’s
total.val(USD cents, inverted-ledger; seegrok::types). - Kilo
Snapshot - Kilo Code — remaining credit balance from
/api/profile/balance(USD). No purchased-total is exposed on that endpoint, so there’s no consumed-%. - Kimi
Snapshot - Kimi Code — weekly subscription quota plus a 5h rolling rate-limit window.
- Moonshot
Snapshot - Moonshot / Kimi — account balance from
/v1/users/me/balance. Currency is USD (api.moonshot.ai) or CNY (api.moonshot.cn); there’s no currency field in the response, so it’s carried here from the region config. - Novita
Snapshot - Novita AI — account balance from
/openapi/v1/billing/balance/detail, with all amounts already converted from the API’s 1/10000-USD integers to USD. - Open
AiCredits - Open
AiSnapshot - OpenAI Codex OAuth — mirrors Anthropic’s two-window + extras pattern.
- Open
Router Snapshot - OpenRouter — credit balance + lifetime/daily/weekly/monthly usage from
/api/v1/creditsand/api/v1/key. - Scoped
Window - A usage window scoped to a specific model, labeled by the API (e.g. “Fable”). Weekly (7d) duration.
- Usage
Window - A single usage window — generic enough that every vendor with a notion of “% used vs. when does it reset” can express itself with it.
- ZaiSnapshot
- Z.AI / BigModel — list of buckets with discriminated types. We project the two we care about into named fields (5h tokens, weekly tokens, MCP).
Enums§
- Open
AiSource - Vendor
Snapshot - Discriminated union of vendor-specific snapshots. The widget and TUI match on this to pick a renderer.
Functions§
- anthropic_
severity - Worst-of severity class for the Waybar bar text color. Mirrors claudebar:606-620 — “extra usage only matters when a rate limit hits 100%”.
- finite_
amount - Reject a non-finite monetary value. A NaN or infinity reaching a balance field means the payload was not what we think it is; displaying it as money (or caching it as authoritative) is worse than failing loudly.
- parse_
amount - Parse a monetary field that the wire encodes as a string. A malformed or empty value is a schema error, not a zero balance — silently reporting $0.00 for an error envelope is the failure mode this guards against.