How to hit the Z.ai (GLM) API

Z.ai (formerly Zhipu AI) serves its GLM models at https://api.z.ai/api/paas/v4 with an OpenAI-compatible chat API. There's also an Anthropic-compatible endpoint at https://api.z.ai/api/anthropic.

Authentication

Create a key at z.ai. Send it as Authorization: Bearer <key>. In the examples it's written {{ZAI_API_KEY}}.

Full reference: https://docs.z.ai/api-reference/introduction

Chat completion

curl https://api.z.ai/api/paas/v4/chat/completions \
  -H "Authorization: Bearer {{ZAI_API_KEY}}" \
  -H "Content-Type: application/json" \
  -d '{"model": "glm-5.3", "messages": [{"role": "user", "content": "Explain what an API rate limit is in two sentences."}]}'
Run in PostTaco

Use GLM 5.3 Flash

The faster, cheaper variant.

curl https://api.z.ai/api/paas/v4/chat/completions \
  -H "Authorization: Bearer {{ZAI_API_KEY}}" \
  -H "Content-Type: application/json" \
  -d '{"model": "glm-5.3-flash", "messages": [{"role": "user", "content": "Write a one-line commit message for fixing a typo."}]}'
Run in PostTaco

List models

curl https://api.z.ai/api/paas/v4/models \
  -H "Authorization: Bearer {{ZAI_API_KEY}}"
Run in PostTaco