Migrate from OpenAI
Move from the OpenAI API to Flux by changing the base URL, key, and model. Nothing else changes.
Flux speaks the OpenAI API. If your code already calls OpenAI, you keep the same SDK and the same request shape. You change three things:
- Base URL to
https://api.fluxrouter.ai/v1 - API key to your Flux key (
sk-...from the dashboard) - Model to
flux-auto(or a specificflux-*id)
That's the whole migration. The endpoints (/chat/completions, /responses, /models), the request and response JSON, streaming, tools, and structured outputs all stay the same.
Get a Flux key
Sign up at /auth/sign-up and copy your key. It looks like sk-.... Get your key walks through it. The examples below read it from a FLUX_API_KEY environment variable.
Migrate the Python SDK
Before (OpenAI)
from openai import OpenAI
client = OpenAI(
api_key="sk-openai-...",
)
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Say hello."}],
)
print(response.choices[0].message.content)
After (Flux)
from openai import OpenAI
client = OpenAI(
api_key="sk-...", # your Flux key
base_url="https://api.fluxrouter.ai/v1", # the one line you change
)
response = client.chat.completions.create(
model="flux-auto", # let Flux route, or pin a flux-* id
messages=[{"role": "user", "content": "Say hello."}],
)
print(response.choices[0].message.content)
Migrate the Node SDK
Before (OpenAI)
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});
const response = await client.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "user", content: "Say hello." }],
});
console.log(response.choices[0].message.content);
After (Flux)
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.FLUX_API_KEY, // your Flux key
baseURL: "https://api.fluxrouter.ai/v1", // the one line you change
});
const response = await client.chat.completions.create({
model: "flux-auto", // let Flux route, or pin a flux-* id
messages: [{ role: "user", content: "Say hello." }],
});
console.log(response.choices[0].message.content);
What stays the same
Everything except the three values above:
- The OpenAI SDK and its method names (
chat.completions.create,responses.create). - The endpoints:
/v1/chat/completions,/v1/responses,/v1/models. - Auth header style:
Authorization: Bearer sk-.... - The request and response JSON, including streaming (
stream: true), tool calls, and structured outputs. - Your prompts, message arrays, and parameters like
temperatureandmax_tokens.
What to do about the model field
OpenAI model ids like gpt-4o are not Flux models. Pick one of these instead:
flux-auto(recommended): Flux picks among vetted models for each kind of task, cost-aware. Use this and you do not have to choose.- A lane alias (
flux-fast,flux-standard,flux-reasoning) to choose a class of model and its rate. - A
flux-pinned-*id when you want the same backing model every time. GPT models are in the catalogue too, so you can pin the one you use today.
What each option costs is on Pricing.
The authoritative list of model ids is GET https://api.fluxrouter.ai/v1/models. See Models for what each option means.
Before you switch production traffic
Run these checks with the new key before real traffic moves.
- List models.
GET https://api.fluxrouter.ai/v1/modelsproves the key works and shows the ids you can use. - Send one non-streaming call and read the headers. You should see the receipt headers from Receipts, including
X-Flux-Cost-Usd. A streamed response has no cost header. - Send one streaming call. Check that your chunk parsing holds to the end of the stream.
- Run one tool-call round trip with your real tool schema. If tools are essential to your product, test the pinned model you will rely on as well as
flux-auto, because tool support belongs to the model that answers. - Check any pin. Send your
flux-pinned-*id without streaming and readX-Flux-Routed: falseandX-Flux-Model. - Log
X-Flux-Request-Idfrom day one. It is the first thing support asks for. - Canary first. Set a prepaid daily or monthly cap in Billing (see Spend caps), send a slice of traffic, compare errors, latency and cost with your OpenAI baseline, and keep the old key until a full day runs clean. The old key is your rollback.
Next steps
- Models: the live catalogue and how
flux-autoand pinning work. - Receipts: see which model answered and what it cost.
- Connect your agent: point an agent or coding tool at Flux instead of code.