The handbook.

Everything you need to point OpenAI SDKs, Codex, Claude Code, and OpenAI-compatible clients at EastRouter in under two minutes.

01 · Quickstart

Three lines of config.

The OpenAI Python SDK is the canonical client. 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,
)

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:

~/.codex/config.toml
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:

~/.claude/settings.json
{
  "env": {
    "ANTHROPIC_AUTH_TOKEN": "sk-er_...",
    "ANTHROPIC_BASE_URL": "https://api.eastrouter.com/api/anthropic",
    "API_TIMEOUT_MS": "3000000"
  }
}

02 · Authentication

Bearer tokens, OpenAI-compatible.

EastRouter uses the same Authorization: Bearer … header shape as OpenAI. Your key looks like:

Key format
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.

03 · 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 · PathWhat it does
POST /v1/chat/completionsOpenAI-compatible chat completions. Streaming + non-streaming. Reasoning tokens supported.
POST /v1/responsesOpenAI Responses-compatible facade for Codex and newer OpenAI clients.
POST /api/anthropic/v1/messagesAnthropic-compatible Claude Code endpoint. Also available as /v1/messages.
POST /api/anthropic/v1/messages/count_tokensClaude Code utility endpoint, proxied to the active coding backend.
GET /api/anthropic/v1/modelsClaude Code model metadata utility endpoint.
GET /v1/modelsList the models available to your key.
GET /v1/balanceCurrent credit balance. EastRouter extension — not on OpenAI.

Compatibility aliases

These public aliases route through the same billing, balance, and automatic dispatch path:

AliasUse when
/api/v1/chat/completionsA client hardcodes an /api/v1 prefix.
/api/coding/paas/v4/chat/completionsA coding tool hardcodes a /coding/paas/v4 prefix.
/codex/v1/chat/completionsYou want an explicit Codex-labeled chat-completions alias.

04 · 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.

05 · How dispatch works

One call, many backends.

Every generation request goes through the same balance reservation and routing path. EastRouter tries the primary upstream first, then falls back to a backup provider automatically when the primary is full, times out, or returns a retryable error.

Claude Code routes use the providers' Anthropic-compatible endpoint. OpenAI, Codex, and generic coding tools use the providers' OpenAI-compatible coding endpoint. In both cases, your EastRouter key, credit balance, and request logs stay the same.

If the primary upstream fails, we re-route automatically. No retries required from your side — we handle it in the same request lifecycle.

See the dispatch diagram on the homepage for the visual.

06 · API reference

Request & response.

Request body

FieldTypeNotes
modelstringRequired. e.g. z-ai/glm-5.2. See catalog.
messagesarrayStandard OpenAI roles: system, user, assistant, tool.
streambooleanDefaults to false. Streaming uses SSE.
temperaturenumber0.0–2.0. Passed through unchanged.
max_tokensintegerCaps output length. Used by the daily-cap reservation logic.
toolsarrayOpenAI tool-calling schema. GLM, Kimi, MiniMax all support it.
reasoningobject{ "effort": "none" | "minimal" | "medium" | "high" }. Maps to the upstream's thinking param.

Response — non-streaming

JSON
{
  "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 }
  }
}

07 · 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

ClientBase URL
OpenAI SDK (Python, JavaScript, TypeScript)https://api.eastrouter.com/v1
Codex CLIhttps://api.eastrouter.com/v1
Cline, RooCodehttps://api.eastrouter.com/v1
Go, Rust, cURL and other HTTP clientshttps://api.eastrouter.com/v1
Claude Codehttps://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:

.env
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:

Shell
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.

08 · Migration

From OpenRouter, in two lines.

If your client is already pointed at OpenRouter, the migration is purely string-level:

OpenRouterEastRouter
https://openrouter.ai/api/v1https://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.