GLM API Guide: GLM-5.2, GLM-5.3 and GLM-5.3-Flash
Call GLM-5.2, GLM-5.3 and GLM-5.3-Flash through APIMaster with Python or curl. Tested Chat, Responses, Messages, streaming, JSON and tool calls.
Use glm-5.2, glm-5.3 or glm-5.3-flash with an APIMaster API key and the base URL https://apimaster.ai/v1. For OpenAI-compatible applications, start with Chat Completions. Codex uses Responses; Claude Code uses the Messages interface.
These are APIMaster gateway integration results, not a claim that every GLM upstream implements every protocol natively. GLM is the model family; OpenAI and Anthropic SDKs provide the client interfaces.
Tested compatibility
Validation started on 2026-09-15 UTC, using the public APIMaster endpoint and normal routing. Each model completed the following checks:
| Check | glm-5.2 |
glm-5.3 |
glm-5.3-flash |
|---|---|---|---|
| Chat Completions: regular and streaming | Passed | Passed | Passed |
| Responses: regular and streaming | Passed | Passed | Passed |
| Messages: regular and streaming | Passed | Passed | Passed |
| Function/tool call and tool-result round trip, all three protocols | Passed | Passed | Passed |
| Chat JSON object output | Passed | Passed | Passed |
Text tests checked the actual answer and the stream termination event, not only HTTP 200. Tool tests requested a weather function and then returned a verification code supplied only in the tool result. These are functional integration checks, not throughput benchmarks or an availability SLA. Long sessions, maximum context, video and every advanced parameter are outside this test matrix.
1. Get an API key
Create an APIMaster API key, enable the desired model and fund the account. Use the exact model IDs above. A key from BigModel, OpenAI or Anthropic cannot authenticate to APIMaster.
macOS / Linux:
export APIMASTER_API_KEY='YOUR_APIMASTER_API_KEY'
Windows PowerShell:
$env:APIMASTER_API_KEY = 'YOUR_APIMASTER_API_KEY'
2. Call Chat Completions with curl
curl --fail-with-body --max-time 120 'https://apimaster.ai/v1/chat/completions' \
-H "Authorization: Bearer $APIMASTER_API_KEY" \
-H 'Content-Type: application/json' \
-d '{"model":"glm-5.3-flash","messages":[{"role":"user","content":"Reply with exactly GLM_API_OK."}],"max_tokens":2048}'
Read choices[0].message.content. Change model to glm-5.2 or glm-5.3 to switch models. Reasoning models may consume part of the output budget before emitting the final answer.
3. Use the Python OpenAI SDK
python -m pip install -U openai
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["APIMASTER_API_KEY"],
base_url="https://apimaster.ai/v1",
timeout=120.0,
)
response = client.chat.completions.create(
model="glm-5.3-flash",
messages=[{"role": "user", "content": "Reply with exactly GLM_API_OK."}],
max_tokens=2048,
)
print(response.choices[0].message.content)
For streaming, set stream=True. Check for empty choices: the final usage chunk can contain usage without a text delta.
stream = client.chat.completions.create(
model="glm-5.3-flash",
messages=[{"role": "user", "content": "Explain binary search briefly."}],
max_tokens=4096,
stream=True,
stream_options={"include_usage": True},
)
for chunk in stream:
if chunk.choices:
text = chunk.choices[0].delta.content
if text:
print(text, end="", flush=True)
if chunk.usage:
print("\nUsage:", chunk.usage)
The first event may contain reasoning rather than visible answer text. Preserve reasoning_content when carrying assistant messages into a tool conversation on routes that return it; do not reconstruct the assistant message from final text alone.
4. Choose the correct endpoint
| Application | Base URL | Request endpoint |
|---|---|---|
| Python OpenAI SDK / Chat | https://apimaster.ai/v1 |
/v1/chat/completions |
| Responses API / Codex | https://apimaster.ai/v1 |
/v1/responses |
| Claude Code | https://apimaster.ai |
/v1/messages |
Minimal Responses request:
curl --fail-with-body --max-time 120 'https://apimaster.ai/v1/responses' \
-H "Authorization: Bearer $APIMASTER_API_KEY" \
-H 'Content-Type: application/json' \
-d '{"model":"glm-5.3","input":"Reply with exactly GLM_API_OK.","max_output_tokens":2048}'
Read text from message items whose content type is output_text; keep reasoning items separate. For streaming, use stream: true and check for response.completed or an error event.
Parameters and troubleshooting
| Situation | Recommended action |
|---|---|
| 401 | Check the APIMaster key and the account that issued it. |
| 404 | Use the base URL expected by your client; do not duplicate /v1. |
| Empty answer or output limit | Inspect the finish reason and reasoning usage; increase the output budget. |
| JSON output | Chat response_format: {"type":"json_object"} passed a basic JSON test. Validate the returned JSON in your application. |
reasoning.summary rejected |
Support depends on the selected upstream. Omit it for the baseline configuration. A successful gateway test does not establish native BigModel support. |
thinking.type: disabled rejected |
The official GLM-5.3-Flash model guide permits only enabled; do not require thinking to be disabled. |
| 429 / 5xx / interrupted stream | Record the request ID, model, UTC time and error. Use bounded retries where safe; do not repeat executed tools blindly. |
Frequently asked questions
Is GLM-5.3-Flash free on APIMaster?
The word Flash is part of the model name, not a promise of free usage. Check the model marketplace for current route prices and the wallet for actual charges.
Does a high cache hit rate apply to every request?
No. Cache reuse depends on matching input prefixes and the upstream. Inspect returned usage and your usage logs. A previous workload's cache hit rate is not a guarantee for a new application.
Does this prove full OpenAI or Anthropic compatibility?
It establishes the tested text, streaming, JSON and tool workflows. Provider-specific fields, stored Responses state, built-in web search and multimedia require separate validation.