#!/usr/bin/env python3 """One-off diagnostic for the z.ai GLM Coding Plan usage endpoint (the source ZaiProvider reads). Dumps the raw quota JSON so the window mapping can be checked against a live plan. Usage (key via env so it never lands in shell history): ZAI_API_KEY=... python tools/probe_zai.py [host] Default host = https://api.z.ai . It's a status GET — it does NOT spend the prompt-metered plan. The API key is read from the environment and never printed. """ import json import os import sys import httpx HOST = (sys.argv[1] if len(sys.argv) > 1 else "https://api.z.ai").rstrip("/") KEY = os.environ.get("ZAI_API_KEY") or os.environ.get("ANTHROPIC_AUTH_TOKEN") if not KEY: sys.exit("Set ZAI_API_KEY in the environment first (it is not printed).") url = f"{HOST}/api/monitor/usage/quota/limit" print(f"GET {url}") try: resp = httpx.get(url, headers={"Authorization": KEY, "Accept-Language": "en-US,en"}, timeout=30.0) except httpx.HTTPError as e: sys.exit(f"request failed: {e}") print(f"HTTP {resp.status_code}\n") try: print(json.dumps(resp.json(), indent=2, ensure_ascii=False)) except ValueError: print(resp.text[:1000])