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.
z-ai/glm-5.3Text only; 1M contextz-ai/glm-5.3-flashSupports image inputz-ai/glm-5.1Text onlyz-ai/glm-5v-turboSupports images and PDFGLM 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
Python
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
All GLM models think by default. Thinking volume and latency we measured on the same math problem:
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 thetextof each item in order.
Use in Claude Code
GLM models support the Anthropic-native API at https://api.ofox.io/anthropic:
https://api.ofox.io/anthropicz-ai/glm-5.3curl 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
thinkingblocks, and"thinking": {"type": "disabled"}also turns thinking off (on the same models as above). - When thinking is on, set a large enough
max_tokensand 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:
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
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.