Expand description
ai-usagebar library — shared core for the Waybar widget and TUI binaries.
The crate is organized by concern, not by binary:
- low-level primitives (
cache,countdown,pacing,pango,theme) - the vendor abstraction (
vendor,vendors::*,usage) - bin-specific composition (
widget,tui) which lives next to its binary
The two binaries (ai-usagebar and ai-usagebar-tui) are thin: they parse
CLI args, instantiate vendors, and hand off to a renderer in this crate.
Re-exports§
Modules§
- active
- Active-vendor state file. Set by
--cycle-next/--cycle-prev(which Waybar’son-scroll-up/on-scroll-downinvoke), read by the widget on every tick. The TUI does NOT consult this — it has its own tab state. - anthropic
- Anthropic vendor — OAuth-based plan usage via the undocumented
https://api.anthropic.com/api/oauth/usageendpoint. - anthropic_
api - Anthropic Admin API vendor — month-to-date spend from
/v1/organizations/cost_reportover a Console Admin key (distinct from the inference key and from the Claude Code OAuth login). The remaining prepaid credit balance is Console-only (no API), so this reports spend. - antigravity
- Google Antigravity vendor — quota tracking via the local language server.
- cache
- Per-vendor on-disk cache with atomic writes, TTL checks, and inter-process locking.
- config
- Config file at
~/.config/ai-usagebar/config.toml. - context
- Best-effort, local-only Claude Code context-window discovery.
- countdown
- Human-readable countdown between two instants.
- deepseek
- error
- Shared error type. Vendors and renderers convert their failures into
AppErrorso the widget shell can decide whether to retry, fall back to cache, show ⚠, or show “Loading…”. - format
{placeholder}substitution for--formatand--tooltip-format.- grok
- xAI (Grok) vendor — prepaid credit balance from the Management API
(
management-api.x.ai) over a management key (distinct from the inference key), optionally auto-resolving the team id. - kilo
- Kilo Code vendor — credit balance from
/api/profile/balanceover an API key (an undocumented endpoint used by the Kilo Code extension; seetypes.rs). - kimi
- moonshot
- Moonshot / Kimi vendor — account balance from
/v1/users/me/balanceover an API key. USD onapi.moonshot.ai, CNY onapi.moonshot.cn. - novita
- Novita AI vendor — account credit balance from
/openapi/v1/billing/balance/detailover an API key. - openai
- OpenAI vendor — Codex OAuth via
~/.codex/auth.json+ the undocumentedchatgpt.com/backend-api/wham/usageendpoint. Reference:~/Projects/codexbar/codexbarby the same author as claudebar. - openrouter
- OpenRouter vendor —
/api/v1/creditsand/api/v1/keyover an API key. - pacing
- Pacing math — encodes claudebar’s
calc_pacing(claudebar:279-321) andpace_color_for(claudebar:212-219) as pure functions. - pango
- Pango-markup rendering helpers shared by the widget bar text and tooltip.
- theme
- Color palette resolution.
- tooltip
- Pango-bordered tooltip primitives shared by every vendor renderer.
- tui
- TUI binary support — ratatui app with one tab per enabled vendor.
- usage
- Canonical in-memory representation of “how much have I used my plan”.
- vendor
- Shared vendor IDs and renderer/fetcher structs used by the widget and TUI.
- waybar
- Waybar JSON output:
{text, tooltip, class}. - widget
- Widget binary support: CLI parsing, per-vendor rendering, the always-exit-0
wrapper, and the local-testing renderers (
--pretty,--watch,--json). - zai
- Z.AI / BigModel vendor — undocumented
/api/monitor/usage/quota/limit. Auth header isAuthorization: <KEY>with NOBearerprefix.