Skip to main content
z-ai avatar

GLM-5.2 API

z-ai/glm-5.2

Open-weight (MIT) thinking model for agentic coding and long-horizon reasoning, with a 1M-token context, seven levels of thinking effort, tool calling and streaming over an OpenAI-compatible chat endpoint.

reasoningtool callingjson mode
$1.4 in · $4.4 out per 1M tokens
1M context
131.1K max output

Chat with this model

Chat

Try this model — replies stream in live.
You need to be logged in to run this model and view results.
Log in

Model Pricing

Pricing

This model is billed per token, at separate rates for what you send and what it produces.

Input tokens
$1.4
per 1M tokens
Cached input tokens
$0.35
per 1M tokens
Output tokens
$4.4
per 1M tokens

Every request rounds up to the nearest $0.01.

If a run reports no token usage, it bills a flat $0.02.

GLM-5.2 API

GLM-5.2 is a text-to-text AI model by z-ai. On ModelRunner it runs through a REST API or via MCP from any AI assistant with pay-per-use pricing.

POST https://queue.modelrunner.run/z-ai/glm-5.2

cURL

# Submit a request to the queue. Input fields go at the top level of the
# body. The optional reserved "metadata" object holds your own flat string
# tags — stored on the request, never sent to the model; filter later with
# GET https://queue.modelrunner.run/requests?metadata=<url-encoded JSON>.
curl -X POST https://queue.modelrunner.run/z-ai/glm-5.2 \
  -H "Authorization: Key $MRUN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "z-ai/glm-5.2",
    "messages": [
      {
        "role": "user",
        "content": "Find every bug in this function, explain each one, then give a corrected version with its time and space complexity.\n\ndef merge_intervals(intervals):\n    intervals.sort()\n    merged = [intervals[0]]\n    for start, end in intervals[1:]:\n        if start < merged[-1][1]:\n            merged[-1][1] = end\n        else:\n            merged.append([start, end])\n    return merged"
      }
    ],
    "max_tokens": 8000,
    "reasoning_effort": "high",
    "metadata": {
      "project": "my-project"
    }
  }'
# → { "request_id": "...", "status_url": "...", "response_url": "..." }

# Poll status_url until "COMPLETED", then fetch the result
curl "https://queue.modelrunner.run/z-ai/glm-5.2/requests/$REQUEST_ID/status" \
  -H "Authorization: Key $MRUN_API_KEY"
curl "https://queue.modelrunner.run/z-ai/glm-5.2/requests/$REQUEST_ID" \
  -H "Authorization: Key $MRUN_API_KEY"

JavaScript

import { modelrunner } from "@modelrunner/client";

const result = await modelrunner.subscribe("z-ai/glm-5.2", {
  input: {
    "model": "z-ai/glm-5.2",
    "messages": [
      {
        "role": "user",
        "content": "Find every bug in this function, explain each one, then give a corrected version with its time and space complexity.\n\ndef merge_intervals(intervals):\n    intervals.sort()\n    merged = [intervals[0]]\n    for start, end in intervals[1:]:\n        if start < merged[-1][1]:\n            merged[-1][1] = end\n        else:\n            merged.append([start, end])\n    return merged"
      }
    ],
    "max_tokens": 8000,
    "reasoning_effort": "high"
  },
});
console.log(result);

Python

import os
import requests

headers = {"Authorization": f"Key {os.environ['MRUN_API_KEY']}"}

submitted = requests.post(
    "https://queue.modelrunner.run/z-ai/glm-5.2",
    headers=headers,
    json={
      "model": "z-ai/glm-5.2",
      "messages": [
        {
          "role": "user",
          "content": "Find every bug in this function, explain each one, then give a corrected version with its time and space complexity.\n\ndef merge_intervals(intervals):\n    intervals.sort()\n    merged = [intervals[0]]\n    for start, end in intervals[1:]:\n        if start < merged[-1][1]:\n            merged[-1][1] = end\n        else:\n            merged.append([start, end])\n    return merged"
        }
      ],
      "max_tokens": 8000,
      "reasoning_effort": "high"
    },
).json()

# Poll submitted["status_url"] until "COMPLETED", then:
result = requests.get(submitted["response_url"], headers=headers).json()

Input parameters

