What is relayfor.si?

Vercel AI SDK

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

Install the AI SDK and the relayfor.si provider:

npm i ai @relayforsi/ai-sdk

npm · GitHub

import { createRelayForSI } from "@relayforsi/ai-sdk";
import { streamText } from "ai";

const rfs = createRelayForSI({ apiKey: process.env.RELAYFOR_ROUTER_KEY });

const result = streamText({
  model: rfs("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)?.relayforsi?.cost);

Every model id from Models works as rfs("..."). The default relayForSI export reads RELAYFOR_ROUTER_KEY itself. Provider options go under relayforsi, such as providerOptions: { relayforsi: { 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:

import { generateText, stepCountIs, tool } from "ai";
import { RelayForSI } from "relayfor.si";
import { z } from "zod";

// Reads RELAYFOR_ROUTER_KEY.
const relayForSI = new RelayForSI();

const { text } = await generateText({
  model: rfs("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 relayForSI.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

import { generateImage } from "ai";

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

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

Every model from GET /images/models works as rfs.imageModel("..."). Fields beyond n, size, aspectRatio and seed go in providerOptions.relayforsi, 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.

On this page