Skip to content

soakes/quotai

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

42 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“Š QuotAI

A small terminal CLI for showing Z.ai quota usage, remaining capacity, and exact reset times.

Validate Release APT Repository Python License Stdlib Only Buy Me a Coffee

Keeping an eye on your AI quota. quotai (pronounced quota-eye) queries the Z.ai quota endpoint and renders the result in a terminal view that is easy to read at a glance. It was built because the Z.ai usage charts are useful, but they do not make the rolling five-hour reset window and exact reset time clear enough when you are trying to plan work.

The default output is for humans. JSON, JSON Lines, compact, and raw modes are available for scripts, dashboards, cron jobs, and debugging.

This is an unofficial tool and is not affiliated with Z.ai.

Quick links: Website and APT repo | Releases | Usage guide | Release flow | License

🧭 Contents

πŸ“– Overview

Z.ai exposes quota information through an authenticated API endpoint. quotai turns that response into:

  • the current Z.ai plan level
  • the known quota windows, including the five-hour rolling token quota
  • percentage used and percentage remaining
  • exposed limit, used, and remaining unit counts
  • exact reset time in your chosen timezone
  • UTC reset timestamp and epoch milliseconds for machine-readable output

The script has no runtime dependencies outside the Python standard library.

✨ Capabilities

  • Human-friendly terminal panels with colour-coded usage bars
  • Compact one-line output for small terminals and status panes
  • JSON output for jq, automation, and monitoring integrations
  • JSON Lines output for logs and append-only collection
  • Raw API response mode for debugging endpoint changes
  • Watch mode for a live refreshing quota dashboard
  • Threshold mode with a separate exit code for cron and shell scripts
  • Timezone control through --timezone or ZAI_TIMEZONE
  • Installable as a Homebrew formula, signed Debian package, single executable script, or Python package

πŸš€ Installation

Homebrew (macOS and Linux)

brew tap soakes/quotai
brew install quotai

Signed APT Repository

For Debian and Ubuntu hosts, use the signed GitHub Pages APT repository:

sudo install -d -m 0755 /etc/apt/keyrings
curl -fsSL https://soakes.github.io/quotai/quotai-archive-keyring.gpg \
  | sudo tee /etc/apt/keyrings/quotai-archive-keyring.gpg >/dev/null

sudo tee /etc/apt/sources.list.d/quotai.sources >/dev/null <<'EOF'
Types: deb deb-src
URIs: https://soakes.github.io/quotai/
Suites: stable
Components: main
Signed-By: /etc/apt/keyrings/quotai-archive-keyring.gpg
EOF

sudo apt update
sudo apt install quotai

Download the Script

mkdir -p ~/.local/bin
curl -fsSL https://raw.githubusercontent.com/soakes/quotai/main/quotai.py -o ~/.local/bin/quotai
chmod +x ~/.local/bin/quotai

Make sure ~/.local/bin is on your PATH.

Install From Git

python3 -m pip install git+https://github.com/soakes/quotai.git

Build From Source

git clone https://github.com/soakes/quotai.git
cd quotai
python3 -m pip install .

βš™οΈ Configuration

Set your Z.ai API key in the environment:

export ZAI_API_KEY='your-api-key'

Supported environment variables:

Variable Required Description Default
ZAI_API_KEY yes Bearer token used to query the quota endpoint none
ZAI_API_URL no Alternate quota endpoint, mainly useful for testing https://api.z.ai/api/monitor/usage/quota/limit
ZAI_TIMEZONE no Timezone used for displayed reset times Europe/London

CLI flags take precedence over environment variables.

πŸ§ͺ Usage

Run the default terminal view:

quotai

Example output:

  Z.ai plan: pro

  β”‚  5-Hour Rolling Token Quota
  β”‚
  β”‚  [β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘] 50% used
  β”‚  Remaining: 50%
  β”‚  Limit:      1.0M
  β”‚  Used:       500.0k
  β”‚  Remaining: 500.0k
  β”‚  Resets in:   30m
  β”‚  Resets at:   2026-05-23 15:00:00 BST
  ──────────────────────────────────

Show a compact status view:

quotai --compact

Use a specific timezone:

quotai --timezone America/New_York

Refresh every 30 seconds:

quotai --watch 30

Exit with code 2 if any quota is at or above 80 percent:

quotai --threshold 80

πŸ“‹ Output Formats

Format Flag Use case
Pretty default Human-readable terminal output
Compact --compact One line per quota
JSON --json Scripting, dashboards, and jq
JSON Lines --jsonl Logs and append-only collection
Raw --raw Debugging the upstream API response

JSON output includes both local and UTC reset fields:

quotai --json | jq '.quotas[] | {quota: .name_compact, local: .resets_at, utc: .resets_at_utc}'
{
  "quota": "5h-rolling",
  "local": "2026-05-23 15:00:00 BST",
  "utc": "2026-05-23T14:00:00Z"
}

πŸšͺ Exit Codes

Code Meaning
0 Success
1 Runtime or input error
2 Threshold exceeded when --threshold is set

The separate threshold exit code makes it safe to distinguish quota pressure from a broken API key, network failure, or invalid response.

πŸ› οΈ Development

Create a local environment and install the development tools:

python3 -m venv .venv
. .venv/bin/activate
python3 -m pip install -e '.[dev]'

Run the local checks:

make fmt-check
make lint
make test
make smoke
make version-check

Format code:

make fmt

Build a Python package:

make build

Build the website locally:

make website-build

πŸ—‚οΈ Project Structure

quotai/
β”œβ”€β”€ quotai.py                 # CLI application
β”œβ”€β”€ tests/                    # Stdlib unittest coverage
β”œβ”€β”€ debian/                   # Debian package metadata
β”œβ”€β”€ homebrew/                 # Homebrew formula template
β”œβ”€β”€ docs/                     # Usage and release documentation
β”œβ”€β”€ scripts/                  # Release helper scripts
β”œβ”€β”€ .github/
β”‚   β”œβ”€β”€ assets/website/       # GitHub Pages landing site
β”‚   └── workflows/            # GitHub Actions release automation
β”œβ”€β”€ AGENTS.md                 # Repository rules for coding agents
β”œβ”€β”€ pyproject.toml            # Packaging and tool configuration
β”œβ”€β”€ Makefile                  # Local validation shortcuts
β”œβ”€β”€ LICENSE                   # MIT License
└── README.md                 # Project overview

πŸ“„ License

quotai is released under the MIT License.