GLM-5.2 API setup: base URL, model id, first request.

Updated 2026-07-16

GLM-5.2 is addressable through any OpenAI-compatible client: point base_url at https://api.apisrouter.com/v1, set the model field to glm-5.2, and send a standard chat completions request. One key also covers glm-5.1, glm-5, DeepSeek, Claude, and GPT ids, so switching models is a string edit rather than a new vendor account.

Quick answer: two values and a key.

Every OpenAI-compatible SDK takes a base URL and an API key. Set the base URL to https://api.apisrouter.com/v1, set the model field to glm-5.2 exactly, and the request shape is the same /v1/chat/completions payload you would send to any other chat model. There is no GLM-specific SDK to install and no vendor account to create. The id matters more than it looks: glm-5.2, glm-5.1, and glm-5 are three separate models with three separate prices, and a typo falls through to a model-not-found error rather than a silent downgrade. Confirm the spelling against the /v1/models listing before wiring it into anything automated.

curl https://api.apisrouter.com/v1/chat/completions \
  -H "Authorization: Bearer $APISROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "glm-5.2",
    "messages": [{"role": "user", "content": "Summarize what a MoE model is in two sentences."}]
  }'

What GLM-5.2 actually is.

GLM-5.2 is Z.ai's mid-June 2026 release in the GLM-5 family, shipped to their coding-plan subscribers on June 13 and released publicly on June 16 with MIT-licensed open weights, per Z.ai's release notes and independent coverage. Launch reports put it at roughly 750 billion total parameters as a Mixture-of-Experts with about 40 billion active per token; the published figures vary slightly between 744B and 753B depending on the source, so treat the exact count as approximate. Z.ai positions the model at coding and long-horizon agent work, and its docs describe a 1M-token context upstream with up to 128K output tokens per response. Two behaviors are worth knowing before the first real workload. First, GLM-5.2 is a reasoning model with a thinking mode that Z.ai's API exposes as a toggle plus an effort setting; reasoning tokens bill as output, which the pricing page below covers in detail. Second, the catalog entry for glm-5.2 on APIsRouter lists a 200K context window, so budget prompts against 200K here rather than the upstream 1M figure.

Quickstart: Python and JavaScript with the OpenAI SDK.

Both official OpenAI SDKs accept a custom base URL at client construction, and nothing else about the call changes. The model field is passed through as a plain string, so the same client object can issue a glm-5.2 request on one line and a claude-sonnet-4-6 or deepseek-v4-pro request on the next. Keep the key in an environment variable rather than the source file, and pin the model id in one place (a constant or config entry) so an upgrade from glm-5.1 to glm-5.2 later is a single edit with a clean diff.

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["APISROUTER_API_KEY"],
    base_url="https://api.apisrouter.com/v1",
)

resp = client.chat.completions.create(
    model="glm-5.2",
    messages=[
        {"role": "system", "content": "You are a concise coding assistant."},
        {"role": "user", "content": "Write a Python function that deduplicates a list, preserving order."},
    ],
    max_tokens=2000,
)
print(resp.choices[0].message.content)
print(resp.usage)  # prompt_tokens / completion_tokens per request

Streaming responses.

GLM-5.2 supports streaming, and through an OpenAI-compatible endpoint it works the standard way: set stream to true and consume server-sent chunks as they arrive. For a reasoning model this matters more than usual, because the model may spend time thinking before the first visible token; a streaming UI shows the user something is happening, while a blocking call just looks slow. If you log costs per request, request usage on the stream where your SDK supports it (stream_options with include_usage in the OpenAI SDKs), or fall back to a non-streamed call for workloads where exact per-request token counts matter more than latency.

stream = client.chat.completions.create(
    model="glm-5.2",
    messages=[{"role": "user", "content": "Draft a README outline for a CLI tool."}],
    max_tokens=2000,
    stream=True,
)
for chunk in stream:
    delta = chunk.choices[0].delta.content if chunk.choices else None
    if delta:
        print(delta, end="", flush=True)

Tool calls: standard function calling.

Z.ai documents tool invocation as a core GLM-5.2 capability, and through the OpenAI-compatible surface it uses the standard tools array: declare each function with a JSON-schema parameter block, check the response for tool_calls, execute, and append the result as a tool-role message. Agent frameworks that speak the OpenAI function-calling protocol (LangChain, CrewAI, AutoGen and the rest) work without GLM-specific adapters for the same reason. One practical note for tool-heavy loops: GLM-5.2's reasoning happens before tool selection, so tool-call turns can bill more output tokens than the visible JSON suggests. Watch usage.completion_tokens across a full loop rather than judging cost from the tool-call payloads alone.

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

