2026-11-04 · Prompt Tutorials
Plenty of people chat comfortably in the GLM web playground, then stall the moment they hit the API: where do I get a key, which model name do I use, does my prompt need reformatting? The jump from web to API is really just three steps: sign up on the platform, grab an API key, and move the prompt you tuned in the playground into a request body. Follow along and you'll have a working call in minutes.
GLM's web version and API are two separate entry points. The playground is for trying ideas and tuning tone; the API goes through the BigModel open platform (open.bigmodel.cn — international users should also check the official site for global access details, subject to the official pages). Register, then create an API key in the console — it may only be shown once, so store it safely and never hardcode it into frontend code or public repos. Your key is tied to billing; leaking it is like handing over your wallet.
Take a look at the model list while you're there: the GLM-5 series is the flagship line, while the GLM-4 family covers multimodal use cases like vision understanding. A simple rule of thumb: pick a cost-effective model for everyday text tasks, and move up to the flagship for complex reasoning, coding, and agent work. Exact model names and availability are subject to the platform pages.
curl is the clearest way to see what's happening. This request uses the model as a translator — copy it and swap in your key:
bash
curl https://open.bigmodel.cn/api/paas/v4/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "glm-4-plus",
"messages": [
{"role": "system", "content": "You are a professional Chinese-English translator. Output only the translation, no explanations."},
{"role": "user", "content": "Translate to English: Since this feature launched, support tickets dropped by half."}
],
"temperature": 0.3
}'
A few fields worth remembering: model is the model name — check the platform docs for current values. messages is the conversation array: system sets the role and rules, user carries the actual task. Keep temperature low (0.2–0.4) for translation or extraction where consistency matters; raise it toward 0.8 for creative copy.
Don't leave a well-tuned prompt buried in chat history — turn it into a reusable template. This structured prompt works well in both Chinese and English; just replace the 【】 placeholders:
# Role
You are a senior assistant for [domain, e.g., cross-border e-commerce].
Respond in the language of the user's input (Chinese in → Chinese out, English in → English out).
# Task
Apply the following action to the text below:
[action, e.g., rewrite in English with a natural Western e-commerce tone]
# Source text
[paste text]
# Requirements
1. Preserve all numbers, model codes, and proper nouns exactly;
2. Output JSON: {"result": "rewritten text", "notes": "one sentence on trade-offs"};
3. Do not add information absent from the source.
Specifying JSON output is a key trick when working through the API — your code can parse it directly instead of scraping answers with regex.
Once your first call succeeds, most problems fall into three buckets:
Bearer .temperature, or add "output JSON only, no extra text" to the system message.The model itself can help you debug. Paste a failed request and its error into this troubleshooting template:
You are an API debugging assistant. I will give you one failed API request and its error response.
[Request body]
{...paste request JSON...}
[Error response]
{...paste error response...}
Answer in order:
1. The most likely cause (one sentence);
2. A corrected, copy-ready request body;
3. If information is insufficient, list what I still need to confirm.
With the first request working, three directions are worth exploring: tool calling (function calling), letting the model check the weather or hit your own endpoints — the foundation for building agents, with GLM-series support details per official docs; tapping GLM-4 multimodal capabilities for image-understanding tasks; and if you code a lot, checking whether the Coding Plan subscription beats pay-as-you-go for your usage — benefits are subject to the official pages.
Moving from playground to API is really the shift from "chatting by hand" to "programmatic calls." Solidify your tuned prompts into templates, constrain outputs into structure, and your first request stops being a dry run — it becomes the seed of something you can build a product on.
本文为使用方法整理,内容选自网上公开资料,供参考;本站为非官方资讯站,产品能力以官方页面为准。