Back to docs

Migrating to PrivateRouter

5-minute drop-in switch from OpenAI / Anthropic / OpenRouter

Migrating to PrivateRouter

PrivateRouter is OpenAI-compatible. Migrating from OpenAI, Anthropic, or OpenRouter is a two-line change in 90% of codebases — flip base_url and swap your model name.

The interactive migration wizard at /migrate walks through this end-to-end:

  1. Pick your current provider (OpenAI / Anthropic / OpenRouter).
  2. See side-by-side "before / after" code for Python, Node, and curl.
  3. Paste your 30-day token counts to get a personalized savings estimate.
  4. Copy the generated snippet and ship.

What the wizard does

Behind the scenes, the wizard calls POST /api/migrate/estimate — a public, unauthenticated endpoint that returns:

  • recommended_pr_model — the closest PrivateRouter model to whatever you're running today (e.g. gpt-4oprivaterouter/qwen-pro, claude-3-haikuprivaterouter/fast).
  • legacy_cost_usd_30d — what those same tokens would have cost on your current provider, using their publicly listed prices.
  • pr_cost_usd_30d — what they'd cost on PrivateRouter.
  • monthly_savings_usd + savings_pct — the headline numbers.
  • code_snippets — ready-to-paste Python / Node / curl swaps, pre-filled with the recommended model name.

The estimate uses hardcoded list prices on both sides — it's a first-order approximation, not a billing contract. Your actual savings will vary with context length, cache hit rate, and routing decisions.

Manual migration (skip the wizard)

If you'd rather wire it up by hand:

Python (OpenAI SDK)

from openai import OpenAI

client = OpenAI(
    api_key="$PRIVATEROUTER_API_KEY",
    base_url="https://api.privaterouter.com/v1",
)

resp = client.chat.completions.create(
    model="privaterouter/qwen-pro",   # was: "gpt-4o"
    messages=[{"role": "user", "content": "Hello!"}],
)
print(resp.choices[0].message.content)

Node (OpenAI SDK)

import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.PRIVATEROUTER_API_KEY,
  baseURL: "https://api.privaterouter.com/v1",
});

const resp = await client.chat.completions.create({
  model: "privaterouter/qwen-pro", // was: "gpt-4o"
  messages: [{ role: "user", content: "Hello!" }],
});

curl

curl https://api.privaterouter.com/v1/chat/completions \
  -H "Authorization: Bearer $PRIVATEROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "privaterouter/qwen-pro",
    "messages": [{"role": "user", "content": "Hello!"}]
  }'

Anthropic users

Anthropic's messages API has a slightly different shape. The simplest path is to switch to the OpenAI SDK pointed at PrivateRouter — the request payload is almost identical and you don't need a separate client. The wizard's "Before / After" panes show the exact diff.

Pricing comparison

Pricing details for every PrivateRouter model live on the pricing page and the model leaderboard. A few common mappings:

  • gpt-4oprivaterouter/qwen-pro
  • gpt-4o-miniprivaterouter/fast
  • claude-3.5-sonnetprivaterouter/qwen-pro
  • claude-3-haikuprivaterouter/fast
  • deepseek-coderprivaterouter/deepseek-code
  • text-embedding-3-smallprivaterouter/embed

API endpoint reference

POST /api/migrate/estimate
Content-Type: application/json

{
  "legacy_provider": "openai",
  "legacy_model": "gpt-4o",
  "input_tokens_30d": 1000000,
  "output_tokens_30d": 500000
}
  • Auth: none. Public endpoint, indexable.
  • Caching: Cache-Control: public, max-age=3600.
  • Validation: token counts must be >= 0; legacy_provider must be one of openai, anthropic, openrouter.

Got stuck?

Open a ticket from the contact page and we'll help wire it up. Most migrations take under five minutes.