resp = client.chat.completions.create(
    model="glm-5.2",
    messages=[{"role": "user", "content": "Do I need an umbrella in Tokyo today?"}],
    tools=tools,
    max_tokens=2000,
)
print(resp.choices[0].message.tool_calls)

glm-5.2 vs glm-5.1 vs glm-5: which id to wire in.

Because every id sits behind the same endpoint, the comparison is an afternoon of A/B calls against your own prompts, not a migration. The usage log prices each candidate run for you.

  • glm-5.2 is the current top of the family: open-source state of the art on coding and long-horizon agent benchmarks per Z.ai, with the highest per-token price of the three. Default for coding agents and hard multi-step work.
  • glm-5.1 (April 2026) focused on long-horizon autonomy; Z.ai claims runs of up to 8 hours on a single task. A reasonable pick when 5.2 quality is more than the task needs.
  • glm-5 (February 2026) is the volume tier: the lowest price in the family and still a capable reasoning model for summarization, extraction, and batch jobs.
  • All three share the request shape, so the family is a natural downshift path: prototype on glm-5.2, then move the workloads that pass evals on glm-5 or glm-5.1 to their lower rates.

Pay-as-you-go · transparent per-model pricing

Selected models are priced below official list prices. Exact input, output, cache, and per-request prices are shown for each model.

ModelOfficial PriceOur Price
GLM-5.2$1.14 / $4.00 per M$1.03 / $3.60 per M
GLM-5.1$0.86 / $3.43 per M$0.77 / $3.09 per M
GLM-5$0.57 / $2.57 per M$0.51 / $2.31 per M
Claude Sonnet 4.6$3.00 / $15.00 per M$2.40 / $12.00 per M
GPT-5.5$5.00 / $30.00 per M$4.00 / $24.00 per M

Verify the endpoint and debug the first request.

Before anything else, list the models your key can address. The curl below returns every served id; glm-5.2 must appear in it, spelled exactly as you plan to send it. First-request failures follow a short list. A 401 means the key is wrong or was exported in a different shell than the one running your code. A 404 on the request path usually means the base URL is missing its /v1 suffix, since SDKs append /chat/completions to whatever base you give them. A model-not-found error is an id typo: the string is glm-5.2 with dots, not glm-52 or glm5.2. And a response that stops mid-answer with finish_reason=length means max_tokens was set too tight for a reasoning model; raise it before concluding anything about quality. Once requests flow, the APIsRouter console shows per-request model, token counts, and spend, which is the fastest way to see what GLM-5.2 costs on your real prompts rather than on assumptions.

curl -s https://api.apisrouter.com/v1/models \
  -H "Authorization: Bearer $APISROUTER_API_KEY" | grep glm

FAQ

What is the GLM-5.2 API base URL?

Through APIsRouter it is https://api.apisrouter.com/v1. Any OpenAI-compatible SDK accepts it as base_url (Python) or baseURL (JavaScript), and the endpoint serves glm-5.2 alongside the rest of the catalog under one key.

What is the exact GLM-5.2 model id?

glm-5.2, lowercase with dots. glm-5.1 and glm-5 are separate models at separate prices. The /v1/models listing on the endpoint is the authoritative spelling for every served id.

Does GLM-5.2 work with the OpenAI Python and Node SDKs?

Yes. Both SDKs take a custom base URL at client construction and pass the model field through as a plain string. Chat completions, streaming, and the standard tools array all work without a GLM-specific client.

Does GLM-5.2 support function calling and JSON output?

Yes. Z.ai documents tool invocation and structured JSON output as core capabilities, and through the OpenAI-compatible surface they use the standard tools array and response_format conventions that agent frameworks already speak.

What context window does GLM-5.2 have?

Z.ai's docs describe a 1M-token context upstream with up to 128K output tokens per response. The glm-5.2 catalog entry on APIsRouter lists a 200K context window, so budget prompts against 200K when calling it here.

Why do GLM-5.2 responses bill more output tokens than the visible answer?

GLM-5.2 is a reasoning model: it can spend part of the max_tokens budget on internal reasoning before the visible answer, and those tokens bill as output. Set max_tokens with headroom and check finish_reason; a length stop with little visible content is a truncated reasoning pass, not a short answer.