Z.ai
Z.ai GLM models with multimodal input, thinking, and function calling.
Overview
Z.ai provides the GLM model family (including its coding-focused endpoint) with native multimodal capabilities. Z.ai is OpenAI- and Zhipu-compatible, so through Yunxin its models are accessed via the Chat Completions API format.
Official Website: https://z.ai API Documentation: https://docs.z.ai
Key features
- Multimodal input — Text plus images (
image_url) and documents (file_url) - Thinking/reasoning — Extended reasoning via the
thinkingparameter - Function calling — Full tool use support
- Structured output — JSON and schema-constrained responses via
response_format - Embeddings — Text embeddings for semantic search
- Image & video generation — Text-to-image and text-to-video
- Audio — Text-to-speech and speech-to-text
- Streaming — Server-sent events for real-time responses
Using Z.ai with Yunxin
Address Z.ai models using the provider/model convention by prefixing with zai/ (for example, zai/glm-4). Requests use the same Yunxin base URL (https://api.yuhuanstudio.com/v1) and your Yunxin sk- API key.
Usage example
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["YUNXIN_API_KEY"],
base_url="https://api.yuhuanstudio.com/v1"
)
response = client.chat.completions.create(
model="zai/glm-4",
messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.YUNXIN_API_KEY,
baseURL: "https://api.yuhuanstudio.com/v1",
});
const response = await client.chat.completions.create({
model: "zai/glm-4",
messages: [{ role: "user", content: "Hello!" }],
});
console.log(response.choices[0].message.content);curl https://api.yuhuanstudio.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $YUNXIN_API_KEY" \
-d '{
"model": "zai/glm-4",
"messages": [{"role": "user", "content": "Hello!"}]
}'Multimodal content
Z.ai supports multiple content types within a Chat Completions message. Capabilities vary by model — check the Models API.
Images
{
"type": "image_url",
"image_url": {"url": "https://example.com/photo.jpg"}
}Documents
{
"type": "file_url",
"file_url": {"url": "https://example.com/document.pdf"}
}Thinking/reasoning
Enable extended reasoning for complex tasks:
response = client.chat.completions.create(
model="zai/glm-4",
messages=[{"role": "user", "content": "Solve this complex problem..."}],
extra_body={"thinking": {"type": "enabled"}}
)Function calling
response = client.chat.completions.create(
model="zai/glm-4",
messages=[{"role": "user", "content": "What's the weather?"}],
tools=[{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get current weather",
"parameters": {
"type": "object",
"properties": {"location": {"type": "string"}},
"required": ["location"]
}
}
}]
)Available models
Query the live catalog with the Models API:
curl "https://api.yuhuanstudio.com/v1/models?provider=zai" \
-H "Authorization: Bearer $YUNXIN_API_KEY"Capabilities and pricing are tracked per model. Use GET /v1/models?provider=zai and each model's capabilities array as the authoritative source rather than relying on a hardcoded list.
Official resources
How is this guide?