Quickstart — Migrating from a Gateway

Already calling OpenAI, OpenRouter, Vercel, Cloudflare, Anthropic or Gemini? After the dashboard setup below, migrating is two code edits — change the base URL and swap the key — plus rewriting model ids to provider/model. No SDK changes. FreeRouter is BYOK-gateway-only: you bring a key from a gateway (OpenRouter, Vercel, Cloudflare, …); direct OpenAI/Anthropic/Google lab keys are not a provider yet.

Starting from scratch? This guide assumes you already call an LLM gateway. New project, no gateway yet? Follow Starting fresh instead.

The two changes

First, bring your current gateway's API key with you: paste it under Providers and create a FreeRouter key routed to it, with the key's API shape set to the format your client speaks — the three dashboard steps are in Getting Started. Then change two values in your code:

You call todayBase URL beforeBase URL afterKey before → afterKey shape
OpenAIhttps://api.openai.com/v1https://api.freerouter.com/v1sk-… → fr_live_…openai
OpenRouterhttps://openrouter.ai/api/v1https://api.freerouter.com/v1sk-or-… → fr_live_…openrouter (OpenRouter fields supported)
Vercel AI Gatewayhttps://ai-gateway.vercel.sh/v1https://api.freerouter.com/v1your gateway's API key → fr_live_…openai
Cloudflare AI Gatewayhttps://gateway.ai.cloudflare.com/v1/{account}/{gateway}/openaihttps://api.freerouter.com/v1API token → fr_live_…openai
Anthropichttps://api.anthropic.comhttps://api.freerouter.com (no /v1)sk-ant-… → fr_live_… (as x-api-key)anthropic
Geminihttps://generativelanguage.googleapis.com/v1betahttps://api.freerouter.com/v1 — /models/{model}:generateContent onlyAIza… → fr_live_… (as x-goog-api-key)google

The account id, gateway name or project your old URL carried is gone from your code: FreeRouter stores those with the provider key. Model ids are provider/model everywhere, e.g. openai/gpt-4o-mini.

That's the whole migration — with four things not carried over Endpoints, request bodies, streaming and tool calls for chat, embeddings, images and Responses stay identical. Not carried over: legacy POST /v1/completions (use chat completions), OpenAI file ids (/v1/files, file_id batches — send files by URL), browser-direct calls (no CORS headers — call from a server), and the Realtime API (no WebSocket surface). Moderations and audio are served only on gateways listed as supporting them; elsewhere they answer 501 moderations_unsupported / audio_unsupported. Everything else that changes behind the proxy — added headers, the 10 MB body limit — is on one page: What's different. Per-SDK before/after snippets are in Use your SDK.

Migration assistant — generate an agent prompt

Switching from another gateway? Use the wizard below to construct a prompt you can paste into your coding agent. The prompt asks the agent to study the FreeRouter docs and your code, then come back with a migration plan for your review — not to start rewriting code.

Step 1 — Which gateway do you use today?

Step 3 — Paste this prompt into your agent

Raw HTTP with curl

The request is byte-for-byte what you send the gateway today; only the host and the key differ. "stream": true returns server-sent events exactly as before:

curl https://api.freerouter.com/v1/chat/completions \
  -H "Authorization: Bearer $FREEROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -N \
  -d '{
    "model": "openai/gpt-4o-mini",
    "stream": true,
    "messages": [{ "role": "user", "content": "Count to 3." }]
  }'

In your SDK

OpenAI Python and Node, Anthropic Python and Node, Claude Code, Vercel AI SDK, LangChain, LiteLLM, the Responses API, Gemini, or just two environment variables — each with a before/after and a streaming variant — are in Use your SDK.

Verify

  • The response carries X-FreeRouter-Provider naming the gateway that answered; GET /v1/models lists what the key can reach.
  • A 401, 402 or 404 on the first call has a one-line fix in Troubleshooting — the Anthropic SDK's /v1-on-the-base-URL mistake and the unfunded-account 402 are the usual two.

Choosing a model

Pass a model string in the model field. FreeRouter uses provider/model style identifiers so a request is unambiguous across gateways — for example openai/gpt-4o-mini or anthropic/claude-haiku-5.5. Your routing rule then decides which gateway actually serves that model. List what's available with the /v1/models endpoint.

Different API shape? If your service speaks the OpenRouter, Anthropic, or Google format instead of OpenAI, set the key's API shape to match — the base URL swap is the same.
Next Use your SDK