Start building
Connect your SDK

Vercel AI SDK

The Fuel Router as a Vercel AI SDK provider, for agents with tools and many steps, and for images.

Install the AI SDK and the Fuel provider:

Shell
npm i ai @fuelpad/ai-sdk

import { createFuel } from "@fuelpad/ai-sdk";
import { streamText } from "ai";

const fuel = createFuel({ apiKey: process.env.FUEL_ROUTER_KEY });

const result = streamText({
  model: fuel("anthropic/claude-sonnet-5.5"),
  prompt: "Write a short welcome post for our token holders.",
  maxOutputTokens: 512,
});

for await (const text of result.textStream) {
  process.stdout.write(text);
}

// What the call was charged, in dollars.
console.log((await result.providerMetadata)?.fuel?.cost);

Every model id from Models works as fuel("..."). The default fuel export reads FUEL_ROUTER_KEY itself. Provider options go under fuel, such as providerOptions: { fuel: { reasoningEffort: "low" } }.

An agent with tools

Tools, structured output and multi-step loops work as with any provider. Here an agent reads its own balance with the TypeScript SDK before it plans:

TypeScript
import { generateText, stepCountIs, tool } from "ai";
import { Fuel } from "@fuelpad/sdk";
import { z } from "zod";

// Reads FUEL_ROUTER_KEY.
const client = new Fuel();

const { text } = await generateText({
  model: fuel("google/gemini-3.8-flash"),
  tools: {
    balance: tool({
      description: "The AI credit this agent can still spend, in dollars",
      inputSchema: z.object({}),
      execute: async () => {
        const { spendable_usd } = await client.ai.balance();
        return { spendable_usd };
      },
    }),
  },
  stopWhen: stepCountIs(4),
  prompt: "Check your credit, then plan today's posts to fit it.",
});

Set maxOutputTokens on long runs: each step reserves its longest answer while it runs.

Images

TypeScript
import { generateImage } from "ai";

const { image, calls } = await generateImage({
  model: fuel.imageModel("openai/gpt-image-2"),
  prompt: "A red lighthouse at dusk, flat illustration",
  aspectRatio: "1:1",
  providerOptions: { fuel: { quality: "medium" } },
});

// What each call was charged, in dollars.
console.log(calls[0]?.providerMetadata?.fuel?.cost);

Every model from GET /images/models works as fuel.imageModel("..."). Fields beyond n, size, aspectRatio and seed go in providerOptions.fuel, such as resolution and quality. n is split into as many calls as the model allows, and images to edit go in prompt: { text, images }. See Images.