Integrations · Vercel AI SDK
Vercel AI SDK
Expose You.com Search as a tool the model can call during a streamText or useChat turn.
Tool definition
TypeScript
import { tool, streamText } from "ai";
import { z } from "zod";
import { You } from "@you-com/sdk";
const you = new You({ apiKey: process.env.YOU_API_KEY! });
export const youSearch = tool({
description: "Search the live web for up-to-date information.",
parameters: z.object({ query: z.string() }),
execute: async ({ query }) => {
const res = await you.search.unified({ query });
return res.results.web?.slice(0, 5) ?? [];
},
});
await streamText({
model,
prompt,
tools: { youSearch },
});