Skip to Content

GLM family

Zhipu’s GLM text models, including the GLM-5.3, GLM-5.2, GLM-5.1 and GLM-5 series and the vision model GLM-5V Turbo. They are called through the OpenAI-compatible API and also support the Anthropic-native API, so they work in Claude Code.

Common tasks

Models

For the full model list and live prices, see the model page , or query the Models API. The model ID prefix is z-ai/ and can be omitted.

Common model IDs (copy them exactly)
GLM-5.3z-ai/glm-5.3Text only; 1M context
GLM-5.3 Flashz-ai/glm-5.3-flashSupports image input
GLM-5.1z-ai/glm-5.1Text only
GLM-5V Turboz-ai/glm-5v-turboSupports images and PDF
CapabilitySupported models
Image inputGLM-5.3 Flash, GLM-5.3 FlashX, GLM-5V Turbo
PDF inputGLM-5V Turbo
1M contextGLM-5.3 series, GLM-5.2; the rest are 200K

GLM models are served by Zhipu’s international site (zai); some models are also available from other providers such as Alibaba Cloud Model Studio and Volcano Engine, selected automatically by default. For how to select one, see Provider routing.

Examples

glm_basic.py
import os from openai import OpenAI client = OpenAI(base_url="https://api.ofox.io/v1", api_key=os.environ["OFOX_API_KEY"]) resp = client.chat.completions.create( model="z-ai/glm-5.1", messages=[{"role": "user", "content": "Explain idempotency in one sentence."}], extra_body={"thinking": {"type": "disabled"}}, ) print(resp.choices[0].message.content)

Thinking mode

Key pointGLM models think by default, and complex questions can use over 10,000 thinking tokens and take several minutes. If you don’t need thinking, set the thinking type to disabled.

All GLM models think by default. Thinking volume and latency we measured on the same math problem:

ModelDefault thinking tokensLatency
GLM-5.3 FlashAbout 1,400About 20 s
GLM-5.3About 3,300About 50 s
GLM-5.1About 7,700About 2 min
GLM-5About 24,000About 4.5 min
GLM-5 TurboAbout 18,000About 8 min

Passing "thinking": {"type": "disabled"} turns thinking off. In our tests it works on GLM-5.2, GLM-5.1, GLM-5, GLM-5 Turbo, GLM-5V Turbo and GLM-4.7 FlashX, and cuts latency substantially (GLM-5, for example, went from about 4.5 minutes to about 10 seconds). With the OpenAI SDK, put it in extra_body.

Thinking tokens are billed at the output rate; the count is in usage.completion_tokens_details.reasoning_tokens.

Reading the thinking content

  • In streaming responses, thinking content is in delta.reasoning_content, the same as Zhipu’s official API.
  • In non-streaming responses, thinking content is in message.reasoning_details; concatenate the text of each item in order.

Use in Claude Code

GLM models support the Anthropic-native API at https://api.ofox.io/anthropic:

Claude Code settings
ANTHROPIC_BASE_URLhttps://api.ofox.io/anthropic
ANTHROPIC_AUTH_TOKENPaste your OfoxAI API key
ANTHROPIC_MODELz-ai/glm-5.3
Terminal
curl https://api.ofox.io/anthropic/v1/messages \ -H "x-api-key: $OFOX_API_KEY" \ -H "anthropic-version: 2023-06-01" \ -H "Content-Type: application/json" \ -d '{ "model": "z-ai/glm-5.3", "max_tokens": 8000, "messages": [{"role": "user", "content": "Explain idempotency in one sentence."}] }'
  • On the Anthropic API, thinking content is returned as thinking blocks, and "thinking": {"type": "disabled"} also turns thinking off (on the same models as above).
  • When thinking is on, set a large enough max_tokens and set the client timeout to 600 seconds or more.

For full Claude Code setup steps, see Claude Code setup.

Images and PDF

Models that support image input use the standard image_url content block; GLM-5V Turbo also accepts PDFs via a file content block:

glm_vision.py
import base64 import os from openai import OpenAI client = OpenAI(base_url="https://api.ofox.io/v1", api_key=os.environ["OFOX_API_KEY"]) img_b64 = base64.b64encode(open("photo.png", "rb").read()).decode() resp = client.chat.completions.create( model="z-ai/glm-5v-turbo", messages=[{"role": "user", "content": [ {"type": "image_url", "image_url": {"url": f"data:image/png;base64,{img_b64}"}}, {"type": "text", "text": "Describe this image."}, ]}], extra_body={"thinking": {"type": "disabled"}}, ) print(resp.choices[0].message.content)

GLM-5.3, GLM-5.2, GLM-5.1, GLM-5 and GLM-5 Turbo are text-only; do not send them images.

JSON output and tool calling

For response_format, use {"type": "json_object"} and state “return JSON” and the required fields in the prompt; tool calling uses the standard tools parameter. For the syntax, see Structured output and Function calling.

Prompt caching

GLM automatically caches repeated request prefixes, with no changes to your request. The cached amount is in usage.prompt_tokens_details.cached_tokens, and the cached portion is billed at the cache read rate.

Common errors

Key pointSlow requests or timeouts are usually caused by thinking, which is on by default. Turn it off if you don’t need it.
HTTP · typeError messageCauseFix
400 invalid_request_errorPrompt 超长Input exceeds the model’s context windowShorten the input, or switch to GLM-5.3 or GLM-5.2, which have 1M context
404 model_not_foundModel 'z-ai/glm-9' not foundModel ID misspelled, or the zhipu/ prefix was usedThe prefix is z-ai/; copy the model ID from this page
504 gateway_timeoutThe upstream service did not respond in time.Thinking took too long and upstream did not respond in timeTurn thinking off, or use streaming
200, empty answer or thinking content only—Thinking used up the output budgetIncrease max_tokens, or turn thinking off

For other general errors, see Error Handling.

Official docs

The official docs describe behavior when calling Zhipu directly. When calling through OfoxAI, model IDs and endpoints on this page take precedence.

FAQ

How do I write a GLM model ID?

The standard format is z-ai/glm-5.3; you can also omit the prefix and write glm-5.3. zhipu/glm-5.3 returns 404.

How do I turn off GLM thinking?

Pass "thinking": {"type": "disabled"}; with the OpenAI SDK, put it in extra_body. In our tests it works on GLM-5.2, 5.1, 5, 5 Turbo and 5V Turbo.

Why does GLM take several minutes to respond?

GLM thinks by default, and on complex questions GLM-5 and GLM-5 Turbo may think for over 10,000 tokens and take several minutes. Turn thinking off if you do not need it, or switch to GLM-5.3 Flash, which thinks less.

Can I use GLM in Claude Code?

Yes. Set ANTHROPIC_BASE_URL to https://api.ofox.io/anthropic and use a GLM model ID such as z-ai/glm-5.3.

Which GLM models can understand images?

GLM-5.3 Flash, GLM-5.3 FlashX and GLM-5V Turbo support image input, and GLM-5V Turbo also supports PDF. The other GLM models are text-only.

What does the GLM error Prompt 超长 mean?

The input exceeds the model context window (the message means "prompt too long"). The GLM-5.3 series and GLM-5.2 have 1M tokens; the rest have 200K tokens.

Last updated on