The handbook.
Everything you need to point OpenAI SDKs, Codex, Claude Code, and OpenAI-compatible clients at EastRouter in under two minutes.
Quickstart
Three lines of config.
Any OpenAI SDK works. Change base_url to https://api.eastrouter.com/v1, paste your sk-er_… key, and pick a model.
Public base URLs: OpenAI SDKs and Codex use https://api.eastrouter.com/v1. Claude Code uses https://api.eastrouter.com/api/anthropic.
from openai import OpenAI
client = OpenAI(
api_key="sk-er_k_7f3a9c2d_•••••",
base_url="https://api.eastrouter.com/v1",
)
response = client.chat.completions.create(
model="z-ai/glm-5.2",
messages=[{"role": "user",
"content": "Refactor this for me."}],
stream=True,
)import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.EASTROUTER_API_KEY,
baseURL: "https://api.eastrouter.com/v1",
});
const reply = await client.chat.completions.create({
model: "z-ai/glm-5.2",
messages: [{ role: "user", content: "Refactor this for me." }],
});curl https://api.eastrouter.com/v1/chat/completions \
-H "Authorization: Bearer $EASTROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "z-ai/glm-5.2",
"messages": [{"role": "user", "content": "Refactor this for me."}]
}'You'll need a key first. Get an API key, or see pricing.
Codex
Codex uses the OpenAI Responses API. Point its custom provider at the same public EastRouter base URL:
model_provider = "eastrouter"
model = "z-ai/glm-5.2"
[model_providers.eastrouter]
name = "EastRouter"
base_url = "https://api.eastrouter.com/v1"
env_key = "EASTROUTER_API_KEY"
wire_api = "responses"
# shell
export EASTROUTER_API_KEY="sk-er_..."Claude Code
Claude Code uses the Anthropic-compatible surface. Use your EastRouter key as the Anthropic auth token:
{
"env": {
"ANTHROPIC_AUTH_TOKEN": "sk-er_...",
"ANTHROPIC_BASE_URL": "https://api.eastrouter.com/api/anthropic",
"API_TIMEOUT_MS": "3000000"
}
}Authentication
Bearer tokens, OpenAI-compatible.
EastRouter uses the same Authorization: Bearer … header shape as OpenAI. Your key looks like:
sk-er_<key_id>_<secret>The key_id is a plaintext lookup; the secret is cryptographically hashed at rest and never stored in readable form. Treat the whole string as a secret — anyone with it can spend your credit.
Rotating a key
Generate a new key in the dashboard, swap it in your environment, then revoke the old one. Revoking takes effect on the next request — there is no key cache to invalidate.
Endpoints
The surface area.
OpenAI/Codex clients use https://api.eastrouter.com/v1. Claude Code uses https://api.eastrouter.com/api/anthropic. The model field accepts the IDs in our catalog — z-ai/glm-5.2 being the recommended default for hard tasks.
| Method and path | What it does |
|---|---|
| POST /v1/chat/completions | OpenAI-compatible chat completions. Streaming + non-streaming. Reasoning tokens supported. |
| POST /v1/responses | OpenAI Responses-compatible facade for Codex and newer OpenAI clients. |
| POST /api/anthropic/v1/messages | Anthropic-compatible Claude Code endpoint. Also available as /v1/messages. |
| POST /api/anthropic/v1/messages/count_tokens | Counts tokens for Claude Code. |
| GET /api/anthropic/v1/models | Claude Code model metadata utility endpoint. |
| GET /v1/models | List the models available to your key. |
| GET /v1/balance | Current credit balance. EastRouter extension — not on OpenAI. |
Compatibility aliases
These aliases work the same way, with the same billing and balance:
| Alias | Use when |
|---|---|
| /api/v1/chat/completions | A client hardcodes an /api/v1 prefix. |
| /api/coding/paas/v4/chat/completions | A coding tool hardcodes a /coding/paas/v4 prefix. |
| /codex/v1/chat/completions | You want an explicit Codex-labeled chat-completions alias. |
Streaming
SSE, byte-identical.
Pass stream=True (Python) or stream: true (Node) and you'll get a Server-Sent Events stream with the same chunk envelope OpenAI uses — same choices[0].delta.content shape, same [DONE] sentinel, same usage block on the final chunk.
Reasoning tokens
Reasoning models stream their reasoning by default. EastRouter normalises the field name to choices[0].delta.reasoning so OpenRouter-compatible clients see what they expect.
To opt out, send reasoning: { "effort": "none" } in your request.
When a request fails
Failed requests are retried for you.
Every request checks your balance before it runs. If a model is busy, times out or returns an error that can be retried, EastRouter retries it within the same request, so your code needs no retry logic of its own.
Claude Code uses the Anthropic-compatible endpoint; OpenAI SDKs, Codex and other coding tools use the OpenAI-compatible one. Either way, your key, balance and request log are the same.
API reference
Request & response.
Request body
| Field | Type | Notes |
|---|---|---|
| model | string | Required. e.g. z-ai/glm-5.2. See catalog. |
| messages | array | Standard OpenAI roles: system, user, assistant, tool. |
| stream | boolean | Defaults to false. Streaming uses SSE. |
| temperature | number | 0.0–2.0. Passed through unchanged. |
| max_tokens | integer | Caps output length. Also used to check your key’s daily cap before the request runs. |
| tools | array | OpenAI tool-calling schema. GLM, Kimi, MiniMax all support it. |
| reasoning | object | { "effort": "none" | "minimal" | "medium" | "high" }. Sets how much the model thinks before it answers. |
Response, non-streaming
{
"id": "chatcmpl-...",
"object": "chat.completion",
"model": "z-ai/glm-5.2",
"choices": [{
"index": 0,
"message": { "role": "assistant", "content": "..." },
"finish_reason": "stop"
}],
"usage": {
"prompt_tokens": 142,
"completion_tokens": 87,
"total_tokens": 229,
"prompt_tokens_details": { "cached_tokens": 0 }
}
}SDKs & tools
Your stack, unchanged.
EastRouter has no SDK of its own to install. Anything that speaks the OpenAI API, or the Anthropic API in Claude Code's case, works once it points at EastRouter with your sk-er_… key.
OpenAI SDK
Python
JavaScript
TypeScript
Go
Rust
cURL
Claude Code
Codex CLI
Cline
RooCode
Which base URL to use
| Client | Base URL |
|---|---|
| OpenAI SDK (Python, JavaScript, TypeScript) | https://api.eastrouter.com/v1 |
| Codex CLI | https://api.eastrouter.com/v1 |
| Cline, RooCode | https://api.eastrouter.com/v1 |
| Go, Rust, cURL and other HTTP clients | https://api.eastrouter.com/v1 |
| Claude Code | https://api.eastrouter.com/api/anthropic |
OpenAI SDKs
The official Python and JavaScript SDKs read their settings from the environment, so existing code can stay as it is:
OPENAI_BASE_URL=https://api.eastrouter.com/v1
OPENAI_API_KEY=sk-er_k_7f3a9c2d_•••••Other languages work the same way: use any OpenAI-compatible client library and set its base URL, or call the endpoints directly as in the cURL quickstart.
Coding agents
Claude Code talks to the Anthropic-compatible endpoint:
export ANTHROPIC_BASE_URL=https://api.eastrouter.com/api/anthropic
export ANTHROPIC_AUTH_TOKEN=sk-er_k_7f3a9c2d_•••••Cline and RooCode: choose the OpenAI-compatible provider in the tool's settings, then enter the base URL, your key and a model ID from the catalog.
Codex CLI: point it at the /v1 base URL; it uses the Responses-compatible endpoint listed under Endpoints.
Migration
From OpenRouter, in two lines.
If your client already points at OpenRouter, you change two strings:
| OpenRouter | EastRouter |
|---|---|
| https://openrouter.ai/api/v1 | https://api.eastrouter.com/v1 |
| sk-or-v1-... | sk-er_..._... |
| model: "z-ai/glm-5.2" | model: "z-ai/glm-5.2" (same) |
Model IDs are 1:1 with OpenRouter's. Response schemas are identical. Provider-prefixed headers (HTTP-Referer, X-Title) are accepted but ignored.
Start building with Asia’s best AI models.
One key for GLM, Kimi, DeepSeek and MiniMax, at 50% off. Qwen on request.