Store the key as a secret variable.
List Models
model ID from the public catalog response. Chat requests require the key and account eligibility for the selected model.
Chat Completion
choices[0].message.content; usage reports tokens. One choice; system_fingerprint is null. For attested hardware use a :confidential ID, for example z-ai/glm-5.2:confidential. Encrypted needs extra headers and client-side encryption.
/v1/responses, /v1/messages, and /v1/messages/count_tokens use the same base URL and auth. See the API Reference.
Errors and Streaming
Errors are{"error": {"message", "code", "param"}}. A 429 carries Retry-After and X-RateLimit-*. Model responses carry Cache-Control: no-store.
Add "stream": true for Server-Sent Events: data: lines with JSON chunks, ending in data: [DONE]. A terminal curl -N is often easier to read. See Streaming.

