Skip to content

Ship in one sitting

Inference goes to the compatible endpoints on the enterprise gateway. It does not pass through this site or the console adapter. Replace the base URL with your line and use a key from the console.

Base URL used in these snippets: https://gateway.irouter.io

Claude Code

Put this in the env block of ~/.claude/settings.json. On Windows the file is %USERPROFILE%\.claude\settings.json. The base URL has no /v1. ANTHROPIC_AUTH_TOKEN is sent as Authorization: Bearer.

Claude Code settings.json

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://gateway.irouter.io",
    "ANTHROPIC_AUTH_TOKEN": "sk-..."
  }
}

Claude Code macOS / Linux

export ANTHROPIC_BASE_URL='https://gateway.irouter.io'
export ANTHROPIC_AUTH_TOKEN='sk-...'

Claude Code Windows PowerShell

$env:ANTHROPIC_BASE_URL = "https://gateway.irouter.io"
$env:ANTHROPIC_AUTH_TOKEN = "sk-..."

Codex

Write this to ~/.codex/config.toml. model_provider points at the irouter table, and base_url includes /v1. Put the secret in OPENAI_API_KEY, not in the file.

Codex config.toml

model_provider = "irouter"
model = "gpt-5.4"

[model_providers.irouter]
name = "iRouter"
base_url = "https://gateway.irouter.io/v1"
env_key = "OPENAI_API_KEY"
wire_api = "responses"
requires_openai_auth = false

Codex macOS / Linux

export OPENAI_API_KEY='sk-...'

Codex Windows PowerShell

$env:OPENAI_API_KEY = "sk-..."

OpenAI SDK

Python and Node both use a base URL that includes /v1. The model id has to match the catalog.

OpenAI SDK Python

from openai import OpenAI

client = OpenAI(
    base_url="https://gateway.irouter.io/v1",
    api_key="sk-...",
)
response = client.chat.completions.create(
    model="gpt-5.4",
    messages=[{"role": "user", "content": "hello"}],
)

OpenAI SDK Node

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://gateway.irouter.io/v1",
  apiKey: "sk-...",
});

await client.chat.completions.create({
  model: "gpt-5.4",
  messages: [{ role: "user", content: "hello" }],
});

OpenAI curl

curl https://gateway.irouter.io/v1/chat/completions \
  -H "Authorization: Bearer sk-..." \
  -H "Content-Type: application/json" \
  -d '{"model":"gpt-5.4","messages":[{"role":"user","content":"hello"}]}'

Anthropic SDK

The SDK base URL has no /v1; the client adds it. Authentication uses x-api-key.

Anthropic SDK Python

import anthropic

client = anthropic.Anthropic(
    base_url="https://gateway.irouter.io",
    api_key="sk-...",
)
message = client.messages.create(
    model="claude-sonnet-4-5",
    max_tokens=256,
    messages=[{"role": "user", "content": "hello"}],
)

Anthropic SDK Node

import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic({
  baseURL: "https://gateway.irouter.io",
  apiKey: "sk-...",
});

await client.messages.create({
  model: "claude-sonnet-4-5",
  max_tokens: 256,
  messages: [{ role: "user", content: "hello" }],
});

Anthropic curl

curl https://gateway.irouter.io/v1/messages \
  -H "x-api-key: sk-..." \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{"model":"claude-sonnet-4-5","max_tokens":256,"messages":[{"role":"user","content":"hello"}]}'

Common errors

These are the failures you can recognize from the response, and the next step. Do not rotate a key just because a call failed.

401 Unauthorized
The key is missing, disabled, or on the wrong header. OpenAI-compatible calls and Claude Code's ANTHROPIC_AUTH_TOKEN use Authorization: Bearer. The Anthropic SDK uses x-api-key. In the console, confirm the key is still enabled and starts with sk-.
429 Too many requests
The call exceeded a rate or balance limit. Wait, then check the balance in the console. Do not retry the same key concurrently.
Model not found
The model id must match the catalog exactly, including case. A name that is not in the catalog fails. Pick a catalog id and call again.
Timeout
The gateway did not answer before the client gave up. Retry once. If it still times out, check the network path to the API base and raise the client timeout. Do not fire the same request in a loop.
403 IP not allowlisted
When a key has an IP allowlist, the caller IP must match one line (IPv4, IPv6, or CIDR). Otherwise the inference call returns HTTP 403. error.message starts with “Your IP address is not on this token's allowlist” and ends with the request id (中文:您的 IP 不在令牌允许访问的列表中) and error.type is new_api_error. An empty list allows any IP.