$ bunx zai-usage

zai-usage

Know your GLM Coding Plan — quota windows, behavioral reviews, and what your usage is worth in list-price dollars.

Single file · zero dependencies · Bun/TypeScript · your key stays yours

Quick start

export GLM_API_KEY=...        # or ZAI_API_KEY / Z_AI_API_KEY
bunx zai-usage                # quota overview

What it reads

Four undocumented Z.ai endpoints, using your GLM Coding Plan API key only. Nothing is written anywhere; the optional AI coach receives aggregate metrics only — never your prompts or code (details).

  1. GET /api/monitor/usage/quota/limit — plan level, 5-hour token %, monthly tool-call %
  2. GET /api/monitor/usage/model-usage — per-model tokens and calls per window
  3. GET /api/biz/customer-package-reset/list — reset packs and your customerId (auto-discovery)
  4. GET /api/platform-charge-zai/bill/day — the day-level billing ledger everything else is computed from

Modes

ModeWhat it tells you
(default)5-hour quota %, per-model rolling windows, reset packs
usageper-model tokens/calls across Hour/24h/7d/30d/current month
week / monthbehavioral review: this span vs previous, 8 tip rules, AI coach
bill [YYYY-MM]month ledger: list-price spend, billed vs plan-covered, cache savings, MoM
benefits · codingplan-benefitslifetime plan value since first billed month (--since YYYY-MM)
pricesprice points learned from your own ledger
estimatewhat a hypothetical workload would cost on list prices
runwayhow long until the 5h window / monthly calls run out at current pace
comparediff two accounts (e.g. Lite vs Pro) side by side
exportraw ledger as CSV or JSONL
checkagent gate: --json, exit codes, thresholds for automations

Flags and annotated output for every mode are in the full guide.

Install

# run without installing
bunx zai-usage
npx zai-usage

# or install the single file
curl -fsSL -o ~/.local/bin/zai-usage \
  https://raw.githubusercontent.com/LogicIncZo/zai-usage/main/zai-usage.ts
chmod +x ~/.local/bin/zai-usage