How to Use the GLM-5.2 API: Quickstart Guide
Get started with the GLM-5.2 API in under 2 minutes. OpenAI-compatible endpoint, code examples in curl, Python, and Node.js.
GLM-5.2 is one of the most cost-effective AI models available today, which makes it a strong choice for high-volume tasks. On Ruvicode it costs well below the official list price, and the GLM-5.2 model page shows the live rate next to the official one.
What is GLM-5.2?
GLM-5.2 is a frontier model from Z.ai (Zhipu AI) with a 1M token context window, up to 128K output tokens, strong reasoning capabilities, and tool-use support. It's particularly good at:
- General chat and conversation
- Code generation and debugging
- Document analysis with long context
- Multi-step reasoning
Quickstart
Ruvicode provides an OpenAI-compatible endpoint, so you can use any OpenAI SDK, just change the base URL and API key.
curl
curl https://api.ruvicode.com/v1/chat/completions \
-H "Authorization: Bearer rvcd_..." \
-H "Content-Type: application/json" \
-d '{
"model": "glm-5.2",
"messages": [{"role": "user", "content": "Hello!"}]
}'Python
from openai import OpenAI
client = OpenAI(
api_key="rvcd_...",
base_url="https://api.ruvicode.com/v1"
)
response = client.chat.completions.create(
model="glm-5.2",
messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)Node.js
import OpenAI from "openai";
const client = new OpenAI({
apiKey: "rvcd_...",
baseURL: "https://api.ruvicode.com/v1",
});
const response = await client.chat.completions.create({
model: "glm-5.2",
messages: [{ role: "user", content: "Hello!" }],
});Streaming
For streaming responses, set stream: true:
stream = client.chat.completions.create(
model="glm-5.2",
messages=[{"role": "user", "content": "Write a haiku about APIs"}],
stream=True
)
for chunk in stream:
if not chunk.choices:
continue # the final chunk carries usage and no choices
print(chunk.choices[0].delta.content or "", end="")Using GLM-5.2 with Cursor
Point Cursor at Ruvicode by setting the base URL in your settings:
- Open Cursor Settings (Ctrl+Shift+J) and go to the Models tab
- Under API Keys, enable OpenAI API Key and paste your Ruvicode API key
- Turn on Override OpenAI Base URL and enter
https://api.ruvicode.com/v1 - Add
glm-5.2with + Add Model, then click Verify
Cost estimation
A request costs its input tokens times the input rate plus its output tokens times the output rate. For a typical chat request with 1,000 input and 500 output tokens, that is 0.001 times the input rate per million plus 0.0005 times the output rate per million. Plug in the live rates from the model page, or let the cost calculator do it for a whole workload.
Every response reports the exact charge in usage.cost, streaming included (the final chunk carries it). Non-streaming responses also send it as an X-Cost header.
Get started
Sign up to get your API key. Once you have one, the dashboard playground lets you try GLM-5.2 before you write any code.