Agent framework

OrcaRouter tools in Vercel AI SDK

Turn OrcaRouter tools into AI SDK tools with jsonSchema() and let generateText call them over several steps.

Details

Kind
Agent framework
Connects through
Function calling

Set it up

  1. Install the packages: npm install ai @ai-sdk/openai.
  2. Set ORCAROUTER_API_KEY to an API key from your OrcaRouter console.
  3. Build a tool set for a task with the helper below and pass it to generateText or streamText.

Code

Load OrcaRouter tools
// orcarouter-tools.ts
import { jsonSchema, tool, type ToolSet } from "ai";

const BASE = "https://api.orcarouter.ai";
const headers = {
  Authorization: `Bearer ${process.env.ORCAROUTER_API_KEY}`,
  "Content-Type": "application/json",
};

export async function orcarouterTools(query: string, limit = 5): Promise<ToolSet> {
  const found = await fetch(`${BASE}/v1/tools/discover`, {
    method: "POST",
    headers,
    body: JSON.stringify({ q: query, limit }),
  }).then((res) => res.json());
  const ids = found.data.results.map((t: { id: string }) => t.id).join(",");
  if (!ids) return {};
  const fns = await fetch(
    `${BASE}/v1/tools/functions?format=openai&ids=${encodeURIComponent(ids)}`,
    { headers },
  ).then((res) => res.json());

  const tools: ToolSet = {};
  for (const { function: fn } of fns.data.tools) {
    tools[fn.name] = tool({
      description: fn.description,
      inputSchema: jsonSchema(fn.parameters),
      execute: async (input) => {
        const res = await fetch(`${BASE}/v1/tools/${fn.name}/run`, {
          method: "POST",
          headers,
          body: JSON.stringify({ input }),
        });
        return res.json();
      },
    });
  }
  return tools;
}
Call them from generateText
import { createOpenAI } from "@ai-sdk/openai";
import { generateText, stepCountIs } from "ai";
import { orcarouterTools } from "./orcarouter-tools";

const orcarouter = createOpenAI({
  baseURL: "https://api.orcarouter.ai/v1",
  apiKey: process.env.ORCAROUTER_API_KEY,
});

const { text } = await generateText({
  model: orcarouter.chat("openai/gpt-5-mini"),
  tools: await orcarouterTools("tiktok user profile"),
  stopWhen: stepCountIs(5),
  prompt: "How many followers does @nasa have on TikTok?",
});
console.log(text);

Recipes to try with Vercel AI SDK

© 2026 OrcaRouter

For Providers

Run an inference platform? Get your models on OrcaRouter.

providers@orcarouter.ai

Join our community

Discordsupport@orcarouter.aiXLinkedInGitHubYouTube