polygate logopolygate

Provider

Z.AI

GLM models, from Zhipu AI.

Quick start

import polygate
 
response = polygate.chat(
provider="zai",
model="glm-4.6",
messages=[{"role": "user", "content": "Say hi in one word."}],
)
 
print(response.content) # "Hi!"
print(response.usage) # Usage(prompt_tokens=..., completion_tokens=...)

Names

Any of these work as provider. They all reach the same adapter, so pick whichever reads best in your code.

zaiz.aiglmzhipubigmodel

Configuration

VariableHolds
ZAI_API_KEYyour API key

Any of these may hold a comma-separated list. polygate rotates across them, parks a rate-limited one for its Retry-After, and drops one the provider rejects — so a key pool is configuration, not code.

Endpoint

https://api.z.ai/api/paas/v4

Pass base_url to point the same wire format somewhere else — a proxy, a regional endpoint, or a gateway in front of it.

Models

Examples that work today. Model names change; the provider's own list is the authority.

glm-4.6glm-4.5-airglm-5.2

Things worth knowing

  • The base path is /api/paas/v4, not the /v1 almost everyone else uses.
  • There are two platforms with non-interchangeable keys: api.z.ai internationally (the default) and open.bigmodel.cn in mainland China. Same API, different host — pass the other as base_url.

The mainland endpoint

import polygate
 
response = polygate.chat(
provider="zai",
base_url="https://open.bigmodel.cn/api/paas/v4",
model="glm-4.6",
messages=[{"role": "user", "content": "Hello"}],
)

Batch

Z.AI has no offline batch API. To run many requests at once, use map_chat — full price, but it works everywhere and returns in seconds. See Batching & concurrency.

Something wrong or missing here? Open an issue.