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
- Install the packages:
npm install ai @ai-sdk/openai. - Set
ORCAROUTER_API_KEYto an API key from your OrcaRouter console. - Build a tool set for a task with the helper below and pass it to
generateTextorstreamText.
Code
// 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;
}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
- Track competitor TikTok accountsPull each competitor's TikTok profile, find its latest videos and read what viewers say, in three tool calls an agent can repeat every week.
- Monitor brand mentions on the web and TikTokSearch the web and TikTok for your brand, then read the comments under the posts that mention it: a daily brand check an agent can run on its own.
- Enrich a lead listTurn a list of company domains into firmographics, a contact's work email and a recent news hook, with one API key.
Other integrations
- MastraConnect a Mastra agent to the OrcaRouter MCP server with MCPClient, so it can search the tool catalog and run what it finds.
- LangChainLoad OrcaRouter tools as LangChain tools from the functions export and give them to any LangChain agent; each call runs the tool through OrcaRouter.
- OpenAI Agents SDKWrap each OrcaRouter tool in a FunctionTool with its own JSON schema and run it from an Agents SDK agent, with the model served through OrcaRouter too.
