All insights

Model APIs

GLM 5.2 API Key: Get One and Make Your First Request

Learn where to create a Z.ai Standard API key for GLM-5.2, how to send a minimal chat-completions request, and what to check if it fails.

Illustration for Glm 5.2 api key

Where to get a GLM-5.2 API key

For direct access through Z.ai, sign in to the Z.AI Open Platform, open API Keys, and create a Standard API Key. If your account needs funds or a usage bundle, check the billing page before making calls. Z.ai lists GLM-5.2 in its model documentation and documents a general API endpoint for model requests. (docs.z.ai)

Use a Standard API Key for the standard model API. Z.ai manages Standard API, Individual Coding Plan, and Team Plan keys separately; the key type determines which usage or billing applies, and the keys are not interchangeable. Z.ai’s Coding Plan FAQ currently names GLM-5.3 and GLM-5.3-Flash as supported plan models, so don’t assume a Coding Plan key or quota provides GLM-5.2 access. (docs.z.ai)

Make a minimal GLM-5.2 API request

The example below uses Z.ai’s documented general chat-completions endpoint, Bearer authentication, and the glm-5.2 model code. It uses the standard API route—not the separate Coding Plan endpoint. (docs.z.ai)

Prerequisite: create a Standard API Key as described above. In a terminal, set it as an environment variable, then send a request:

export ZAI_API_KEY='your_zai_standard_api_key'

curl --request POST \
  --url 'https://api.z.ai/api/paas/v4/chat/completions' \
  --header "Authorization: Bearer $ZAI_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
    "model": "glm-5.2",
    "messages": [
      {"role": "user", "content": "Reply with: GLM-5.2 API connection successful."}
    ],
    "stream": false
  }'

A successful chat-completions response is JSON with a choices array; look for the generated text at choices[0].message.content. The response schema also includes a model field, which you can inspect when confirming the response. This is a documentation-based example, not a reported live test. (docs.z.ai)

If the request fails

  • 401 authentication error: Check that the key is present, copied correctly, and sent as Authorization: Bearer …. Z.ai documents 401 errors for failed or missing authentication. (docs.z.ai)
  • 400 unknown model: Check the spelling of glm-5.2 and confirm the model is available to the key and API route you chose. Z.ai documents an “Unknown Model” error for an unrecognized model code. (docs.z.ai)
  • 429 insufficient balance or no resource package: Check the Standard API account’s billing balance or applicable usage bundle. A Coding Plan subscription is a separate key and billing path. (docs.z.ai)

Keep the key private: use an environment variable or secret manager, and don’t commit the key to source control. If you use a gateway instead of Z.ai directly, create that gateway’s key and use its own documented endpoint and model identifier; provider keys and endpoints are not interchangeable.

Sources

Z.AI Quick Start

Z.AI API Key Management Guide

Z.AI GLM-5.2 Overview

Z.AI API Introduction

Z.AI Chat Completion API

Z.AI API Errors

Z.AI Coding Plan FAQ

Contact us