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.2.

OpenRouter-style API reference, focused for GLM 5

If you have used OpenRouter, the integration model should feel familiar: send a bearer-authenticated JSON request to a versioned /chat/completions endpoint, provide a model and messages, and read an OpenAI-compatible response with 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/v1 as the base URL.
  • Use GLM 5 model IDs such as glm-5.2, not provider-prefixed slugs like openai/gpt-5.2.
  • Use max_completion_tokens for new code. The legacy max_tokens field still works for existing OpenAI/OpenRouter-style clients.
  • Use stream: true when you want Server-Sent Events and handle data: [DONE].
  • Use tools and tool_choice for function calling on models that support tools.

OpenRouter-specific routing and marketplace features such as models, route, provider, plugins, transforms, app attribution headers, and web-search plugins are documented in Chat Completions as accepted but not applied by GLM 5.

Base URLhttps://glm5.app/api/v1OpenAI-compatible
Recommended modelglm-5.2Coding, reasoning & agents
Context and outputProvider-managedNo GLM 5 token cap

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.

.env
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.2 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

POSThttps://glm5.app/api/v1/chat/completions

Bearer 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 provider's default.

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": "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 OpenAI or OpenRouter fields may be accepted by SDKs, but they are not guaranteed to be forwarded by this API. 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_tokens when your workflow needs a predictable output cap.
  • Monitor the usage.prompt_tokens and usage.completion_tokens fields.
  • Do not append unlimited chat history.
  • Handle provider context-limit errors because each upstream model and provider can enforce a different window.
  • 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.

Explore more