NameTypeRequiredDescription
messagesarrayyesOpenAI-style conversation history. Each item is an object with a `role` (`system`, `user`, `assistant` or `tool`) and `content`.
streambooleannoReturn the reply as a Server-Sent Events stream of deltas terminated by `data: [DONE]`. Default: false.
reasoning_effortenumnoHow 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. Default: "max".
max_tokensintegernoUpper bound on generated tokens, up to the documented 131,072-token output ceiling. Thinking consumes this budget, so allow generous headroom.
toolsarraynoOpenAI-format tool definitions the model may call.
tool_choiceno`auto`, `none`, `required`, or a specific tool.
response_formatobjectnoStructured-output control. Set its `type` to `json_object` to force a JSON reply.
stopnoUp to 4 stop sequences.
seedintegernoBest-effort determinism hint.

Machine-readable: OpenAPI schema · llms.txt

Use GLM-5.2 from Claude & Cursor (MCP)

Point Claude Code, Claude Desktop, Cursor, or any MCP client at the ModelRunner MCP server and GLM-5.2 becomes a tool your assistant can call directly — it authorizes via OAuth (no API key in config) and runs this model with the run_model tool using the endpoint z-ai/glm-5.2.

MCP client config (Claude Desktop, Cursor)

{
  "mcpServers": {
    "modelrunner": {
      "command": "npx",
      "args": ["-y", "mcp-remote", "https://mcp.modelrunner.run/mcp"]
    }
  }
}

Claude Code

claude mcp add --transport http modelrunner https://mcp.modelrunner.run/mcp

Then ask your assistant, for example: “Run z-ai/glm-5.2 on ModelRunner to generate text”. MCP setup guide.

Model Details

Model Details

GLM-5.2 is an open-weight **thinking model**, MIT-licensed, built for agentic engineering. It reasons internally before answering, and the brand publishes results close to the closed frontier on long-horizon coding work: **62.1 on SWE-Bench Pro** and **81.0 on Terminal-Bench 2.1**, plus second place across FrontierSWE, PostTrainBench and SWE-Marathon and the highest-ranked open-source model on all three. You send `messages`, you get a chat completion.

Thinking is tunable through `reasoning_effort` across **seven** levels — `none`, `minimal`, `low`, `medium`, `high`, `xhigh`, `max` — a wider range than the usual three. **The default is `max`, the most expensive setting**: it gives the strongest answers and the largest bill, because thinking tokens are billed as output tokens. Drop to `low` or `medium` for routine work; `none` turns reasoning off entirely and returns zero reasoning tokens. It also accepts its own `enable_thinking: false` switch, which overrides `reasoning_effort` — unknown fields are forwarded verbatim — but prefer `reasoning_effort` alone, since the two overlap. A live call also returned the chain of thought in a `message.reasoning_content` field beside `content` — observed behaviour, not a documented guarantee.

The context window is 1M tokens and a single reply can run to 131,072 tokens; the brand describes the context as stably sustaining long-horizon work — large-scale implementation, automated research, performance optimisation and complex debugging.

## Best for - Multi-step bug hunting and refactoring where the model has to plan, edit and re-check its own work - Terminal- and tool-driven agent loops that call functions reliably over many turns - Reading a whole codebase or a long document set in one prompt instead of chunking it - Work that needs open-weight, MIT-licensed capability rather than a closed model - Trading cost against answer quality per request by moving the thinking level

## Choose another model when - Your input includes images, audio or video — this is a text-only model - A single reply has to exceed 131,072 tokens — that is the published output ceiling, and thinking tokens count against it - You want the cheapest possible tokens for bulk classification, tagging or translation — this model thinks at `max` by default and bills that thinking as output tokens

Served through the OpenAI-compatible chat completions API:

``` POST https://queue.modelrunner.run/z-ai/glm-5.2/chat/completions ```

Point any OpenAI SDK or OpenAI-compatible tool at `base_url = https://queue.modelrunner.run/z-ai/glm-5.2` with your ModelRunner API key; streaming, tool calling and JSON mode all work.

```js import OpenAI from "openai";

const client = new OpenAI({ apiKey: process.env.MODELRUNNER_API_KEY, baseURL: "https://queue.modelrunner.run/z-ai/glm-5.2", });

const result = await client.chat.completions.create({ model: "z-ai/glm-5.2", messages: [ { role: "user", content: "Find every bug in this function, explain each one, then rewrite it with a complexity analysis." }, ], reasoning_effort: "high", max_tokens: 4096, }); ```

Billing is per token from the model's own reported usage, thinking included; repeated prompt prefixes are cached automatically and bill at a reduced rate.