← All articles

Zhipu GLM API: The Complete Guide for AI Engineers (2026)

Everything you need to start building with Zhipu's GLM model family — signup, API key, first call in 3 minutes. We cover GLM-5.1, GLM-5, GLM-4.7, vision models, specialty models like GLM-OCR, pricing across BigModel and Z.AI, common errors, and how to route GLM as a primary or fallback provider.

· TheRouter

The Zhipu GLM API is an OpenAI-compatible endpoint that gives you access to one of the largest Chinese AI model families — from GLM-5.1, their latest flagship with 8-hour agentic coding sessions, down to free-tier models like GLM-4.7-Flash. Zhipu (智谱) operates two platforms: BigModel for Chinese developers and Z.AI for international access. Both expose the same models through an OpenAI-compatible chat completions interface: point your existing OpenAI SDK at the right base URL, swap the API key, and your code works.

We wrote this guide because Zhipu now has 78 model routes in our system — 66 via the BigModel provider and 12 via the Z.AI international provider — making it the largest Chinese AI provider by route count. The model lineup spans text, vision, OCR, image generation, video generation, TTS, embeddings, and web search. Navigating three access paths (BigModel direct, Z.AI international, and DashScope-hosted) with different model IDs and pricing tiers can be confusing. This is the single reference we wished we had when we first integrated the full Zhipu lineup.

Getting Started in 3 Minutes

Step 1: Create an account. For the China-region platform, go to open.bigmodel.cn and register with a Chinese phone number. For international access, go to z.ai and sign up with email.

Step 2: Get your API key. On BigModel, navigate to API Keys in the developer console and create one. On Z.AI, go to z.ai/manage-apikey to generate your key. Copy it immediately — keys are shown once.

Step 3: Make your first call. Install the OpenAI Python SDK:

pip install --upgrade openai

Then call GLM-5.1 via the BigModel endpoint:

from openai import OpenAI

client = OpenAI(
    api_key="YOUR_ZHIPU_KEY",
    base_url="https://open.bigmodel.cn/api/paas/v4",
)

response = client.chat.completions.create(
    model="glm-5.1",
    messages=[{"role": "user", "content": "What is Zhipu's GLM model family?"}],
)

print(response.choices[0].message.content)

Or via the Z.AI international endpoint:

client = OpenAI(
    api_key="YOUR_ZAI_KEY",
    base_url="https://api.z.ai/v1",
)

response = client.chat.completions.create(
    model="GLM-5.1",
    messages=[{"role": "user", "content": "Explain GLM-5.1 capabilities."}],
)

That's it. Both platforms offer free credits on registration and provide free-tier models (GLM-4.7-Flash, GLM-4.5-Flash) that require no payment to use.

OpenAI-compatible means a provider exposes a chat-completions endpoint whose request and response shape matches the OpenAI API contract closely enough that an unmodified OpenAI SDK call works against it after swapping three values: API key, base URL, and model name. The minimum surface in practice is POST /v1/chat/completions with messages, model, and an OpenAI-shaped streaming response.

The GLM Model Family

Zhipu's model lineup has grown into a full-stack offering. Here's the current state as of June 2026:

Flagship Text Models

ModelModel IDContextMax OutputBest For
GLM-5.1glm-5.1200K128KLong-horizon agentic coding, 8-hour autonomous tasks
GLM-5glm-5200K128KHigh-intelligence base, agentic planning and execution
GLM-5-Turboglm-5-turbo200K128KOptimized sequential task execution, lower latency
GLM-4.7glm-4.7200K128KStrong general reasoning, interleaved thinking
GLM-4.6glm-4.6200K128KMid-range performance, advanced coding and tool calls
GLM-4.5-Airglm-4.5-air128K96KCost-efficient reasoning, coding, and agent tasks

Source: Zhipu model overview, retrieved 2026-06-14.

Free-Tier Models

Zhipu offers several models with zero per-token cost:

  • GLM-4.7-Flash — Latest base model, universal version, 200K context
  • GLM-4.5-Flash — Supports deep thinking mode, 128K context (being phased out)
  • GLM-4-Flash-250414 — Multi-language support with tool calls, 128K context
  • GLM-4V-Flash — Free vision understanding, 16K context

Source: BigModel pricing page, retrieved 2026-06-14.

Vision Models

ModelModel IDContextMax OutputBest For
GLM-5V-Turboglm-5v-turbo200K128KMultimodal coding, visual reasoning + agent workflows
GLM-4.6Vglm-4.6v128K32KVisual reasoning, tool calling, frontend code replication
GLM-OCRglm-ocr65K—Document parsing (PDF/image to structured Markdown)
GLM-4.1V-Thinking-FlashXglm-4.1v-thinking-flashx64K16KLightweight visual reasoning with high concurrency

Source: Zhipu model overview, retrieved 2026-06-14.

Specialty Models

