DEV Community

RouterBase for RouterBase

Posted on

Call GLM-5.2 from the OpenAI Python SDK with RouterBase

GLM-5.2 is live on RouterBase. If you already use the OpenAI Python SDK, you do not need another client library. Keep the SDK, change the base URL, and use the exact live model ID.

Prerequisites

  • Python 3.9 or later
  • A RouterBase API key stored as ROUTERBASE_API_KEY
  • The current openai package
pip install openai
Enter fullscreen mode Exit fullscreen mode

Make the call

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["ROUTERBASE_API_KEY"],
    base_url="https://routerbase.com/v1",
)

response = client.chat.completions.create(
    model="zai/glm-5-2/chat",
    messages=[
        {
            "role": "system",
            "content": "You are a careful software engineering assistant.",
        },
        {
            "role": "user",
            "content": "Give me a five-point review checklist for a risky database migration.",
        },
    ],
    max_tokens=800,
)

print(response.choices[0].message.content)
Enter fullscreen mode Exit fullscreen mode

The two RouterBase-specific values are:

base_url = https://routerbase.com/v1
model = zai/glm-5-2/chat
Enter fullscreen mode Exit fullscreen mode

Do not shorten the model name to glm-5.2. RouterBase's live model page currently exposes the full ID zai/glm-5-2/chat, and exact IDs prevent an integration from silently pointing at the wrong route.

Before sending a million-token prompt

Z.ai documents a 1M-token context window for GLM-5.2. That is a ceiling, not a recommended starting prompt.

Start with a smaller baseline, then increase context while recording:

  1. Time to first token and total wall-clock time.
  2. Whether the answer uses the right evidence from the prompt.
  3. Tool-call failures and retry behavior.
  4. Whether tool state survives a long, multi-step run.
  5. Cost per successful task, not only cost per token.

A longer context window reduces some chunking pressure, but it does not replace retrieval tests, observability, or a fallback path.

Scope and limitations

This quickstart verifies the current RouterBase base URL and model ID. It does not claim a benchmark ranking, a latency target, or a fixed price. Those values can change, so check the live model page before a production rollout.

Top comments (0)