All Integrations
Integration
Vercel AI SDK
Integrate SkillRouter into your Next.js or React applications using the Vercel AI SDK. Perfect for building AI-powered web apps that can execute real-world tasks from the browser.
1
Installation
- 1Install the SkillRouter JS SDK: npm install @skillrouter/sdk
- 2Install the Vercel AI SDK: npm install ai
- 3Create a SkillRouter tool provider
- 4Use it in your AI chat route handler
2
Configuration
terminal
# Install dependencies
npm install @skillrouter/sdk ai @ai-sdk/openai
# Set environment variables in .env.local
SKILLROUTER_API_KEY=sk_live_...
OPENAI_API_KEY=sk-...3
Usage Example
app/api/chat/route.ts
// app/api/chat/route.ts
import { openai } from '@ai-sdk/openai';
import { streamText } from 'ai';
import { SkillRouter } from '@skillrouter/sdk';
import { toVercelTools } from '@skillrouter/sdk/vercel';
const sr = new SkillRouter({ apiKey: process.env.SKILLROUTER_API_KEY! });
export async function POST(req: Request) {
const { messages } = await req.json();
// Convert SkillRouter skills to Vercel AI SDK tools
const tools = await toVercelTools(sr, {
categories: ['email', 'calendar', 'weather'],
});
const result = streamText({
model: openai('gpt-4o'),
messages,
tools,
});
return result.toDataStreamResponse();
}