Chat Completions

Request and response reference for the OpenAI-compatible GLM 5 Chat Completions API.

POST/chat/completions

Generate 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",
    "messages": [
      {"role": "system", "content": "Answer in concise Markdown."},
      {"role": "user", "content": "Explain idempotency in two bullets."}
    ],
    "max_completion_tokens": 600
  }'

Request Body

ParameterTypeRequiredDefaultGLM 5 behavior
modelstringYes-Public model ID from Models, for example glm-5.3.
messagesarrayYes-Conversation messages. At least one valid message is required.
max_completion_tokensintegerNoModel defaultOptional output limit for the request.
max_tokensintegerNoModel defaultLegacy alias for max_completion_tokens.
temperaturenumberNoModel defaultForwarded as sampling temperature.
top_pnumberNoModel defaultForwarded as nucleus sampling.
top_kintegerNoModel defaultApplied when supported by the selected model.
seedintegerNo-Used as a deterministic sampling hint when supported.
stopstring or string[]No-One or more stop sequences.
streambooleanNofalseWhen true, returns Server-Sent Events.
toolsarrayNo-OpenAI-compatible function tools.
tool_choicestring or objectNoautoauto, 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 window across all models. Context and output limits can vary by model, and oversized requests return the corresponding API error.

Supported fields

GLM 5 accepts the documented Chat Completions fields below. Only the documented subset is guaranteed to affect model behavior.

FieldGLM 5 behavior
modelRequired. Must be a GLM 5 public model ID.
messagesRequired. Text messages and function-call history are supported.
streamSupported with OpenAI-style SSE chunks and data: [DONE].
toolsSupported for glm-5.3, glm-5.2, glm-5, kimi-k3, kimi-k2, deepseek-v4-pro, and deepseek-v4-flash.
tool_choiceSupported for normal function tools.
max_completion_tokensApplies an output limit when supplied; omitted requests use the model default.
max_tokensLegacy alias for max_completion_tokens.
temperatureSupported.
top_pSupported.
top_kSupported when available for the selected model.
seedSupported when available for the selected model.
stopSupported 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_format JSON mode and JSON Schema enforcement are not available.
  • frequency_penalty, presence_penalty, repetition_penalty, and logit_bias are not applied.
  • logprobs and top_logprobs are not returned.
  • reasoning and reasoning_effort are not exposed as public controls.
  • modalities, audio, and image_config are not supported by this text endpoint.
  • stream_options, service_tier, prediction, and parallel_tool_calls are 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.

RoleContent supportPurpose
systemString or OpenAI text partsApplication instructions and behavior constraints.
userString or OpenAI text partsUser input or task data.
assistantString content, tool_calls, or bothPrior assistant output or function calls.
toolString or OpenAI text parts plus matching tool_call_idResult 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",
  "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

FieldMeaning
idGLM 5-generated completion ID.
objectAlways chat.completion for non-streaming responses.
createdUnix timestamp in seconds.
modelPublic model ID used for the request.
choices[].indexChoice index. GLM 5 currently returns one choice.
choices[].message.roleUsually assistant.
choices[].message.contentAssistant text, or null when the model returns only tool calls.
choices[].message.tool_callsFunction calls requested by the model.
choices[].finish_reasonstop or tool_calls.
usage.prompt_tokensInput tokens counted for the completed request.
usage.completion_tokensOutput tokens counted for the completed request.
usage.total_tokensPrompt 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 or enforce one shared token window for every model. Use the final usage.prompt_tokens value for monitoring and handle any context or output-limit error returned for the selected model.

Finish Reasons

ValueMeaning
stopThe model finished normally.
tool_callsThe model requested one or more function calls.

For incremental output, see Streaming. For tool-call loops, see Function calling.