Skip to main content

Z.AI (Zhipu AI)

Z.AI (Zhipu AI) makes the GLM model family; LiteLLM calls the GLM text and chat models with the zai/ prefix from the Python SDK or AI Gateway.

https://z.ai/

We support Z.AI GLM text/chat models, just set zai/ as a prefix when sending completion requests

API Key​

# env variable
os.environ['ZAI_API_KEY']

Sample Usage​

from litellm import completion
import os

os.environ['ZAI_API_KEY'] = ""
response = completion(
model="zai/glm-4.7",
messages=[
{"role": "user", "content": "hello from litellm"}
],
)
print(response)

Sample Usage - Streaming​

from litellm import completion
import os

os.environ['ZAI_API_KEY'] = ""
response = completion(
model="zai/glm-4.7",
messages=[
{"role": "user", "content": "hello from litellm"}
],
stream=True
)

for chunk in response:
print(chunk)

Supported Models​

We support ALL Z.AI GLM models, just set zai/ as a prefix when sending completion requests.

Model NameFunction CallNotes
glm-4.7completion(model="zai/glm-4.7", messages)Latest flagship, 200K context, Reasoning
glm-4.6completion(model="zai/glm-4.6", messages)200K context
glm-4.5completion(model="zai/glm-4.5", messages)128K context
glm-4.5vcompletion(model="zai/glm-4.5v", messages)Vision model
glm-4.5-xcompletion(model="zai/glm-4.5-x", messages)Premium tier
glm-4.5-aircompletion(model="zai/glm-4.5-air", messages)Lightweight
glm-4.5-airxcompletion(model="zai/glm-4.5-airx", messages)Fast lightweight
glm-4-32b-0414-128kcompletion(model="zai/glm-4-32b-0414-128k", messages)32B parameter model
glm-4.5-flashcompletion(model="zai/glm-4.5-flash", messages)FREE tier

Latest model aliases​

Since v1.109.0

zai/<family>-latest names follow a model family as LiteLLM moves them to newer models, so your application keeps one model string. Use them like any other Z.AI model name. LiteLLM sends Z.AI the current target model and bills at that model's price. See Latest model aliases for how aliases work and the full list across providers.

AliasModel family
zai/glm-latestGLM
zai/glm-flash-latestGLM Flash

Model Pricing​

ModelInput ($/1M tokens)Output ($/1M tokens)Cached Input ($/1M tokens)Context Window
glm-4.7$0.60$2.20$0.11200K
glm-4.6$0.60$2.20-200K
glm-4.5$0.60$2.20-128K
glm-4.5v$0.60$1.80-128K
glm-4.5-x$2.20$8.90-128K
glm-4.5-air$0.20$1.10-128K
glm-4.5-airx$1.10$4.50-128K
glm-4-32b-0414-128k$0.10$0.10-128K
glm-4.5-flashFREEFREE-128K

Using with LiteLLM Proxy​

from litellm import completion
import os

os.environ['ZAI_API_KEY'] = ""
response = completion(
model="zai/glm-4.7",
messages=[{"role": "user", "content": "Hello, how are you?"}],
)

print(response.choices[0].message.content)
LiteLLM Enterprise
SSO/SAML, audit logs, spend tracking, multi-team management, and guardrails, built for production.
Learn more →