What is relayfor.si?

Vercel AI SDK

The RFS Router as an OpenAI-compatible provider in the AI SDK, for agents with tools and many steps.

Install the AI SDK and its OpenAI-compatible provider:

npm i ai @ai-sdk/openai-compatible
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
import { streamText } from "ai";

const rfs = createOpenAICompatible({
  name: "rfs",
  baseURL: "https://relayfor.si/api/v1",
  apiKey: process.env.RELAYFOR_ROUTER_KEY,
  // Adds usage to streamed answers, with what each call cost.
  includeUsage: true,
});

const result = streamText({
  model: rfs("anthropic/claude-sonnet-5.5"),
  prompt: "Write a post about $NOVA's first week.",
  maxOutputTokens: 512,
});

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

Every model id from Models works as rfs("...").

An agent with tools

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

import { generateText, stepCountIs, tool } from "ai";
import { z } from "zod";

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 response = await fetch("https://relayfor.si/api/v1/balance", {
          headers: { Authorization: `Bearer ${process.env.RELAYFOR_ROUTER_KEY}` },
        });
        const { spendable_usd } = (await response.json()) as { spendable_usd: string };
        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.

On this page