GuidesConfiguration
Configuration
Setting the Z.ai API key, the display timezone and the quota endpoint with environment variables or flags, and which one wins.
zquota has no config file. It reads three settings, each from a flag or an environment variable, and the flag wins when both are set:
| Setting | Flag | Environment variable | Default |
|---|---|---|---|
| API key | --api-key |
ZAI_API_KEY |
none, so one of them is required |
| Timezone | --timezone, -z |
ZAI_TIMEZONE |
Europe/London |
| Endpoint | --api-url |
ZAI_API_URL |
https://api.z.ai/api/monitor/usage/quota/limit |
Everything else is chosen per run with flags, listed in the CLI reference.
The API key
Section titled “The API key”zquota sends the key to Z.ai as a bearer token. Keep it in the environment:
export ZAI_API_KEY='your-api-key'Put that line in your shell’s profile, such as ~/.zshrc or ~/.bashrc, to have it in every new
terminal. If you’d rather not keep the key in a profile that’s backed up or shared, write the same
line into a file of its own with an editor, so the key doesn’t pass through your shell history:
export ZAI_API_KEY='your-api-key'Then make it readable only by you, and load it from your profile:
chmod 600 ~/.config/zquota.env. ~/.config/zquota.env--api-key works too, but a key on the command line ends up in your shell history and is visible
to other users in the process list while zquota runs. Use it for a one-off check with a different
key, not as a habit.
An empty --api-key '' counts as not given, so zquota falls back to ZAI_API_KEY. With neither,
it stops before making a request:
ERROR: ZAI_API_KEY is not setSet it with: export ZAI_API_KEY='your-api-key'and exits with code 1.
The timezone
Section titled “The timezone”Reset times are shown in Europe/London unless you set an IANA timezone name:
zquota --timezone America/New_Yorkexport ZAI_TIMEZONE=America/New_YorkAn unrecognised name gets a warning and falls back to Europe/London.
Reset times has the details, including what
the timezone does and doesn’t change.
The endpoint
Section titled “The endpoint”ZAI_API_URL and --api-url replace the quota endpoint. You won’t need them to use Z.ai; they’re
for testing, or for a proxy that sits in front of the API. zquota sends the same request with your
key to whatever address you give, so only point it at endpoints you trust.
The address can also be a file:// URL. zquota then reads a saved response from disk instead of
asking Z.ai, which is handy for testing a script against a known answer:
zquota --raw > response.jsonzquota --api-url "file://$PWD/response.json" --compactzquota still needs a key for a file:// address, though it doesn’t send it anywhere, so set any
value if ZAI_API_KEY isn’t set. Scripts and alerts
uses this to test a threshold check.
Settings that apply to one run
Section titled “Settings that apply to one run”Colour, the output format, --watch and --threshold have no environment variables. Set them on
each run, or wrap zquota in a shell alias or function if you always want the same ones:
alias zq='zquota --compact --timezone UTC'