Quickstart — Drop-In Migration
The two changes
FreeRouter's default API shape is OpenAI-compatible, so your existing client keeps working. Point it at FreeRouter and use your fr_live_... key:
| Setting | Before | After |
|---|---|---|
| Base URL | https://api.openai.com/v1 | https://api.freerouter.com/v1 |
| API key | sk-... | fr_live_... |
That's the whole migration
Everything else — endpoints, request bodies, streaming, tool calls — stays identical. Point your app at FreeRouter and your routing rule decides where each request goes.
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.