Chat Completions
Full request and response reference for GLM 5 Chat Completions — supported fields, message shapes, usage accounting, finish reasons, and model limits.
/chat/completionsGenerate assistant text or function calls from a list of chat messages.
The GLM 5 Chat Completions endpoint follows an OpenAI-compatible request and response shape for text chat. Existing OpenAI-compatible clients can usually keep the same SDK and request body, then change the base URL, API key, and model ID.
https://glm5.app/api/v1
Basic Request
curl https://glm5.app/api/v1/chat/completions \
-H "Authorization: Bearer $GLM5_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "glm-5.3-flash",
"messages": [
{"role": "system", "content": "Answer in concise Markdown."},
{"role": "user", "content": "Explain idempotency in two bullets."}
],
"max_completion_tokens": 600
}'
Request Body
| Parameter | Type | Required | Default | GLM 5 behavior |
|---|---|---|---|---|
model | string | Yes | - | Public model ID from Models, for example glm-5.3-flash. |
messages | array | Yes | - | Conversation messages. At least one valid message is required. |
max_completion_tokens | integer | No | Model default | Optional output limit for the request, forwarded to the model as-is. |
max_tokens | integer | No | Model default | Legacy alias for max_completion_tokens. |
temperature | number | No | Model default | Forwarded as sampling temperature. |
top_p | number | No | Model default | Forwarded as nucleus sampling. |
top_k | integer | No | Model default | Applied when supported by the selected model. |
seed | integer | No | - | Used as a deterministic sampling hint when supported. |
stop | string or string[] | No | - | One or more stop sequences. |
stream | boolean | No | false | When true, returns Server-Sent Events. |
tools | array | No | - | OpenAI-compatible function tools. |
tool_choice | string or object | No | auto | auto, none, required, or a named function choice. |
The request JSON body must be at most 4 MB. GLM 5 does not impose one global
token context or output window across all models, and does not add its own
ceiling on top of a model's native limits. max_completion_tokens is passed
straight through to the selected model; omit it and the model runs to its own
default stopping point. If a value is genuinely too large for the model you
selected, the request fails the same way it would calling that model
directly — see Errors for the shape of that response.
Context and output limits vary by model; oversized requests return
context_length_exceeded.
Safe Retries And Request Status
For network retries, send one stable Idempotency-Key with the request. GLM5
creates at most one inference task for each key and API key pair. The request
body may be retried in any JSON key order, but reusing the key for different
content returns 409 idempotency_key_reused.
Idempotency-Key: codex:turn_01JQ9KPC3H5YQ2T8
If the original request is still running, or has already reached a terminal
state, GLM5 returns 409 with request_id, request_status, and status_url.
It also exposes the same URL in X-GLM5-Request-Status. Poll that endpoint
with the same API key instead of submitting the request again:
curl https://glm5.app/api/v1/requests/chatcmpl-01... \
-H "Authorization: Bearer $GLM5_API_KEY"
The status response includes the terminal state, token usage, charged credits, and a safe error code when applicable. It does not retain or replay completion text, so a client reconnects to inspect task state and then decides whether a new request is needed. This avoids silently storing prompts or responses just to support retries.
For an in-flight request, streaming or non-streaming, send an explicit cancellation with the same API key:
curl -X POST https://glm5.app/api/v1/requests/chatcmpl-01.../cancel \
-H "Authorization: Bearer $GLM5_API_KEY"
The endpoint returns 202 with cancel_requested, then the status endpoint
settles as cancelled. Cancelled reservations are released; error remains
reserved for provider, validation, and timeout failures.
Supported fields
GLM 5 accepts the documented Chat Completions fields below. Only the documented subset is guaranteed to affect model behavior.
| Field | GLM 5 behavior |
|---|---|
model | Required. Must be a GLM 5 public model ID. |
messages | Required. Text messages and function-call history are supported. |
stream | Supported with OpenAI-style SSE chunks and data: [DONE]. |
tools | Supported for glm-5.3-flash, glm-5.3, glm-5.2, glm-5, kimi-k3, kimi-k2, deepseek-v4-pro, and deepseek-v4-flash. |
tool_choice | Supported for normal function tools. |
max_completion_tokens | Applies an output limit when supplied, unmodified; omitted requests use the model default. |
max_tokens | Legacy alias for max_completion_tokens. |
temperature | Supported. |
top_p | Supported. |
top_k | Supported when available for the selected model. |
seed | Supported when available for the selected model. |
stop | Supported as stop sequences. |
Additional SDK fields
Some SDKs may send fields that are not listed in this reference. GLM 5 may ignore unknown fields for compatibility, but applications should not depend on undocumented behavior.
Notable current limitations include:
response_formatJSON mode and JSON Schema enforcement are not available.frequency_penalty,presence_penalty,repetition_penalty, andlogit_biasare not applied.logprobsandtop_logprobsare not returned.reasoningandreasoning_effortare not exposed as public controls.modalities,audio, andimage_configare not supported by this text endpoint.stream_options,service_tier,prediction, andparallel_tool_callsare not currently applied.
For strict integrations, only depend on fields documented on this page.
Messages
messages is an ordered array. GLM 5 is stateless: previous turns are only
remembered when your application sends them again.
| Role | Content support | Purpose |
|---|---|---|
system | String or OpenAI text parts | Application instructions and behavior constraints. |
user | String or OpenAI text parts | User input or task data. |
assistant | String content, tool_calls, or both | Prior assistant output or function calls. |
tool | String or OpenAI text parts plus matching tool_call_id | Result for a previous assistant tool call. |
Only text parts are used. Image, audio, video, and file parts are ignored by this text endpoint.
[
{
"role": "system",
"content": "You are a concise technical assistant."
},
{
"role": "user",
"content": [
{
"type": "text",
"text": "Summarize this deployment checklist."
}
]
}
]
When trimming history, keep assistant tool_calls and their matching tool
messages together. A tool message without a preceding matching
tool_call_id returns 400 invalid_request_error.
Non-Streaming Response
Non-streaming calls return a chat.completion object:
{
"id": "chatcmpl-01...",
"object": "chat.completion",
"created": 1785292800,
"model": "glm-5.3-flash",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "- Idempotency makes retries safe..."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 42,
"completion_tokens": 31,
"total_tokens": 73
}
}
Response Fields
| Field | Meaning |
|---|---|
id | GLM 5-generated completion ID. |
object | Always chat.completion for non-streaming responses. |
created | Unix timestamp in seconds. |
model | Public model ID used for the request. |
choices[].index | Choice index. GLM 5 currently returns one choice. |
choices[].message.role | Usually assistant. |
choices[].message.content | Assistant text, or null when the model returns only tool calls. |
choices[].message.tool_calls | Function calls requested by the model. |
choices[].finish_reason | stop or tool_calls. |
usage.prompt_tokens | Input tokens counted for the completed request. |
usage.completion_tokens | Output tokens counted for the completed request. |
usage.total_tokens | Prompt plus completion tokens. |
GLM 5 does not currently return fields such as usage.cost,
usage.prompt_tokens_details.cached_tokens, service_tier, or
system_fingerprint.
Model limits
GLM 5 does not return synthetic context-budget headers, does not publish a
per-model context/output limit table, and does not enforce an application
ceiling below what the selected model natively supports — capability limits
come from the model itself. Use the final usage.prompt_tokens value for
monitoring and handle any context or output-limit error returned for the
selected model. A streaming (stream: true) response may run for up to 90
seconds before it is cut off with stream_timeout; see
Errors.
Finish Reasons
| Value | Meaning |
|---|---|
stop | The model finished normally. |
tool_calls | The model requested one or more function calls. |
For incremental output, see Streaming. For tool-call loops, see Function calling.