Quickstart — Migrating from a Gateway

Already calling the OpenAI API? Migrating to FreeRouter is two edits: change the base URL and swap the key. No SDK changes, no request rewrites.

Starting from scratch? This guide assumes you already call an LLM gateway. New project, no gateway yet? Follow Starting fresh instead — it walks through signup, picking gateways, and your first key.

The two changes

FreeRouter is flexible about the format your client already speaks: it supports the popular API shapes — OpenAI, OpenRouter, Anthropic, and Google — with OpenAI-compatible as the default, so your existing code keeps working with no rewrites. Migrating is two edits: point your client at FreeRouter and use your fr_live_... key (with its shape set to match your client) — and bring your current gateway key with you: paste it into the dashboard under Providers → Add provider, then attach a routing rule that sends traffic to it (the full flow is in Getting Started):

SettingBeforeAfter
Base URLhttps://api.openai.com/v1https://api.freerouter.com/v1
API keysk-...fr_live_...
That's the whole migration Everything else — endpoints, request bodies, streaming, tool calls — stays identical. Your old gateway key isn't thrown away; it moves out of your codebase and into the dashboard as a BYOK provider key, and your routing rule decides where each request goes.

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

curl

curl https://api.freerouter.com/v1/chat/completions \
  -H "Authorization: Bearer $FREEROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "openai/gpt-4o-mini",
    "messages": [
      { "role": "system", "content": "You are concise." },
      { "role": "user", "content": "Say hi in one word." }
    ]
  }'

Streaming with curl

Set "stream": true to receive server-sent events, exactly like the OpenAI API:

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." }]
  }'

Python (openai SDK)

The official openai Python SDK takes a base_url and api_key. Set those two and nothing else changes:

# pip install openai
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.freerouter.com/v1",
    api_key=os.environ["FREEROUTER_API_KEY"],
)

resp = client.chat.completions.create(
    model="openai/gpt-4o-mini",
    messages=[
        {"role": "user", "content": "Hello from FreeRouter!"},
    ],
)

print(resp.choices[0].message.content)

Streaming in Python

stream = client.chat.completions.create(
    model="openai/gpt-4o-mini",
    messages=[{"role": "user", "content": "Count to 3."}],
    stream=True,
)

for chunk in stream:
    delta = chunk.choices[0].delta.content or ""
    print(delta, end="", flush=True)

Node (openai SDK)

The openai Node SDK is the same story — pass baseURL and apiKey:

// npm install openai
import OpenAI from "openai";

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

const resp = await client.chat.completions.create({
  model: "openai/gpt-4o-mini",
  messages: [{ role: "user", content: "Hello from FreeRouter!" }],
});

console.log(resp.choices[0].message.content);

Streaming in Node

const stream = await client.chat.completions.create({
  model: "openai/gpt-4o-mini",
  messages: [{ role: "user", content: "Count to 3." }],
  stream: true,
});

for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}

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-3.5-sonnet. 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 API Reference