This topic describes how to use APIs to call GLM series models on the Alibaba Cloud Model Studio platform.
Service endpoints
Service endpoints vary by region. Configure the base URL that corresponds to your selected region.
- OpenAI compatible
- OpenAI compatible - Responses API
- DashScope
- China (Beijing)
- US (Virginia)
- Germany (Frankfurt)
- Hong Kong (China)
- Singapore
base_url for SDK calls is: https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1HTTP request endpoint: POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/chat/completions{WorkspaceId} with your actual workspace ID.
Getting started
glm-5.3, glm-5.2, and glm-5.2-fast-preview are the latest models in the GLM series. They have a context length of 1M. glm-5.2 and glm-5.2-fast-preview let you set the thinking mode and non-thinking mode using the enable_thinking parameter. glm-5.3 supports only the thinking mode, which cannot be disabled. You can run the following code to quickly call the glm-5.2 model in thinking mode.
Before you start, obtain an API key and configure it as an environment variable. If you use an SDK, you must also install the OpenAI or DashScope SDK.
- OpenAI compatible
- DashScope
- Anthropic compatible
enable_thinking parameter is not a standard OpenAI parameter. In the OpenAI Python SDK, it is passed through extra_body. In the Node.js SDK, it is passed as a top-level parameter.- Python
- Node.js
- HTTP
Sample code
Response
Streaming tool calling
glm-5.3, glm-5.2, glm-5.2-fast-preview, glm-5.1, glm-5 support the tool_stream parameter. This boolean parameter defaults to true for glm-5.3 and to false for the other models, and takes effect only when stream is set to true. When enabled, the arguments of the tool_call parameter from Function Calling are returned incrementally in a stream, rather than all at once after the full generation is complete.
The combined behavior of stream and tool_stream is as follows:
stream | tool_stream | tool_call return method |
|---|---|---|
true | true | The arguments are returned incrementally in multiple chunks. |
true | false (default) | The arguments are returned completely in a single chunk. |
false | true/false | tool_stream has no effect. The arguments are returned at once in the complete response. |
- OpenAI compatible
- DashScope
- Python
- Node.js
- HTTP
Sample code
Reasoning effort (reasoning_effort)
glm-5.3, glm-5.2, glm-5.2-fast-preview, and glm-5.1 have the thinking mode enabled by default. The model first outputs the thinking process (reasoning_content) and then provides the final answer. You can use the reasoning_effort parameter to adjust the reasoning effort. A higher value indicates more thorough thinking. The supported values vary by model. If you pass an unsupported value, an invalid_parameter_error error is returned. Select a value from the following table.
Model | Available values for reasoning_effort |
|---|---|
glm-5.3 |
|
glm-5.2 |
|
glm-5.2-fast-preview |
|
glm-5.1 |
|
enable_thinking parameter to false in OpenAI compatible or DashScope mode. This parameter has a higher priority than reasoning_effort. glm-5.3 does not support disabling the thinking mode. Setting enable_thinking to false has no effect.reasoning_effort parameter. To obtain the thinking content, use the native Anthropic thinking parameter: {"thinking":{"type":"enabled","budget_tokens":1024}}. When enabled, the response content will include a thinking block with type set to thinking.- OpenAI compatible
- DashScope
Clear thinking history (clear_thinking)
The clear_thinking parameter controls whether the reasoning_content (thinking process) from previous turns in a multi-turn conversation is passed to the model as context. This parameter is supported only by GLM series models.
true: Ignores thereasoning_contentfrom previous turns. Only non-reasoning content such as visible text, tool calls, and results is used as context input. This reduces the context length and cost.false: Retains thereasoning_contentfrom previous turns and provides it to the model along with the context. To enable Preserved Thinking, you must pass the historicalreasoning_contentcompletely, unmodified, and in the original order within the messages. Missing, clipping, rewriting, or reordering the content may degrade performance or cause the feature to fail.
true for glm-5.3 and false for the other GLM models.
assistant message contains reasoning_content. When clear_thinking is set to true, the historical thinking content is not included in the context. Therefore, the prompt_tokens count is lower than when it is set to false. The actual value depends on the length of the historical reasoning_content.
- OpenAI compatible
- DashScope
Responses API
glm-5.2 supports calls through the OpenAI-compatible Responses API. Only the China (Beijing) and Singapore regions are supported. For endpoints, see Service endpoints.
When calling the Responses API, you can add the web_search (Web search), web_extractor (Web extractor), and code_interpreter (Code Interpreter) tools to the tools parameter.
Other features
| Model | Multi-turn conversation | Function Calling | Structured output | Web search | Partial mode | Context cache |
|---|---|---|---|---|---|---|
| glm-5.3 | Supported | Supported | SupportedOnly | Not supported | Not supported | SupportedOnly implicit cache is supported |
| glm-5.2 | Supported | Supported | SupportedOnly in non-thinking mode | Not supported | Not supported | SupportedOnly implicit cache is supported |
| glm-5.2-fast-preview | Supported | Supported | SupportedOnly in non-thinking mode | Not supported | Not supported | SupportedOnly implicit cache is supported |
| glm-5.1 | Supported | Supported | SupportedOnly in non-thinking mode | Not supported | Not supported | SupportedBoth explicit and implicit cache are supported |
| glm-5 | Supported | Supported | SupportedOnly in non-thinking mode | Not supported | Not supported | SupportedOnly implicit cache is supported |
Default parameter values
Model | enable_thinking | temperature | top_p | top_k | repetition_penalty |
|---|---|---|---|---|---|
glm-5.3 | true (cannot be disabled) | 1.0 | 0.95 | Not supported | Not supported |
glm-5.2 | true | 1.0 | 0.95 | 20 | 1.0 |
glm-5.1 | true | 1.0 | 0.95 | 20 | 1.0 |
glm-5 | true | 1.0 | 0.95 | 20 | 1.0 |
Precautions
Models and billing
The GLM series models are hybrid reasoning models designed by Zhipu AI for agents. They provide both thinking and non-thinking modes.
- glm-5.3: The latest GLM model in the GLM series with a context length of 1M. It supports Function Calling, structured output, and implicit cache. You can call it using OpenAI compatible, DashScope, and Anthropic compatible interfaces.
- glm-5.2: A GLM model with a context length of 1M. It supports Function Calling, structured output, and implicit cache. You can call it using OpenAI compatible, DashScope, and Anthropic compatible interfaces.
- glm-5.2-fast-preview: The fast mode of the glm-5.2 model. For more information, see Prime mode.
In thinking mode, the chain-of-thought is billed as output tokens.