GLM (Z.ai) API key setup

Published 2026-10-09 · Updated 2026-10-21

Z.ai, the international face of Zhipu’s GLM models, issues keys in an unusual two-part format: 32 hex characters, a dot, then 16 alphanumeric characters. The first half is a key id, the second is the secret; you send the whole thing, dot included.

Setup

export ZAI_API_KEY="0123456789abcdef0123456789abcdef.A1b2C3d4E5f6G7h8"

Base URL for the OpenAI-compatible API: https://api.z.ai/api/paas/v4. There’s also an Anthropic-compatible endpoint at https://api.z.ai/api/anthropic for tools that speak Claude’s protocol.

Verify

curl https://api.z.ai/api/paas/v4/models \
  -H "Authorization: Bearer $ZAI_API_KEY"

Python

from openai import OpenAI
import os

client = OpenAI(
    api_key=os.environ["ZAI_API_KEY"],
    base_url="https://api.z.ai/api/paas/v4",
)

resp = client.chat.completions.create(
    model="glm-5.1",
    messages=[{"role": "user", "content": "Say hello"}],
)
print(resp.choices[0].message.content)

Gotchas

If a key 401s on both endpoints, it’s revoked, the dot format makes it obvious which service it belonged to, at least.