Chat Completions
Request and response reference for the OpenAI-compatible GLM 5 Chat Completions API.
/chat/completionsGenerate assistant text or function calls from a list of chat messages.
The GLM 5 Chat Completions endpoint follows the OpenAI/OpenRouter request and response shape for text chat. Existing OpenAI or OpenRouter-style clients can usually keep the same SDK and request body, then change the base URL, API key, and model ID.
https://glm5.app/api/v1Basic Request
curl https://glm5.app/api/v1/chat/completions \
-H "Authorization: Bearer $GLM5_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "glm-5.2",
"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.2. |
messages | array | Yes | - | Conversation messages. At least one valid message is required. |
max_completion_tokens | integer | No | Model/provider | Forwarded without an application-level maximum. |
max_tokens | integer | No | Model/provider | Legacy alias for max_completion_tokens; forwarded without clamping. |
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 | Forwarded when the selected upstream model supports it. |
seed | integer | No | - | Forwarded 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 a token-based context window or output cap before contacting the model. The selected upstream provider applies its own current limits and returns an error if the request is too large.
OpenRouter Compatibility
OpenRouter exposes a broad router API. GLM 5 accepts the common Chat Completions shape, but only the documented subset affects model behavior.
Compatible Fields
| OpenRouter/OpenAI 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.2, glm-5, kimi-k3, kimi-k2, deepseek-v4-pro, and deepseek-v4-flash. |
tool_choice | Supported for normal function tools. |
max_completion_tokens | Forwarded when supplied; omitted requests use the provider default. |
max_tokens | Forwarded as the legacy alias without an application-level cap. |
temperature | Forwarded. |
top_p | Forwarded. |
top_k | Forwarded when supported upstream. |
seed | Forwarded when supported upstream. |
stop | Forwarded as stop sequences. |
Accepted But Not Applied
Some SDKs include extra OpenRouter or OpenAI fields. GLM 5 does not currently reject every unknown field, but these fields are not forwarded to the model and should not be relied on:
| Field family | GLM 5 behavior |
|---|---|
models, route, provider | No model fallback chain, provider ordering, or provider filtering. |
plugins, transforms | No OpenRouter web plugin, file parser, moderation, or compression. |
response_format | JSON mode and JSON Schema modes are not currently enforced. |
frequency_penalty, presence_penalty, repetition_penalty, logit_bias | Not forwarded. |
logprobs, top_logprobs | Not returned. |
reasoning, reasoning_effort | Not forwarded as a public API control. |
modalities, audio, image_config | This endpoint is text-only. |
metadata, user, session_id, prompt_cache_key | Not used for routing, billing, or cache affinity. |
stream_options, service_tier, prediction, parallel_tool_calls | Not currently applied. |
For strict integrations, remove unsupported fields before depending on their effects. For compatibility, old callers that already send harmless extra fields can continue using the endpoint.
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.2",
"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 reported by the provider after completion. |
usage.completion_tokens | Output tokens reported by the provider after completion. |
usage.total_tokens | Prompt plus completion tokens. |
GLM 5 does not currently return OpenRouter-specific fields such as
openrouter_metadata, usage.cost, usage.prompt_tokens_details.cached_tokens,
service_tier, or system_fingerprint.
Provider Limits
GLM 5 does not return synthetic context-budget headers or reject requests using
a locally configured token window. Use the final usage.prompt_tokens value for
monitoring and handle any context or output-limit error returned by the selected
upstream model.
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.