View as /docs.md
Migrate

Migrate from Replicate

OpenAI-compatible alternative to Replicate's async-by-default model. Same access to FLUX / Stable Diffusion / Llama / etc., but sync chat completions and unified billing.

CLI automation for Replicate isn't shipped yet — you'll do this manually below. PRs welcome at packages/aig-cli/src/commands/migrate.ts.

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.replicate.com/v1

# 3. search-and-replace the env var name

What changes, line-by-line

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

ThingReplicateAIgateway
Base URLhttps://api.replicate.com/v1https://api.aigateway.sh/v1
API key env varREPLICATE_API_TOKENAIGATEWAY_API_KEY
Auth headerToken …Authorization: Bearer …
Request shapeCustom Replicate JSONOpenAI-compatible (chat/images/etc.)
PollingRequired for most modelsStreaming for text, async-job pattern for video

Before / after — Python (OpenAI SDK)

BEFORE · Replicate
from openai import OpenAI

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

What to read next