GLM API

GLM API, pay as you go

Z.ai’s GLM models through the MegaBrain API, without an account on the Z.ai platform. Pay per token from a prepaid US-dollar balance at the prices in the table; the same key opens Claude, GPT, Gemini and image and video generation.

GLM models and prices

Prices in US dollars per 1M tokens, from the MegaBrain catalogue; they update automatically.

ModelInputOutputContext
GLM 5.3
z-ai/glm-5.3
$1.51$4.751M
GLM 5.3 Prime
z-ai/glm-5.3-prime
$2.02$6.341M
GLM 5.3 Flash
z-ai/glm-5.3-flash
$0.18$0.61M
GLM 5.2
z-ai/glm-5.2
$1.68$5.281M
GLM 5.1
z-ai/glm-5.1
$1.68$5.28205K
GLM 5 Turbo
z-ai/glm-5-turbo
$1.44$4.8203K
GLM 5
z-ai/glm-5
$1.2$3.84205K
GLM 4.7 Flash
z-ai/glm-4.7-flash
$0.07$0.48131K
GLM 4.7
z-ai/glm-4.7
$0.48$2.1203K
GLM 4.6V
z-ai/glm-4.6v
$0.36$1.08131K

All Z.ai models in the catalogue — 14

Which GLM model to pick

GLM 5.3 is Z.ai’s model for complex software engineering and long-horizon agent tasks, with a 1M-token context window. GLM 5.3 Prime is the same model with 1.5–2× the output speed. GLM 5.3 Flash is a native multimodal model for efficient coding and agents, and GLM 4.7 Flash is a light 30B-class model.

GLM-5.3-Flash tied Claude Opus 4.8 on the same benchmark

Your code barely changes

The MegaBrain API is OpenAI-compatible. Change the base URL to https://getmegabrain.com/api/gateway/v1, the key to your MegaBrain key, and set model to an id from the table: they start with z-ai/.

First request

The API is OpenAI-compatible: the official SDK, LangChain and any client with a base URL field work. Create the key on the API key page after you sign up.

from openai import OpenAI

client = OpenAI(
    base_url="https://getmegabrain.com/api/gateway/v1",
    api_key="YOUR_MEGABRAIN_KEY",
)

response = client.chat.completions.create(
    model="z-ai/glm-5.3",
    messages=[{"role": "user", "content": "Hello! What can you do?"}],
)
print(response.choices[0].message.content)

Questions and answers

Do I need a Z.ai platform account?

No. Sign up on MegaBrain, top up the balance by card and create a key. Requests to GLM models are paid from that balance for the tokens actually used, and the same key works for every other model in the catalogue.

How are requests paid for?

From a prepaid balance in US dollars, for the tokens actually used: input and output separately, at the price per 1M tokens in the table. No subscription is needed: top up by card and pay as you go.

Can I use GLM in Cursor or an AI agent?

Yes, in any client with a base URL field: the OpenAI SDK, LangChain, Cursor, Continue, OpenCode, Kilo Code. Step-by-step guides for agents are in MegaBrain University.

Can I try it for free?

Yes. The model mb-auto/free (Auto Free) is free and works without an API key or sign-up: each request goes to a free model available at that moment, with a limit per IP address. The paid models in the table need an account and a balance.

Get your API key

Sign-up is open. Create an account, top up the balance by card and create a key: it works for every text, image, video and audio model in the catalogue. Credits never expire.

Questions? Write to team@getmegabrain.com