Quick Start
Make your first OpenAI-compatible GLM 5 API request in a few minutes.
OpenAI SDK compatible
Keep your existing OpenAI SDK for the documented Chat Completions subset, then
change the API key, base URL, and model. For most new integrations, start with
glm-5.3.
OpenAI-compatible API reference, focused for GLM 5
The GLM 5 API uses an OpenAI-compatible Chat Completions interface: send a
bearer-authenticated JSON request to the versioned /chat/completions endpoint,
provide a model and messages, and read the response from choices and
usage.
The reference pages in these docs follow that same structure: request body, message format, response fields, streaming chunks, tool calls, models, errors, limits, and billing. GLM 5 keeps the compatible shape but exposes a curated, predictable model surface:
- Use
https://glm5.app/api/v1as the base URL. - Use a model ID returned by
GET /models, such asglm-5.3. - Use
max_completion_tokensfor new code. The legacymax_tokensfield still works for existing OpenAI-compatible clients. - Use
stream: truewhen you want Server-Sent Events and handledata: [DONE]. - Use
toolsandtool_choicefor function calling on models that support tools.
Only the parameters documented in this API reference are guaranteed to affect request behavior. For the supported request fields, see Chat Completions.
Using an OpenAI-compatible client?
Set the base URL to https://glm5.app/api/v1, authenticate with your
sk-glm5-... key, and choose a model ID returned by GET /models, such as
glm-5.3.
Getting started
Create an API key
Sign in, open API Keys, and create a key for your application. The full key is shown once, so store it in a password manager or secret store.
GLM5_API_KEY=sk-glm5-your-key
Never expose an API key in browser code, public repositories, screenshots, or client-side environment variables.
Choose a model
glm-5.3 is the recommended default for coding, reasoning, agent workflows,
and long-form tasks. Use a different model when its price or behavior better
fits your application.
Choose a calling method
Call the REST endpoint directly or use the official OpenAI SDK. Both use the documented Chat Completions parameters and return the same response shape.
Make your first request
https://glm5.app/api/v1/chat/completionsBearer authentication · JSON request and response
max_completion_tokens is optional. Set it when your application needs a
predictable response length; omit it to use the selected model's default.
GLM 5 may reserve credits using an internal estimate for billing, but that
estimate does not change the requested output limit.
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": "You are a concise technical assistant."
},
{
"role": "user",
"content": "Give me a three-step API launch checklist."
}
],
"max_completion_tokens": 1024
}'
Compatibility scope
GLM 5 implements the documented Chat Completions subset. Extra SDK fields may be accepted, but only the fields listed in this reference are guaranteed to affect request behavior. Check Chat Completions before depending on a parameter.
Keep context costs predictable
Chat Completions is stateless
Every request is billed for all messages you send in that request. If your client resends the complete conversation on every turn, the input grows and the same history is charged again. Keep a bounded history, summarize older turns, and start a new conversation when earlier context is no longer needed.
For predictable billing:
- Set
max_completion_tokenswhen your workflow needs a predictable output cap. - Monitor the
usage.prompt_tokensandusage.completion_tokensfields. - Do not append unlimited chat history.
- Handle context-limit errors because supported models can have different limits.
- Use streaming for responsiveness, not as a way to reduce input-token cost.
Read Context and cost control before connecting an autonomous agent or a long-running chat client.