Skip to content

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.

  1. Create an API key and fund the account — see Quickstart.

  2. Set the base URL to https://router-api.0g.ai/v1.

  3. Replace the model identifier with one from the 0G catalog.

Before:

Terminal window
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:

Terminal window
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"}]
}'

Anything that already speaks the OpenAI API — agent frameworks, orchestration libraries, gateways — takes the same two settings.

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.

Model identifiers differ from OpenAI’s. The catalog is a public endpoint — no authentication required:

Terminal window
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.

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.

Terminal window
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.