View as /docs.md
Migrate

Migrate from Portkey

Portkey-compatible gateway with 5% PAYG (no $49/mo flat), every modality (not just text), and a programmatic sub-account API instead of workspace-only keys.

CLI automation for Portkey is shipping: `aig migrate portkey` 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://api.portkey.ai/v1

# 3. aig migrate portkey     # or rewrite by hand

Automated: aig migrate portkey

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 portkey --dry-run

# apply (with backups)
aig migrate portkey

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

What changes, line-by-line

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

ThingPortkeyAIgateway
Base URLhttps://api.portkey.ai/v1https://api.aigateway.sh/v1
API key env varPORTKEY_API_KEYAIGATEWAY_API_KEY
Auth headerx-portkey-api-keyAuthorization: Bearer …
Trace headerx-portkey-trace-idx-aig-tag
Virtual key (vk_…)Portkey virtual keyAIgateway sub-account key (sk-aig-…)
Configx-portkey-config headerRouting rules in dashboard
Platform fee$49/mo flat (Pro) or 5% per call (PAYG)5% per call, no monthly fee
Per-user keysWorkspace-onlySub-account API (programmatic)

Before / after — Python (OpenAI SDK)

BEFORE · Portkey
from openai import OpenAI

client = OpenAI(
    base_url="https://api.portkey.ai/v1",
    api_key=os.environ["PORTKEY_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 Portkey to switch@aigateway.sh and we match the credit up to $1,000 (24-hour turnaround). Or read the full pitch at /switch/portkey.

What to read next