Migrate from OpenAI or Anthropic
The Router speaks the OpenAI API. Migrating an existing integration means changing the base URL and the key. Request bodies, response parsing, streaming, and tool calling stay as they are.
The whole change
Section titled “The whole change”-
Create an API key and fund the account — see Quickstart.
-
Set the base URL to
https://router-api.0g.ai/v1. -
Replace the model identifier with one from the 0G catalog.
Before:
curl https://api.openai.com/v1/chat/completions \ --fail-with-body --max-time 60 \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $OPENAI_API_KEY" \ -d '{ "model": "<OPENAI_MODEL_ID>", "messages": [{"role": "user", "content": "Hello"}] }'After:
curl https://router-api.0g.ai/v1/chat/completions \ --fail-with-body --max-time 60 \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $ZG_API_KEY" \ -d '{ "model": "glm-5", "messages": [{"role": "user", "content": "Hello"}] }'import OpenAI from "openai";
const apiKey = process.env.ZG_API_KEY;if (!apiKey) throw new Error("ZG_API_KEY is not set");
const client = new OpenAI({ // Was: the default OpenAI base URL and OPENAI_API_KEY baseURL: process.env.ZG_BASE_URL ?? "https://router-api.0g.ai/v1", apiKey, timeout: 60_000, maxRetries: 2,});
try { const res = await client.chat.completions.create({ model: "glm-5", // was: your OpenAI model id messages: [{ role: "user", content: "Hello" }], }); console.log(res.choices[0].message.content);} catch (err) { if (err instanceof OpenAI.APIError) { console.error(`Router error ${err.status} ${err.code}: ${err.message}`); } throw err;}import os
from openai import OpenAI, APIError
# Was: the default OpenAI base URL and OPENAI_API_KEYclient = OpenAI( api_key=os.environ["ZG_API_KEY"], base_url=os.environ.get("ZG_BASE_URL", "https://router-api.0g.ai/v1"), timeout=60.0, max_retries=2,)
try: res = client.chat.completions.create( model="glm-5", # was: your OpenAI model id messages=[{"role": "user", "content": "Hello"}], ) print(res.choices[0].message.content)except APIError as err: print(f"Router error {err.status_code}: {err.message}") raiseAnything that already speaks the OpenAI API — agent frameworks, orchestration libraries, gateways — takes the same two settings.
Extensions are additive
Section titled “Extensions are additive”The Router adds capabilities without changing the request schema you already send.
Routing lives in headers, not the body. Provider selection, trust tier, price ceilings, and failover behaviour are all controlled through X-0G-Provider-* request headers. Send none of them and you get sensible default routing. Because they are headers, a request body written for OpenAI stays valid. See the headers reference for the full set, and trust modes for the one that decides where your prompt runs.
Trace data is a new response block. Every response carries x_0g_trace with the request ID, the serving provider address, and the exact cost of that call. Standard fields are untouched, so a parser that reads choices and usage keeps working and simply ignores the addition.
Rate limit information is in response headers. Remaining request budget and reset time arrive as headers on every inference response, in the same style you are used to.
Choosing a model identifier
Section titled “Choosing a model identifier”Model identifiers differ from OpenAI’s. The catalog is a public endpoint — no authentication required:
curl https://router-api.0g.ai/v1/models{ "data": [ { "id": "glm-5", "type": "chatbot", "verifiability": "TeeTLS" } ]}Abridged from the live response, 2026-07-20 — each entry carries more fields than the three shown here. See Model catalog.
The verifiability field states which trust technology backs each model, which is what determines whether it can serve a given trust mode. The Console’s Models page lists the same catalog with current pricing and capabilities.
Coming from the Anthropic API
Section titled “Coming from the Anthropic API”If your integration speaks the Anthropic Messages API instead, the same migration applies: the Router serves the Messages format at /v1/messages on the same base URL, with the same Authorization: Bearer header as every other endpoint.
curl https://router-api.0g.ai/v1/messages \ --max-time 60 --fail-with-body \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $ZG_API_KEY" \ -d '{ "model": "claude-sonnet-5", "max_tokens": 256, "messages": [{"role": "user", "content": "Hello"}] }'A live call against claude-sonnet-5 returns the Anthropic shape — content, stop_reason, usage.input_tokens — with the 0G trace block appended, exactly as on the OpenAI surface:
{ "type": "message", "role": "assistant", "model": "claude-sonnet-5", "content": [{ "type": "text", "text": "OK." }], "stop_reason": "end_turn", "usage": { "input_tokens": 11, "output_tokens": 5, "service_tier": "standard" }, "x_0g_trace": { "request_id": "de4867d2-8b8a-4e17-b956-dd17a211bf84", "provider": "0x1F444c8A8D0b8e99A50e9f165806d28B01916E04", "billing": { "input_cost": "124080000000000", "output_cost": "282150000000000", "total_cost": "406230000000000" } }}Live response, 2026-07-20, abridged. Note the authentication difference from Anthropic’s own API: the Router uses Authorization: Bearer sk-… on every endpoint, not x-api-key. Point an Anthropic SDK at this base URL and set its auth accordingly, or call the endpoint directly.
Anthropic’s own client libraries authenticate with x-api-key by default, so pointing one at the Router means overriding both the base URL and the auth header. How that override is spelled differs by library and version; the endpoint itself is verified above, so a plain HTTP client is the fastest way to confirm your key and model before you fight a wrapper’s configuration.
Five models accept the Anthropic format:
| Model | Formats accepted |
|---|---|
claude-fable-5 |
Anthropic |
claude-opus-4-8 |
Anthropic |
claude-sonnet-5 |
Anthropic |
glm-5 |
OpenAI and Anthropic |
glm-5.2 |
OpenAI and Anthropic |
Because glm-5 and glm-5.2 accept both, they are the models to reach for when a codebase mixes the two client libraries and you would rather not maintain two model lists.
Next steps
Section titled “Next steps”- Quickstart — create a key and confirm the first call end to end.
- Headers reference — every routing header and its accepted values.
- Failover and retries — behaviour when a provider fails.