# GLM (Zhipu) API: model IDs, thinking mode, image input and Claude Code Source: https://ofox.ai/docs/develop/models/glm 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 - [Turn off thinking](#thinking) — Thinking is on by default; how to turn it off when responses are slow. - [Use in Claude Code](#anthropic) — Call GLM through the Anthropic API. - [Images & PDF](#vision) — Which models can understand images and documents. - [Troubleshooting errors](#errors) — Prompt too long, empty answers, request timeouts. ## Models For the full model list and live prices, see the [model page](https://ofox.ai/models?provider=z-ai), or query the [Models API](https://ofox.ai/docs/api/openai/models). The model ID prefix is `z-ai/` and can be omitted. **Common model IDs (copy them exactly)** - GLM-5.3: `z-ai/glm-5.3` — Text only; 1M context - GLM-5.3 Flash: `z-ai/glm-5.3-flash` — Supports image input - GLM-5.1: `z-ai/glm-5.1` — Text only - GLM-5V Turbo: `z-ai/glm-5v-turbo` — Supports images and PDF | Capability | Supported models | |---|---| | Image input | GLM-5.3 Flash, GLM-5.3 FlashX, GLM-5V Turbo | | PDF input | GLM-5V Turbo | | 1M context | GLM-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](https://ofox.ai/docs/develop/advanced/provider-routing). ## Examples **Python** ```python filename="glm_basic.py" import os from openai import OpenAI client = OpenAI(base_url="https://api.ofox.ai/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) ``` **cURL** ```bash filename="Terminal" curl https://api.ofox.ai/v1/chat/completions \ -H "Authorization: Bearer $OFOX_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "z-ai/glm-5.1", "messages": [{"role": "user", "content": "Explain idempotency in one sentence."}], "thinking": {"type": "disabled"} }' ``` ## Thinking mode **Key point**:GLM 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: | Model | Default thinking tokens | Latency | |---|---|---| | GLM-5.3 Flash | About 1,400 | About 20 s | | GLM-5.3 | About 3,300 | About 50 s | | GLM-5.1 | About 7,700 | About 2 min | | GLM-5 | About 24,000 | About 4.5 min | | GLM-5 Turbo | About 18,000 | About 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.ai/anthropic`: **Claude Code settings** - ANTHROPIC_BASE_URL: `https://api.ofox.ai/anthropic` - ANTHROPIC_AUTH_TOKEN: Paste your OfoxAI API key - ANTHROPIC_MODEL: `z-ai/glm-5.3` ```bash filename="Terminal" curl https://api.ofox.ai/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](https://ofox.ai/docs/integrations/claude-code). ## 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: ```python filename="glm_vision.py" import base64 import os from openai import OpenAI client = OpenAI(base_url="https://api.ofox.ai/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](https://ofox.ai/docs/develop/guides/structured-output) and [Function calling](https://ofox.ai/docs/develop/guides/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 point**:Slow requests or timeouts are usually caused by thinking, which is on by default. Turn it off if you don't need it. | HTTP · type | Error message | Cause | Fix | |---|---|---|---| | 400 `invalid_request_error` | `Prompt 超长` | Input exceeds the model's context window | Shorten the input, or switch to GLM-5.3 or GLM-5.2, which have 1M context | | 404 `model_not_found` | `Model 'z-ai/glm-9' not found` | Model ID misspelled, or the `zhipu/` prefix was used | The prefix is `z-ai/`; copy the model ID from this page | | 504 `gateway_timeout` | `The upstream service did not respond in time.` | Thinking took too long and upstream did not respond in time | Turn thinking off, or use streaming | | 200, empty answer or thinking content only | — | Thinking used up the output budget | Increase `max_tokens`, or turn thinking off | For other general errors, see [Error Handling](https://ofox.ai/docs/develop/guides/error-handling). ## Official docs - [Zhipu Open Platform · Docs](https://docs.bigmodel.cn/) - [Z.ai · Developer docs](https://docs.z.ai/) 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.ai/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.