curl --request POST \
--url https://api.z.ai/api/paas/v4/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "glm-5.3",
"messages": [
{
"role": "system",
"content": "You are a helpful coding assistant."
},
{
"role": "user",
"content": "Write a Python function to calculate the factorial of a number."
}
],
"temperature": 1,
"stream": false
}
'{
"id": "<string>",
"request_id": "<string>",
"created": 123,
"model": "<string>",
"choices": [
{
"index": 123,
"message": {
"role": "assistant",
"content": "<string>",
"reasoning_content": "<string>",
"tool_calls": [
{
"function": {
"name": "<string>",
"arguments": {}
},
"id": "<string>",
"type": "<string>"
}
]
},
"finish_reason": "<string>"
}
],
"usage": {
"prompt_tokens": 123,
"completion_tokens": 123,
"prompt_tokens_details": {
"cached_tokens": 123
},
"total_tokens": 123
},
"web_search": [
{
"title": "<string>",
"content": "<string>",
"link": "<string>",
"media": "<string>",
"icon": "<string>",
"refer": "<string>",
"publish_date": "<string>"
}
]
}{
"code": 123,
"message": "<string>"
}Chat Completion
Create a chat completion model that generates AI replies for given conversation messages. It supports multimodal inputs (text, images, audio, video, file), offers configurable parameters (like temperature, max tokens, tool use), and supports both streaming and non-streaming output modes.
curl --request POST \
--url https://api.z.ai/api/paas/v4/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "glm-5.3",
"messages": [
{
"role": "system",
"content": "You are a helpful coding assistant."
},
{
"role": "user",
"content": "Write a Python function to calculate the factorial of a number."
}
],
"temperature": 1,
"stream": false
}
'{
"id": "<string>",
"request_id": "<string>",
"created": 123,
"model": "<string>",
"choices": [
{
"index": 123,
"message": {
"role": "assistant",
"content": "<string>",
"reasoning_content": "<string>",
"tool_calls": [
{
"function": {
"name": "<string>",
"arguments": {}
},
"id": "<string>",
"type": "<string>"
}
]
},
"finish_reason": "<string>"
}
],
"usage": {
"prompt_tokens": 123,
"completion_tokens": 123,
"prompt_tokens_details": {
"cached_tokens": 123
},
"total_tokens": 123
},
"web_search": [
{
"title": "<string>",
"content": "<string>",
"link": "<string>",
"media": "<string>",
"icon": "<string>",
"refer": "<string>",
"publish_date": "<string>"
}
]
}{
"code": 123,
"message": "<string>"
}Authorizations
Headers
Config desired response language for HTTP requests.
en-US,en "en-US,en"
Body
- Text Model
- Vision Model
The model code to be called. GLM-5.3, GLM-5.2, GLM-5.1 are the latest flagship model series, foundational models specifically designed for agent applications.
glm-5.3, glm-5.2, glm-5.1, glm-5, glm-4.7, glm-4.7-flash, glm-4.7-flashx, glm-4.6, glm-4.5, glm-4.5-air, glm-4.5-x, glm-4.5-airx, glm-4.5-flash, glm-4-32b-0414-128k "glm-5.3"
The current conversation message list as the model’s prompt input, provided in JSON array format, e.g.,{“role”: “user”, “content”: “Hello”}. Possible message types include system messages, user messages, assistant messages, and tool messages. Note: The input must not consist of system messages or assistant messages only.
1- User Message
- System Message
- Assistant Message
- Tool Message
When do_sample is true, sampling strategy is enabled; when do_sample is false, sampling strategy parameters such as temperature and top_p will not take effect. Default value is true.
true
This parameter should be set to false or omitted when using synchronous call. It indicates that the model returns all content at once after generating all content. Default value is false. If set to true, the model will return the generated content in chunks via standard Event Stream. When the Event Stream ends, a data: [DONE] message will be returned.
false
Only supported by GLM-4.5 series and higher models. This parameter is used to control whether the model enable the chain of thought.
Hide child attributes
Hide child attributes
Whether to enable the chain of thought(GLM-5.3 GLM-5.3-FLASH can only be enabled, and the thinking depth is controlled by reasoning_effort; for other models, when enabled, GLM-5.2 GLM-5.1 GLM-5 GLM-4.6 GLM-4.5 and others will automatically determine whether to think, while GLM-4.7 and GLM-4.5V will think compulsorily), default: enabled
enabled, disabled Default value is True. Controls whether to clear reasoning_content from previous conversation turns. View more in Thinking Mode.
true(default): For this request, the system ignores/removesreasoning_contentfrom prior turns, and only keeps non-reasoning context (e.g., user/assistant visible text, tool calls, and tool results). This is recommended for general chat or lightweight tasks to reduce context length and cost.false: Retainsreasoning_contentfrom prior turns and includes it in the context sent to the model. To enable Preserved Thinking, you must forward the full, unmodified, and correctly ordered historicalreasoning_contentinmessages. Missing, truncated, rewritten, or reordered blocks may degrade performance or prevent the feature from taking effect.- Notes: This parameter only affects cross-turn historical thinking blocks; it does not change whether the model generates/returns thinking in the current turn.
true
Controls the model's reasoning effort level, takes effect when thinking is enabled. Default is max, supported by GLM-5.2 and above. For the GLM-5.3 GLM-5.3-FLASH model, only the low / high / max levels are supported. For the GLM-5.2 model, for compatibility with other protocols, passing none or minimal will cause the model to skip thinking; low and medium will be mapped to high; xhigh will be mapped to max.
max, xhigh, high, medium, low, minimal, none "max"
Sampling temperature, controls the randomness of the output, must be a positive number within the range: [0.0, 1.0]. The GLM-5.3, GLM-5.2, GLM-5.1, GLM-5, GLM-4.7, GLM-4.6 series default value is 1.0, GLM-4.5 series default value is 0.6, GLM-4-32B-0414-128K default value is 0.75.
0 <= x <= 11
Another method of temperature sampling, value range is: [0.01, 1.0]. The GLM-5.3, GLM-5.2, GLM-5.1, GLM-5, GLM-4.7, GLM-4.6, GLM-4.5 series default value is 0.95, GLM-4-32B-0414-128K default value is 0.9.
0.01 <= x <= 10.95
The maximum number of tokens for model output, the GLM-5.3, GLM-5.2, GLM-5.1, GLM-5, GLM-4.7, GLM-4.6 series supports 128K maximum output, the GLM-4.5 series supports 96K maximum output, the GLM-4.6v series supports 32K maximum output, the GLM-4.5v series supports 16K maximum output, GLM-4-32B-0414-128K supports 16K maximum output.
1 <= x <= 1310721024
Whether to enable streaming response for Function Calls. Default value is false. Only supported by the GLM-5.3, GLM-5.2, GLM-5.1, GLM-5, GLM-4.7, and GLM-4.6 series. Refer to the Stream Tool Call
false
A list of tools the model may call. Currently, only functions are supported as a tool. Use this to provide a list of functions the model may generate JSON inputs for. A max of 128 functions are supported.
- Function Call
- Retrieval
- Web Search
Hide child attributes
Hide child attributes
function Hide child attributes
Hide child attributes
The name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64.
1 - 64^[a-zA-Z0-9_-]+$A description of what the function does, used by the model to choose when and how to call the function.
Parameters defined using JSON Schema. Must pass a JSON Schema object to accurately define accepted parameters. Omit if no parameters are needed when calling the function.
Controls how the model selects a tool.
auto Stop word list. Generation stops when the model encounters any specified string. Currently, only one stop word is supported, in the format ["stop_word1"].
4Specifies the response format of the model. Defaults to text. Only text models support this field. type converges to three values: text (plain text output), json_object (JSON output).
Hide child attributes
Hide child attributes
Output format type: text for plain text, json_object for JSON-formatted output.
text, json_object Passed by the user side, needs to be unique; used to distinguish each request, 6–64 characters. If not provided by the user side, the platform will generate one by default.
6 - 64Unique ID for the end user, 6–128 characters. Avoid using sensitive information.
6 - 128Response
Processing successful
Task ID
Request ID
Request creation time, Unix timestamp in seconds
Model name
List of model responses
Hide child attributes
Hide child attributes
Result index.
Hide child attributes
Hide child attributes
Current conversation role, default is ‘assistant’ (model)
"assistant"
Current conversation content. Hits function is null, otherwise returns model inference result.
For the GLM-4.5V series models, the output may contain the reasoning process tags <think> </think> or the text boundary tags <|begin_of_box|> <|end_of_box|>.
Reasoning content, supports by GLM-4.5 series.
Function names and parameters generated by the model that should be called.
Hide child attributes
Hide child attributes
Contains the function name and JSON format parameters generated by the model.
Unique identifier for the hit function.
Tool type called by the model, currently only supports ‘function’.
Reason for model inference termination. Can be stop, tool_calls, length, sensitive, model_context_window_exceeded or network_error.
Token usage statistics returned when the model call ends.
Hide child attributes
Hide child attributes
Search results.
Was this page helpful?