页面简介
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.
正文摘录
cURLBasic Examplecurl --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.4", "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 } '200default{ "id": "<string>", "request_id": "<string>", "created": 123, "model": "<string>", "choices": [ { "index": 123, "message": { "role": "assistant", "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>" } ] }POST/paas/v4/chat/completionsTry itcURLBasic Examplecurl --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.4", "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 } '200default{ "id": "<string>", "request_id": "<string>", "created": 123, "model": "<string>", "choices": [ { "index": 123, "message": { "role": "assistant", "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>" } ] }AuthorizationsAuthorizationstringheaderrequiredUse the following format for authentication: Bearer HeadersAccept-Languageenum<string>default:en-US,enConfig desired response language for HTTP requests.Available options: en-US,en Example:"en-US,en"Bodyapplication/jsonmodelenum<string>default:glm-5.4requiredThe model code to be called. GLM-5.4, GLM-5.3, GLM-5.2, GLM-5.1 are the latest flagship model series, foundational models specifically designed for agent applications.Available options: glm-5.4, glm-5.3-flashx, glm-5.3-flash, glm-5.3-flashx-legal, glm-5.3, glm-5.2, glm-5.1, glm-5, glm-4.7, glm-4.6 Example:"glm-5.4"messages(User Message · object | System Message · object | Assistant Message · object | Tool Message · object)[]requiredThe 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.Minimum array length: 1User MessageSystem MessageAssistant MessageTool MessageHide child attributesmessages.roleenum<string>default:userrequiredRole of the message authorAvailable options: user messages.content(Text · object | Image · object | Video · object | File · object)[]stringrequiredMultimodal message content, supports text, images, video, file. Only supported by the GLM-5.4 and GLM-5.3-Flash series; other models only support plain text content (string).TextImageVideoFileHide child attributesmessages.content.typeenum<string>default:textrequiredContent type is textAvailable options: text messages.content.textstringrequiredText contentdo_samplebooleandefault:trueWhen 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.Example:truestreambooleandefault:falseThis 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.Example:falsethinkingobjectOnly supported by GLM-4.6 series and higher models. This parameter is used to control whether the model enable the chain of thought.Hide child attributesthinking.typeenum<string>default:enabledWhether to enable the chain of thought(GLM-5.4 GLM-5.3 GLM-5.3-FLASH series 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 and others will automatically determine whether to think, while GLM-4.7 will think compulsorily), default: enabledAvailable options: enabled, disabled thinking.clear_thinkingbooleanControls whether to clear reasoning_content from previous conversation turns. The default value depends on the model: false for GLM-5.4 and later, true for earlier models. View more in Thinking Mode. true (default for models before GLM-5.4): For this request, the system ignores/removes reasoning_content from 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 (default for GLM-5.4 and later): Retains reasoning_content from 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 historical reasoning_content in messages. 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. Example:truereasoning_effortenum<string>default:maxControls 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.4 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.Available options: max, xhigh, high, medium, low, minimal, none Example:"max"temperaturenumber<float>default:1Sampling temperature, controls the randomness of the output, must be a positive number within the range: [0.0, 1.0]. The default value is 1.0 for all models.Required range: 0 <= x <= 1Example:1top_pnumber<float>default:0.95Another method of temperature sampling, value range is: [0.01, 1.0]. The default value is 0.95 for all models.Required range: 0.01 <= x <= 1Example:0.95max_tokensintegerThe maximum number of tokens for model output. All models support a maximum output length of 128K.Required range: 1 <= x <= 131072Example:1024tool_streambooleandefault:falseWhether to enable streaming response for Function Calls. Default value is false. Only supported by the GLM-5.4, GLM-5.3, GLM-5.2, GLM-5.1, GLM-5, GLM-4.7, and GLM-4.6 series. Refer to the Stream Tool CallExample:falsetools(Function Call · object | Retrieval · object | Web Search · object)[]A list of tools the model may call. Use this to provide a list of functions the model may generate JSON inputs for. A max of 128 functions are supported.Function CallRetrievalWeb SearchHide child attributestools.typeenum<string>default:functionrequiredAvailable options: function tools.functionobjectrequiredHide child attributestools.function.namestringrequiredThe 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.Required string length: 1 - 64Pattern: ^[a-zA-Z0-9_-]+$tools.function.descriptionstringrequiredA description of what the function does, used by the model to choose when and how to call the function.tools.function.parametersobjectrequiredParameters 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.tool_choiceenum<string>Controls how the model selects a tool.Available options: auto stopstring[]Stop word list. Generation stops when the model encounters any specified string. Currently, only one stop word is supported, in the format ["stop_word1"].Maximum array length: 4response_formatobjectSpecifies the response format of the model. Defaults to text. Only supported by the GLM-5.4, GLM-5.3-Flash, and GLM-5.3 series. type supports text (plain text output) and json_object (JSON output).Hide child attributesresponse_format.typeenum<string>default:textrequiredOutput format type: text for plain text, json_object for JSON-formatted output.Available options: text, json_object request_idstringPassed 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.Required string length: 6 - 64user_idstringUnique ID for the end user, 6–128 characters. Avoid using sensitive information.Required string length: 6 - 128Response200application/jsonProcessing successfulidstringTask IDrequest_idstringRequest IDcreatedintegerRequest creation time, Unix timestamp in secondsmodelstringModel namechoicesobject[]List of model responsesHide child attributeschoices.indexintegerResult index.choices.messageobjectHide child attributeschoices.message.rolestringCurrent conversation role, default is ‘assistant’ (model)Example:"assistant"choices.message.contentstringCurrent conversation content. Hits function