Beyond text and vision, Zhipu provides:

  • Image generation: GLM-Image (flagship, text rendering SOTA for Chinese characters), CogView-4 (diverse styles), CogView-3-Flash (free)
  • Video generation: CogVideoX-3 (high-quality with first/last frame control), Vidu2 (fast, cost-efficient), Vidu Q1 (cinema-grade quality)
  • Audio: GLM-TTS (speech synthesis), GLM-TTS-Clone (voice cloning from 3s audio), GLM-ASR (speech recognition), GLM-Realtime (real-time audio/video chat), GLM-4-Voice (spoken dialogue)
  • Embeddings: Embedding-3 (v3, 8K context), Embedding-2 (v2, 8K context)
  • Web search: Search-Pro (optimized for LLM use), Search-Std (standard)

Source: Zhipu model overview, retrieved 2026-06-14.

GLM-5.1 and the HighSpeed Variant

GLM-5.1, released April 7, 2026, is Zhipu's latest flagship. It's a 744B-parameter MoE model (40B active) released under the MIT license. The standout feature is sustained long-horizon agentic execution — the model can autonomously work for up to 8 hours on a single task, handling planning, execution, and iterative optimization.

Key benchmarks (as reported by Zhipu):

  • SWE-Bench Pro: 58.4% (SOTA at launch among open-source models)
  • NL2Repo: 42.7% (repository generation)
  • Terminal-Bench 2.0: 63.5%
  • CyberGym: 68.7% (cybersecurity tasks)

Source: GLM-5.1 developer guide, retrieved 2026-06-14; Zhipu official docs, retrieved 2026-06-14.

On May 22, 2026, Zhipu launched GLM-5.1-HighSpeed — a variant achieving 400 tokens/second output speed, the fastest among major API providers at the time. The optimization spans the inference engine (TileRT), scheduling system, and underlying infrastructure. This variant is currently available to enterprise customers.

Source: Securities Times report on GLM-5.1-HighSpeed, retrieved 2026-06-14.

Three Access Paths

One of the more confusing aspects of GLM is that you can reach the same models through three different providers, each with slightly different model IDs and pricing:

1. BigModel Direct (open.bigmodel.cn)

The first-party platform from Zhipu. Widest model selection, most up-to-date releases.

  • Base URL: https://open.bigmodel.cn/api/paas/v4
  • Model IDs: lowercase without prefix — glm-5.1, glm-4.7, glm-ocr
  • Pricing: CNY per million tokens. GLM-5.1 starts at ¥6/M input, ¥24/M output (currently free as a promotional offer). GLM-4.7 at ¥0.96/M input
  • Free tier: GLM-4.7-Flash, GLM-4.5-Flash, GLM-4V-Flash, CogView-3-Flash, CogVideoX-Flash

2. Z.AI International (api.z.ai)

Zhipu's international platform. Same core models, USD pricing, accessible without a Chinese phone number.

  • Base URL: https://api.z.ai/v1
  • Model IDs: capitalized — GLM-5.1, GLM-4.7, GLM-5
  • Pricing: USD per million tokens. GLM-5 at ~$0.60/M input, $1.92/M output. GLM-4.7 at ~$1.01/M input
  • Coding Plan: Subscription tiers ($18–$200/month) with quota-based access to GLM-5.2, GLM-5-Turbo, GLM-4.7

Source: Z.AI developer docs, retrieved 2026-06-14; BigModel pricing, retrieved 2026-06-14.

3. DashScope-Hosted (via Aliyun Bailian)

Alibaba's Bailian platform hosts GLM models alongside Qwen. Useful if you already have an Aliyun account and want unified billing.

  • Base URL: https://dashscope.aliyuncs.com/compatible-mode/v1
  • Model IDs: lowercase — glm-4-plus, glm-4-flash, glm-4-long
  • Note: DashScope hosts a subset of GLM models (primarily GLM-4 series). Each model comes with 1 million free tokens.

Source: DashScope GLM integration docs, retrieved 2026-06-14.

Code Examples

Streaming with Tool Use

from openai import OpenAI

client = OpenAI(
    api_key="YOUR_ZHIPU_KEY",
    base_url="https://open.bigmodel.cn/api/paas/v4",
)

tools = [
    {
        "type": "function",
        "function": {
            "name": "get_weather",
            "description": "Get current weather for a location",
            "parameters": {
                "type": "object",
                "properties": {
                    "location": {"type": "string", "description": "City name"},
                },
                "required": ["location"],
            },
        },
    }
]

stream = client.chat.completions.create(
    model="glm-4.7",
    messages=[{"role": "user", "content": "What's the weather in Beijing?"}],
    tools=tools,
    stream=True,
)

for chunk in stream:
    delta = chunk.choices[0].delta
    if delta.content:
        print(delta.content, end="")
    if delta.tool_calls:
        for tc in delta.tool_calls:
            print(f"\nTool call: {tc.function.name}({tc.function.arguments})")

curl Example

curl https://open.bigmodel.cn/api/paas/v4/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_ZHIPU_KEY" \
  -d '{
    "model": "glm-5.1",
    "messages": [{"role": "user", "content": "Hello from GLM-5.1"}],
    "max_tokens": 1024
  }'

Vision Model Example

