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.
| Thing | Portkey | AIgateway |
|---|---|---|
| Base URL | https://api.portkey.ai/v1 | https://api.aigateway.sh/v1 |
| API key env var | PORTKEY_API_KEY | AIGATEWAY_API_KEY |
| Auth header | x-portkey-api-key | Authorization: Bearer … |
| Trace header | x-portkey-trace-id | x-aig-tag |
| Virtual key (vk_…) | Portkey virtual key | AIgateway sub-account key (sk-aig-…) |
| Config | x-portkey-config header | Routing rules in dashboard |
| Platform fee | $49/mo flat (Pro) or 5% per call (PAYG) | 5% per call, no monthly fee |
| Per-user keys | Workspace-only | Sub-account API (programmatic) |
Before / after — Python (OpenAI SDK)
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"}],
)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
- Virtual keys are the trickiest piece — swap them for AIgateway sub-account keys (see /sub-accounts). The mint endpoint is POST /v1/sub-accounts.
- Gateway configs (retries, fallbacks, conditional routing) are declared once per AIgateway account in the dashboard, not per-request in headers.
- Cost-attribution: Portkey-Property-* headers map to x-aig-tag — one tag per request, query usage by tag at /v1/usage/by-tag.
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
- BYOK — bring your existing Portkey provider keys; pay 0% on those routes.
- Sub-accounts — per-customer keys with spend caps; the closest analogue to Portkey's virtual keys.
- All migration guides — same docs for OpenRouter, Portkey, Helicone, LiteLLM, Together, Replicate, Fireworks, Requesty.