View as /docs.md
Migrate

Migrate from OpenRouter

Drop in for OpenRouter. Same OpenAI-compatible API, broader catalog (video / audio / music / 3D), lower platform fee on top-ups, evals + sub-accounts included.

CLI automation for OpenRouter is shipping: `aig migrate openrouter` walks the working tree and rewrites every match.

TL;DR — three lines

# 1. set your AIgateway key
export AIGATEWAY_API_KEY="sk-aig-..."

# 2. change the base URL
base_url="https://api.aigateway.sh/v1"  # was https://openrouter.ai/api/v1

# 3. aig migrate openrouter     # or rewrite by hand

Automated: aig migrate openrouter

Walks the current directory tree (ignoring node_modules, build outputs, lockfiles), shows you a preview of every change, and applies them after a y/N confirmation. Leaves *.aig-migrate.bak backups alongside each rewritten file unless you pass --no-backup.

# install once
npm i -g aigateway-cli

# preview without writing
aig migrate openrouter --dry-run

# apply (with backups)
aig migrate openrouter

# CI-friendly: skip the prompt
aig migrate openrouter --yes --no-backup

What changes, line-by-line

The table below is what aig migrate openrouter rewrites. If you're doing it by hand, do these in order.

ThingOpenRouterAIgateway
Base URLhttps://openrouter.ai/api/v1https://api.aigateway.sh/v1
API key env varOPENROUTER_API_KEYAIGATEWAY_API_KEY
Auth headerAuthorization: Bearer …Authorization: Bearer …
Model slug formatanthropic/claude-opus-4.7anthropic/claude-opus-4.7
Streaming formatOpenAI SSEOpenAI SSE
Platform fee5.5% at top-up5% per call (no top-up fee beyond Stripe)
BYOK fee5% (after 1M free/mo)0% on BYOK traffic
Cost-attribution headersx-aig-tag (any string)

Before / after — Python (OpenAI SDK)

BEFORE · OpenRouter
from openai import OpenAI

client = OpenAI(
    base_url="https://openrouter.ai/api/v1",
    api_key=os.environ["OPENROUTER_API_KEY"],
)
r = client.chat.completions.create(
    model="anthropic/claude-opus-4.7",
    messages=[{"role": "user", "content": "Hi"}],
)
AFTER · AIgateway
from openai import OpenAI

client = OpenAI(
    base_url="https://api.aigateway.sh/v1",
    api_key=os.environ["AIGATEWAY_API_KEY"],
)
r = client.chat.completions.create(
    model="anthropic/claude-opus-4.7",
    messages=[{"role": "user", "content": "Hi"}],
)

Behavioral notes

Credit match

Email your last invoice from OpenRouter to switch@aigateway.sh and we match the credit up to $1,000 (24-hour turnaround). Or read the full pitch at /switch/openrouter.

What to read next