response = client.chat.completions.create(
    model="glm-4.6v",
    messages=[
        {
            "role": "user",
            "content": [
                {"type": "text", "text": "What's in this image?"},
                {
                    "type": "image_url",
                    "image_url": {"url": "https://example.com/photo.jpg"},
                },
            ],
        }
    ],
)

Pricing at a Glance

Prices on BigModel are in CNY per million tokens (1M = 1,000,000 tokens):

ModelInput (¥/M)Output (¥/M)Notes
GLM-5.1624Currently free (promotional)
GLM-5522—
GLM-5-Turbo522Optimized for sequential tasks
GLM-4.70.963.48Strong value for general use
GLM-4.60.3361.68Mid-range
GLM-4.5-Air0.181.44Budget option
GLM-4.7-FlashFreeFreeUniversal free tier
GLM-OCR0.0480.048Document parsing

Source: BigModel pricing page, retrieved 2026-06-14.

Z.AI international pricing is in USD. GLM-5 runs approximately $0.60/M input, $1.92/M output. GLM-4.7 runs approximately $1.01/M input, $4.70/M output. The Z.AI Coding Plan starts at $18/month for quota-based access including GLM-5.2 and GLM-4.7.

Source: Z.AI developer docs, retrieved 2026-06-14; PricePerToken GLM-5 listing, retrieved 2026-06-14.

Common Errors and Fixes

Model ID Mismatch Across Providers

The most common integration error: each platform uses different model ID formats.

PlatformGLM-5.1 IDGLM-4.7 IDGLM-5 ID
BigModelglm-5.1glm-4.7glm-5
Z.AIGLM-5.1GLM-4.7GLM-5
DashScopeNot availableNot availableNot available

Fix: Normalize model IDs per provider. When routing through TheRouter, use the prefixed format: zhipu/glm-5.1 for BigModel routes or zai/glm-5.1 for Z.AI routes.

Rate Limiting

BigModel returns HTTP 429 when you exceed your quota. Free-tier models have lower concurrency limits than paid tiers. The Z.AI Coding Plan uses a 5-hour rolling window with per-plan prompt limits (80–1,600 prompts per window).

Fix: Implement exponential backoff. For sustained workloads, consider the Z.AI Coding Plan or BigModel enterprise tiers.

Context Length Exceeded

GLM-5.1 and GLM-5 support 200K tokens of context. GLM-4.5-Air supports 128K. GLM-4-Long supports up to 1M tokens but with only 4K max output — it's designed for long-document comprehension, not generation.

Fix: Match your model to your context needs. For long-document Q&A, use GLM-4-Long. For long-generation tasks, use GLM-5.1 (128K output cap).

Authentication Format

BigModel uses Bearer token authentication. Z.AI uses the same format. DashScope-hosted GLM uses the DashScope API key format.

# BigModel / Z.AI
Authorization: Bearer sk-xxxx

# DashScope
Authorization: Bearer sk-xxxx  # same format, different key

Routing GLM Models with TheRouter

We route 78 GLM model variants — 66 via the zhipu provider and 12 via the zai provider. TheRouter supports OpenAI-compatible routing and fallback when configured for these providers.

When you send a request to TheRouter with a zhipu/ prefixed model ID, we route it to the BigModel endpoint. For zai/ prefixed models, we route to the Z.AI international endpoint. This means you can set up fallback chains that span both platforms:

# Route through TheRouter with zhipu provider
from openai import OpenAI

client = OpenAI(
    api_key="YOUR_THEROUTER_KEY",
    base_url="https://therouter.ai/api/v1",
)

response = client.chat.completions.create(
    model="zhipu/glm-5.1",
    messages=[{"role": "user", "content": "Explain quantum computing."}],
)

Available model routes include text models (GLM-5.1, GLM-5, GLM-4.7), vision models (GLM-5V-Turbo, GLM-4.6V), document parsing (GLM-OCR), embeddings (Embedding-3), image generation (CogView-4, GLM-Image), and video generation (CogVideoX-3).

Production Checklist

Before going live with GLM models:

  • Pick your access path. BigModel for China-region, Z.AI for international, DashScope if you need unified Aliyun billing. Each has different model availability and pricing.
  • Test model ID mapping. Verify the exact model ID string for your chosen platform — they differ between BigModel, Z.AI, and DashScope.
  • Set up rate-limit handling. Implement exponential backoff for 429 responses. Monitor your quota on the platform dashboard.
  • Configure fallback. Consider routing through TheRouter to set up automatic fallback between Zhipu and other providers.
  • Validate output format. GLM models support response_format: { type: "json_object" } — test that structured output works for your use case.
  • Check context limits. Match your model to your context needs. GLM-5.1 supports 200K input / 128K output. GLM-4-Long supports 1M input / 4K output.
  • Monitor costs. Free-tier models (GLM-4.7-Flash) are good for development. Switch to paid models (GLM-5.1, GLM-4.7) for production workloads that need higher quality or throughput.
  • Test tool calling. GLM-4.6+ supports function calling via the tools parameter. Verify tool call streaming works for your agent framework.

Sources cited in this article:

Help & contact