GLM-5.2 Fast Preview API
Low-latency chat completions from the GLM-5.2 weights on throughput-tuned serving — consistently faster than the standard tier, at twice the price and identical answer quality.
- Context window
- 1M tokens
- Max output
- 131.1K tokens
- Input
- $2.8 / 1M tokens
- Output
- $8.8 / 1M tokens
- Cached input
- $0.7 / 1M tokens
- Modalities
- text → text
- Features
- reasoningtool callingjson modestreaming
Connect to GLM-5.2 Fast Preview
GLM-5.2 Fast Preview is served through an OpenAI-compatible chat completions API. Point any OpenAI SDK or OpenAI-compatible tool at the base URL below with a ModelRunner API key — no polling, the reply comes back in the response (or streams).
- base_url
- https://queue.modelrunner.run/z-ai/glm-5.2-fast-preview
- model
- z-ai/glm-5.2-fast-preview
- auth
- Authorization: Bearer <MODELRUNNER_API_KEY>get a key
import os
from openai import OpenAI
client = OpenAI(
base_url="https://queue.modelrunner.run/z-ai/glm-5.2-fast-preview",
api_key=os.environ["MODELRUNNER_API_KEY"],
)
completion = client.chat.completions.create(
model="z-ai/glm-5.2-fast-preview",
messages=[
{
"role": "user",
"content": "Explain what an API rate limit is in two sentences."
}
],
reasoning_effort="medium", # low | medium | high — thinking bills as output tokens
)
print(completion.choices[0].message.content)
# Streaming: add stream=True and iterate the chunks
# for chunk in client.chat.completions.create(..., stream=True):
# print(chunk.choices[0].delta.content or "", end="")import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://queue.modelrunner.run/z-ai/glm-5.2-fast-preview",
apiKey: process.env.MODELRUNNER_API_KEY,
});
const completion = await client.chat.completions.create({
model: "z-ai/glm-5.2-fast-preview",
messages: [
{
"role": "user",
"content": "Explain what an API rate limit is in two sentences."
}
],
reasoning_effort: "medium", // low | medium | high — thinking bills as output tokens
});
const reply = completion.choices[0].message.content;
// Streaming: pass stream: true and iterate the chunks
// for await (const chunk of await client.chat.completions.create({ ..., stream: true })) {
// process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
// }# One synchronous call — the reply is in the response body (no polling)
curl https://queue.modelrunner.run/z-ai/glm-5.2-fast-preview/chat/completions \
-H "Authorization: Bearer $MODELRUNNER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"messages": [
{
"role": "user",
"content": "Explain what an API rate limit is in two sentences."
}
],
"reasoning_effort": "medium"
}'
# Streaming (Server-Sent Events, ends with "data: [DONE]")
curl -N https://queue.modelrunner.run/z-ai/glm-5.2-fast-preview/chat/completions \
-H "Authorization: Bearer $MODELRUNNER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"messages": [
{
"role": "user",
"content": "Explain what an API rate limit is in two sentences."
}
],
"reasoning_effort": "medium",
"stream": true
}'Works withCline · Continue · Claude Code · LangChain · Vercel AI SDK · LiteLLM · Aider
Cline → Settings → API Configuration (or the CLI line below)
API Provider: OpenAI Compatible
Base URL: https://queue.modelrunner.run/z-ai/glm-5.2-fast-preview
API Key: <your ModelRunner API key>
Model ID: z-ai/glm-5.2-fast-preview
# Cline CLI equivalent
cline auth --provider openai --baseurl https://queue.modelrunner.run/z-ai/glm-5.2-fast-preview --modelid z-ai/glm-5.2-fast-preview --apikey <your ModelRunner API key>~/.continue/config.yaml (the IDE extension and the `cn` CLI read the same file)
models:
- name: GLM-5.2 Fast Preview (ModelRunner)
provider: openai
model: z-ai/glm-5.2-fast-preview
apiBase: https://queue.modelrunner.run/z-ai/glm-5.2-fast-preview
apiKey: <your ModelRunner API key>
roles: [chat, edit]shell environment (or the env block of ~/.claude/settings.json)
export ANTHROPIC_BASE_URL=https://queue.modelrunner.run/z-ai/glm-5.2-fast-preview
export ANTHROPIC_AUTH_TOKEN=<your ModelRunner API key>
export ANTHROPIC_MODEL=z-ai/glm-5.2-fast-preview
# optional: send Claude Code's background/sub-agent calls to the same model
export ANTHROPIC_DEFAULT_HAIKU_MODEL=z-ai/glm-5.2-fast-preview
export CLAUDE_CODE_SUBAGENT_MODEL=z-ai/glm-5.2-fast-preview
claudeimport os
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
base_url="https://queue.modelrunner.run/z-ai/glm-5.2-fast-preview",
api_key=os.environ["MODELRUNNER_API_KEY"],
model="z-ai/glm-5.2-fast-preview",
)
llm.invoke("Explain what an API rate limit is in two sentences.")import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
import { generateText } from "ai";
const modelrunner = createOpenAICompatible({
name: "modelrunner",
baseURL: "https://queue.modelrunner.run/z-ai/glm-5.2-fast-preview",
apiKey: process.env.MODELRUNNER_API_KEY,
});
const { text } = await generateText({
model: modelrunner("z-ai/glm-5.2-fast-preview"),
prompt: "Explain what an API rate limit is in two sentences.",
});import os
import litellm
response = litellm.completion(
model="openai/z-ai/glm-5.2-fast-preview", # "openai/" = OpenAI-compatible route
api_base="https://queue.modelrunner.run/z-ai/glm-5.2-fast-preview",
api_key=os.environ["MODELRUNNER_API_KEY"],
messages=[{"role": "user", "content": "Explain what an API rate limit is in two sentences."}],
)
print(response.choices[0].message.content)terminal
export OPENAI_API_BASE=https://queue.modelrunner.run/z-ai/glm-5.2-fast-preview
export OPENAI_API_KEY=<your ModelRunner API key>
aider --model openai/z-ai/glm-5.2-fast-previewStreaming via SSE (stream: true; ends with data: [DONE]) · Non-streaming calls time out at ~290 s — stream long generations · 10 MB request body · Errors use the OpenAI error envelope · Optional metadata object for your own tags, never sent to the model · Many models, one provider entry: base_url https://queue.modelrunner.run/v1 (GET /v1/models lists ids; model field required)
From an MCP client (Claude Desktop, Cursor, Claude Code): connect the ModelRunner MCP server once and its run_model tool runs GLM-5.2 Fast Preview with a messages input — the reply comes back in the same call.
Machine-readable: OpenAPI schema · llms.txt
Example conversation
A real run of GLM-5.2 Fast Preview on ModelRunner · charged $0.0177 · 130 in / 1,972 out / 1,261 reasoning tokens
Here are the bugs in the provided function:
### Bug 1: Ties are not broken alphabetically **Why it's wrong:** The sorting key `lambda kv: -kv[1]` only sorts the words by their frequency in descending order. Python's `sorted` function is stable, meaning that if two words have the same frequency, they will retain their original relative order (which is the order they were inserted into the dictionary), not alphabetical order. **Fix:** Change the sorting key to a tuple: `lambda kv: (-kv[1], kv[0])`. This sorts by frequency descending (`-kv[1]`), and for ties, it sorts by the word alphabetically ascending (`kv[0]`).
### Bug 2: Punctuation is not stripped **Why it's wrong:** The function uses `text.lower().split()`, which splits the text by whitespace but leaves punctuation attached to the words. For example, the word `"apple"` and `"apple!"` will be treated as two completely different words, resulting in incorrect frequency counts. **Fix:** Use a regular expression like `re.findall(r'\w+', text.lower())` to extract only the alphanumeric words, ignoring punctuation.
### Bug 3 (Edge Case): No handling for negative `k` **Why it's wrong:** If `k` is negative, `ranked[:k]` behaves unexpectedly in Python (it returns all items except the last `k` items). A top-k function should ideally just return an empty list if `k <= 0`. **Fix:** Add an early return `if k <= 0: return []`.
### Corrected Version
```python import re
def top_k_words(text, k): if k <= 0: return [] # Extract words (alphanumeric sequences) and convert to lowercase words = re.findall(r'\w+', text.lower()) # Count frequencies counts = {} for w in words: counts[w] = counts.get(w, 0) + 1 # Sort by frequency (descending) and alphabetically (ascending) for ties ranked = sorted(counts.items(), key=lambda kv: (-kv[1], kv[0])) return [w for w, _ in ranked[:k]] ```
### Complexity Let \(N\) be the number of words in the text, and \(U\) be the number of unique words (so \(U \le N\)).
**Time Complexity:** - Finding words and counting: \(O(N)\) - Sorting the unique words: \(O(U \log U)\) - Slicing the list: \(O(k)\) Overall Time Complexity: **\(O(N + U \log U)\)**
*(Note: If we wanted to optimize the time complexity strictly for \(k\), we could use a min-heap of size \(k\) via `heapq.nlargest`, which would reduce the time complexity to \(O(N + U \log k)\). However, the standard `sorted` approach is cleaner and usually sufficient unless \(U\) is massive).*
**Space Complexity:** - The `counts` dictionary takes \(O(U)\) space. - The `ranked` list takes \(O(U)\) space. Overall Space Complexity: **\(O(U)\)** (or \(O(N)\) in the worst case where every word is unique).
Model Pricing
Pricing
This model is billed per token, at separate rates for what you send and what it produces.
If a run reports no token usage, it bills a flat $0.04.
Real run: the example conversation above was charged $0.0177 for 130 input and 1,972 output tokens (of which 1,261 thinking).
Cost estimator
Estimate from the rates above — your bill is the model's reported usage × rate, exact to 6 decimals.
This model thinks before it answers. Thinking tokens bill at the output rate and are often several times the visible reply — count them in the output figure, or set a lower reasoning effort.
Compare tiers and related models
| Model | Input / 1M | Output / 1M | Context | Max output | Features |
|---|---|---|---|---|---|
| GLM-5.2 Fast Previewz-ai/glm-5.2-fast-preview | $2.8 | $8.8 | 1M | 131.1K | reasoning, tool calling, json mode |
| GLM-5.2z-ai/glm-5.2 | $1.4 | $4.4 | 1M | 131.1K | reasoning, tool calling, json mode |
| DeepSeek V4 Prodeepseek/v4 | $2.4 | $4.8 | 1M | 393.2K | reasoning, tool calling, json mode |
| Gemini 3.5 Flashgoogle/gemini-3.5-flash | $1.5 | $9 | 1M | 65.5K | reasoning, tool calling, json mode |
| Gemini 3.5 Flash-Litegoogle/gemini-3.5-flash-lite | $0.3 | $2.5 | 1M | 65.5K | tool calling, json mode |
| Gemini 3.7 Flashgoogle/gemini-3.7-flash | $0.75 | $3.75 | 1M | 65.5K | reasoning, tool calling, json mode |
| Qwen3.8-Maxalibaba/qwen3.8-max | $2 | $6 | 1M | 131.1K | reasoning, tool calling, json mode |
Request parameters
The body follows OpenAI’s chat completions shape. Fields below are the ones this model documents; anything else the platform does not interpret is forwarded to the model unchanged, and the model is the authority on what it accepts.
| Name | Type | Required | Description |
|---|---|---|---|
| messages | array | yes | OpenAI-style conversation history. Each item is an object with a role (system, user, assistant or tool) and content. |
| stream | boolean | no | Return the reply as a Server-Sent Events stream of deltas terminated by data: [DONE]. Default: false. |
| reasoning_effort | enum | no | How hard the model thinks before answering, across seven levels. Defaults to max, the highest — lower it to cut cost, because thinking tokens bill as output tokens. none disables reasoning entirely. One of: none, minimal, low, medium, high, xhigh, max. Default: "max". |
| max_tokens | integer | no | Upper bound on generated tokens, up to the family's published 131,072-token output ceiling. Thinking consumes this budget, so allow generous headroom. |
| tools | array | no | OpenAI-format tool definitions the model may call. |
| tool_choice | — | no | auto, none, required, or a specific tool. |
| response_format | object | no | Structured-output control. Set its type to json_object to force a JSON reply. Structured output is supported in non-thinking mode only, so pair it with reasoning_effort set to none. |
| stop | — | no | Up to 4 stop sequences. |
| seed | integer | no | Best-effort determinism hint. |
Response
An OpenAI ChatCompletion object: id, object, created, model, choices[] and usage. Cache hits surface at usage.prompt_tokens_details.cached_tokens; thinking, where the model reports it, at usage.completion_tokens_details.reasoning_tokens — thinking tokens are billed as output tokens. The id is chatcmpl-<requestId>, and the same request appears in your dashboard.
About GLM-5.2 Fast Preview
GLM-5.2 Fast Preview runs the GLM-5.2 weights on higher-throughput infrastructure for latency-sensitive work. In back-to-back testing it ran **consistently faster than the standard tier, by roughly 20–30%** — a steady gain, not a step change, and it varies with load. You send `messages`, you get a chat completion.
Best for
- Low-latency coding assistant: fast inline completions while a developer waits
- Speed up an agent loop that makes many sequential model calls
- Real-time streaming chat where response time matters more than token cost
- Agentic coding: multi-step bug fixing and refactoring at high throughput
- Long-context code review across an entire repository in one prompt
How it thinks
GLM-5.2 Fast Preview reasons before it answers. Set reasoning_effort to none, minimal, low, medium, high, xhigh or max (default max) to trade answer quality against latency and cost. Thinking tokens are billed at the output rate and reported as usage.completion_tokens_details.reasoning_tokens.
Notesshow the full description ›
**This is the more expensive tier, not the cheaper one.** It bills **twice** the standard `z-ai/glm-5.2` row per token — same weights, same answers, so you pay double for about a quarter more throughput. Worth it only when wall-clock latency is your binding constraint; otherwise use `z-ai/glm-5.2`.
Quality is GLM-5.2's own: the brand publishes **62.1 on SWE-Bench Pro** and **81.0 on Terminal-Bench 2.1** for these open-weight, MIT-licensed weights. Those are the model's published results, not a measurement of this serving tier.
Thinking is tunable through `reasoning_effort` across **seven** levels — `none`, `minimal`, `low`, `medium`, `high`, `xhigh`, `max` — with **`max` as the default**, the strongest and most expensive, since thinking bills as output. The context window is 1M tokens and a single reply can run to 131,072 tokens.
## Choose another model when - Cost matters more than speed — `z-ai/glm-5.2` runs the same weights for the same answers at half the token price - You need the family's most stable id — this one is a preview, with capabilities and specifications subject to change - Your input includes images, audio or video — this is a text-only model - A single reply has to exceed 131,072 tokens, which thinking also counts against
## Tips - Structured output works in non-thinking mode only — pair `response_format` with `reasoning_effort: "none"` - Budget `max_tokens` generously — at `max` effort most of it goes to thinking, and too small a budget returns an empty reply you still pay for
Behaviour & limits
- Context window
- 1M tokens (input + output)
- Max output
- 131.1K tokens per reply — thinking counts against this budget
- Structured calls
- OpenAI-format tools + tool_choice · response_format JSON mode
- Transport
- OpenAI-compatible chat completions · SSE streaming · ~290 s non-stream ceiling · 10 MB body
- License
- License termsOpen weights
FAQ
How do I connect to GLM-5.2 Fast Preview through the API?
GLM-5.2 Fast Preview is served by an OpenAI-compatible chat completions endpoint. Point any OpenAI SDK or OpenAI-compatible tool at base_url https://queue.modelrunner.run/z-ai/glm-5.2-fast-preview with a ModelRunner API key (Authorization: Bearer <key>) and model z-ai/glm-5.2-fast-preview; the SDK appends /chat/completions itself. The call is synchronous — the reply comes back in the response body, or streams as Server-Sent Events with "stream": true. Do not submit it to the asynchronous queue path, which returns HTTP 400 for this model.
How much does GLM-5.2 Fast Preview cost?
GLM-5.2 Fast Preview is billed per token from the usage the model reports: $2.8 per 1M input tokens, $0.7 per 1M cached input tokens, $8.8 per 1M output tokens. Thinking (reasoning) tokens bill at the output rate. There is no per-request minimum — a short call bills a fraction of a cent, exact to six decimals.
What is GLM-5.2 Fast Preview's context window?
GLM-5.2 Fast Preview supports a 1M-token context window and up to 131.1K output tokens per reply — thinking tokens count against the output budget, so leave headroom in max_tokens.
Can I use GLM-5.2 Fast Preview in GitHub Copilot or another tool that requires a /models endpoint?
Yes. Custom-provider flows that probe GET {base_url}/models before first use (GitHub Copilot's BYOK flow does) work with either base URL: https://queue.modelrunner.run/z-ai/glm-5.2-fast-preview self-describes at https://queue.modelrunner.run/z-ai/glm-5.2-fast-preview/models, and the platform base https://queue.modelrunner.run/v1 covers every public chat model with one provider entry — GET /v1/models lists the ids and the request's model field selects z-ai/glm-5.2-fast-preview.
Does GLM-5.2 Fast Preview support streaming?
Yes. Set "stream": true and the reply arrives as Server-Sent Events (data: frames ending with data: [DONE]); stream_options: {"include_usage": true} adds a final usage frame. Non-streaming calls are cut off at about 290 seconds, so stream long generations.
Does GLM-5.2 Fast Preview support tool calling or JSON mode?
GLM-5.2 Fast Preview supports function calling via an OpenAI-format tools array with tool_choice and JSON mode via response_format {"type": "json_object"}. Both are passed through to the model in the standard OpenAI chat completions shape, so existing client code works unchanged.
What happens if my ModelRunner balance runs out while calling GLM-5.2 Fast Preview?
The request is refused with HTTP 429 and an OpenAI-style error whose code is insufficient_quota — the convention OpenAI SDKs already understand — and nothing is charged. Top up in the dashboard and retry. (Disconnecting from a stream after output has started is not a refund — the platform finishes the upstream call and bills its exact usage.)
