GLM-5 is the new generation of general-purpose models in Zhipu's GLM family. Teams usually have three questions: where to get a key, what to put in the base URL, and whether an existing OpenAI SDK can be reused. The answer to the last one is usually yes. GLM has offered an OpenAI-compatible interface for a long time, and in most integrations you only change three things: the base URL, the key, and the model name.

This article follows the integration order. It first explains what the GLM-5 API is, then walks through getting a key and making a working request, and finishes with troubleshooting and cost-control checklists.

Note: Zhipu and GLM are trademarks of their respective owners. This article is for technical integration only. Model names, context lengths, and billing rules are subject to the official documentation and the model pricing page. Verify model names in the console before using the examples below.

1. What the GLM-5 API is

The GLM-5 API is the model invocation interface that Zhipu's open platform provides to developers. Common capabilities include:

  • Multi-turn conversation and instruction following;
  • Long-document summarization, rewriting, and translation;
  • Structured extraction and JSON output;
  • Code generation and code explanation;
  • Reasoning nodes in agents and workflows.

It is not the same product as the web app. The web app is billed as an account subscription, while the API is billed by token or call volume. A key is only an invocation credential; it does not represent membership benefits. Before integrating, define your use case, concurrency, and budget, then decide whether to use the official platform or an aggregation gateway.

2. Two paths to a GLM API key

Path one: the Zhipu open platform

  1. Register and sign in to the Zhipu open platform, then complete individual or enterprise verification as required by the platform.
  2. Create an API key in the console and name it by project or environment.
  3. Check the account balance and available models, and top up first if needed.
  4. Store the key in a server-side environment variable. Never ship it to the front end.

The official base URL is usually https://open.bigmodel.cn/api/paas/v4. Check the current official documentation for the exact value.

Path two: the ZSQH AI Gateway

If you already use several models, or want unified billing and key management, register for the ZSQH AI Gateway, create a key, and confirm on the model pricing page whether the GLM family is enabled and how the model names are written.

Neither path is inherently better. If you use one model and official access is reliable, direct access is simpler. If you need to switch between models, unify quotas, and use a stable entry point in mainland China, a gateway saves operational work.

3. OpenAI-compatible configuration

GLM's interface closely resembles OpenAI Chat Completions. Migration mainly involves three changes:

Setting Official direct ZSQH AI Gateway
Base URL https://open.bigmodel.cn/api/paas/v4 https://ai.zhongshangqihang.com/v1
API key Created on the Zhipu platform Created in the gateway console
Model name Per official documentation Per the on-site pricing page
SDK OpenAI SDK works OpenAI SDK works

Pay attention to the end of the base URL. Some SDKs append /chat/completions automatically, while others require the full path. Mixing official and gateway addresses most often produces a 401 or 404.

4. Calling with curl

export ZSQH_API_KEY="sk-your-key"

curl "https://ai.zhongshangqihang.com/v1/chat/completions" \
  -H "Authorization: Bearer $ZSQH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "glm-5",
    "messages": [
      {"role": "system", "content": "You are a technical editor. Be specific."},
      {"role": "user", "content": "Explain in three points what kinds of teams benefit from an API gateway"}
    ],
    "temperature": 0.6,
    "max_tokens": 800
  }'

Replace model with the GLM-5 model identifier actually available on the pricing page. If you get model not found, check the letter case and the version suffix first.

5. Calling from Python

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["ZSQH_API_KEY"],
    base_url="https://ai.zhongshangqihang.com/v1",
)

resp = client.chat.completions.create(
    model="glm-5",  # check the on-site pricing page
    messages=[
        {"role": "system", "content": "You are a customer service QA assistant. Output JSON only."},
        {"role": "user", "content": "Classify the sentiment: The shipping was slow, but the support agent was helpful."},
    ],
    temperature=0.2,
    response_format={"type": "json_object"},
)

print(resp.choices[0].message.content)

Older SDK versions may not support response_format; upgrade the openai package first. If the gateway does not support JSON mode, constrain the output format in the prompt and add a parsing fallback in your code.

6. How to choose a model name

The GLM family usually includes general-purpose, lightweight, and reasoning branches at the same time, and names carry version numbers and date suffixes. Selection guidance:

Use case Selection approach Considerations
Support, summaries, rewriting General chat model Start with a low temperature
Complex reasoning, math Reasoning-enhanced model Slower and consumes more tokens
High-concurrency classification Lightweight model Measure accuracy before scaling
Code tasks Version with stronger code ability Watch truncation with long contexts

Which model names are available, how long the context is, and what each costs should all come from the on-site pricing page. Do not copy old model names from online tutorials; GLM versions change quickly.

7. Common errors

Error Common cause What to do
401 Unauthorized Wrong key, missing Bearer, deleted key Copy the key again and check the request header
404 Not Found Extra or missing /v1 in the base URL Use the address from the documentation consistently
model not found Model name does not exist or is not permitted Copy the model name from the pricing page
429 Too Many Requests Concurrency or frequency limit exceeded Reduce concurrency and retry with exponential backoff
insufficient balance Not enough balance Top up or switch keys
Response interrupted Timeout, network, or long output Increase the timeout and stream the output

Start troubleshooting with authentication: verify the key with the smallest possible request, then verify the model name, and only then suspect the network. This avoids repeatedly editing code in the wrong place.

8. Cost control

  1. Set max_tokens so the model cannot generate indefinitely.
  2. Keep system prompts lean; cache or template long instructions that repeat.
  3. Use a lightweight model for batch jobs and upgrade only for hard cases.
  4. Record token usage per request and split billing by business line.
  5. Set spending limits on keys so abnormal calls stop automatically.
  6. Run a peak-load test before launch to confirm the rate-limit threshold.

Cost is not just the unit price. Retries, long contexts, and wasted output all inflate the bill. Bring success rates up and average token usage down before worrying about unit price.

9. Security and team collaboration

  • Split keys by environment: one each for test, staging, and production, with no reuse.
  • Split keys by project so you can measure tokens and spend for each business line.
  • Keep keys in server-side environment variables or a secrets manager, never in Git or front-end bundles.
  • Do not log full keys or raw user text; redact them when necessary.
  • Set quota alerts and notify the owner when the balance drops below a threshold.
  • Disable and rotate keys immediately when staff change or a key leaks.

The most common risk in a team is not the model itself but a key copied into a chat tool, a document, or front-end code. Adding one rule to the integration process — keys only exist on the server — is far cheaper than investigating an incident later.

FAQ

Can the GLM-5 API use the OpenAI SDK directly?

In most cases yes. Change base_url, api_key, and model. A few parameters, such as certain reasoning switches and multimodal fields, may not be compatible; check the official or on-site documentation.

Is a GLM API key the same as a web membership?

No. A web membership is a product subscription, while an API key is a developer credential. Billing and permissions are managed separately.

Can one key call other models at the same time?

On the ZSQH AI Gateway, one key can call multiple enabled models, and the model is specified in the request. See the pricing page and console for the exact scope.

Does calling from mainland China require extra configuration?

It depends on your network environment and the terms of service. For production, add timeouts, retries, and a backup channel rather than sending every request to a single entry point.

Next steps

Register for the ZSQH AI Gateway, create a test key, verify the smallest possible request with curl, and then connect your business code. Model names and prices are subject to model pricing.

Related reading: