Skip to content

feat: add Z.ai usage quota monitor - #11

Merged
NihilDigit merged 3 commits into
NihilDigit:mainfrom
FelipeMayerDev:feat/zai-support
Apr 30, 2026
Merged

NihilDigit merged 3 commits into
NihilDigit:mainfrom
FelipeMayerDev:feat/zai-support

Conversation

@FelipeMayerDev

Copy link
Copy Markdown
Contributor

Summary

  • Add zai.py provider that monitors Z.ai usage via the api.z.ai/api/monitor/usage/quota/limit endpoint
  • Displays 5-hour token usage in the Waybar bar with reset timer
  • Shows monthly tool quota breakdown (search-prime, web-reader, zread) in the tooltip
  • Uses token-based auth from ~/.config/waybar-ai-usage/zai.conf (same pattern as Copilot module)
  • Color-coded by usage level: green (zai-low), yellow (zai-mid), red (zai-high)

Changes

File Change
zai.py New Z.ai provider module
pyproject.toml Register zai-usage script entry point
waybar_ai_usage.py Add Z.ai to MODULES, config template, style template, setup/cleanup
waybar-config-example.jsonc Add Z.ai module block (signal 12)
waybar-style-example.css Add Z.ai CSS styles
README.md Add Z.ai to description, setup guide, usage examples

Setup

mkdir -p ~/.config/waybar-ai-usage
# Get token: z.ai > F12 > Network > copy Authorization header (eyJ...)
echo "ZAI_TOKEN=eyJ..." > ~/.config/waybar-ai-usage/zai.conf
zai-usage --waybar

Auth Notes

Z.ai uses an HS512 JWT for API calls that is generated in JavaScript memory (not persisted to cookies or localStorage). Unlike Claude/Codex, browser auto-detection is not feasible, so config-file auth (like Copilot) is the only reliable approach.

Add zai.py provider that monitors Z.ai (GLM models) usage via the
api.z.ai quota/limit endpoint. Uses token-based auth from
~/.config/waybar-ai-usage/zai.conf (same pattern as Copilot).

Displays 5-hour token usage in the Waybar text with reset timer, and
monthly tool quota (web search, reader, ZRead) breakdown in the tooltip.
Color-coded by usage level: green (low), yellow (mid), red (high).
Add window_not_started check (matching claude/codex pattern) so Z.ai
shows 'Ready' instead of '0% ??' when the API returns percentage 0
with no nextResetTime or remaining fields.

@NihilDigit NihilDigit left a comment •

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Overall the integration looks solid — pattern matches Copilot, setup CLI / CSS / cleanup are all wired up. A few small things I'd like to see fixed before merge:

1. is_unused and window_not_started collapse to the same condition (zai.py:179-180)

is_unused = pct == 0 and tl and tl.get("remaining") is not None
window_not_started = pct == 0 and tl and tl.get("nextResetTime") is None

Their union is just pct == 0 and tl, so status = "Ready" whenever pct == 0. The two-variable split implies a distinction that doesn't exist. Either collapse into a single check, or actually distinguish the two cases (e.g. only "Ready" when the API explicitly reports an unused window vs. one that hasn't started yet).

2. Redundant branch in _format_ms_reset (zai.py:111-119)

return format_eta(None) if secs <= 0 else format_eta(reset_dt.isoformat())

format_eta already handles the secs <= 0 case internally (returns "0m00s"), so the branch is unnecessary — and worse, format_eta(None) returns "0′00″", a different format. Simplify to:

return format_eta(reset_dt.isoformat())

(The try/except and secs calculation can also go away if you just pass through to format_eta.)

3. _format_tokens is unused (zai.py:96-101)

Dead code — please either drop it, or wire it into the tooltip (showing token counts alongside percentages would actually be nice).

4. Stray blank line / extra indentation inside the cleanup tuple (waybar_ai_usage.py:478-482)

"#custom-zen-balance",

    "#custom-zai-usage",
)

The blank line and 4-space indent inside the tuple literal look like a merge artifact. Should just be:

"#custom-zen-balance",
"#custom-zai-usage",
)

Thanks again — happy to merge once these are addressed.

@FelipeMayerDev

Copy link
Copy Markdown
Contributor Author

Thanks for the review! I pushed the requested fixes: collapsed the redundant Ready-state checks, simplified the reset formatting through format_eta, wired _format_tokens into the tooltip, and cleaned up the stray tuple formatting in waybar_ai_usage.py. Appreciate the detailed feedback!

@NihilDigit
NihilDigit merged commit f36307d into NihilDigit:main Apr 30, 2026
@NihilDigit

Copy link
Copy Markdown
Owner

Thanks for the quick turnaround — all four points addressed cleanly, and the diff actually got smaller in the process. Merged.

Thanks for the solid contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants