Use Flux with the Vercel AI SDK
Point the Vercel AI SDK at FluxRouter using its OpenAI-compatible provider with a custom baseURL.
The Vercel AI SDK talks to FluxRouter through its OpenAI-compatible provider. You create the provider with baseURL set to https://api.fluxrouter.ai/v1 and your Flux key, then use flux-auto as the model.
Set up the OpenAI-compatible provider
Install the provider package (npm install @ai-sdk/openai-compatible ai), then create a Flux provider:
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
import { generateText } from "ai";
const flux = createOpenAICompatible({
name: "flux",
baseURL: "https://api.fluxrouter.ai/v1", // the one line that points at Flux
apiKey: process.env.FLUX_API_KEY, // your Flux key
});
const { text } = await generateText({
model: flux("flux-auto"), // let Flux route, or pin a flux-* id
prompt: "Say hello from FluxRouter.",
});
console.log(text);
createOpenAICompatible is the AI SDK's documented way to point at any OpenAI-compatible endpoint.
Stream a response
Streaming works the same way; swap generateText for streamText:
import { streamText } from "ai";
const result = streamText({
model: flux("flux-auto"),
prompt: "Stream a short greeting from FluxRouter.",
});
for await (const chunk of result.textStream) {
process.stdout.write(chunk);
}
Pick a model
flux-auto routes each request for you. To pin a model, pass a tier alias (flux-fast, flux-standard, flux-reasoning) or a flux-pinned-* id to the provider, for example flux("flux-reasoning"). See Models.