> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stophy.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Vercel AI SDK

> Give any AI SDK model live web search with Stophy. Save one search function, wrap it in tool() with zod, and let the model call it in generateText.

Give any AI SDK model live web search. The model asks for a search, `execute` calls Stophy, and the model answers from the results.

## The search tool

Save this as `stophy.ts`. It calls Google search and returns the top 5 results as JSON. It works with no key. Set `STOPHY_API_KEY` to lift the free limit.

```ts stophy.ts theme={null}
export async function stophySearch(query: string): Promise<string> {
  const headers: Record<string, string> = { "content-type": "application/json" };
  if (process.env.STOPHY_API_KEY) headers.authorization = `Bearer ${process.env.STOPHY_API_KEY}`;
  const response = await fetch("https://api.stophy.dev/v1/google/search", {
    method: "POST",
    headers,
    body: JSON.stringify({ query }),
  });
  const body = await response.json();
  if (!body.success) throw new Error(body.error.message);
  return JSON.stringify(body.data.results.slice(0, 5));
}
```

## Give it to the AI SDK

```bash theme={null}
npm install ai @ai-sdk/openai zod
```

Set `OPENAI_API_KEY` in your environment.

Wrap the search in `tool()`. `stopWhen` lets the model search, read the results and answer in up to five steps. Any AI SDK model works, so swap `openai(...)` for another provider.

```ts theme={null}
import { openai } from "@ai-sdk/openai";
import { generateText, stepCountIs, tool } from "ai";
import { z } from "zod";
import { stophySearch } from "./stophy";

const { text } = await generateText({
  model: openai("gpt-5-mini"),
  prompt: "What changed in the latest Bun release?",
  tools: {
    webSearch: tool({
      description: "Search the web. Returns the top results as JSON.",
      inputSchema: z.object({ query: z.string().describe("What to search for") }),
      execute: async ({ query }) => stophySearch(query),
    }),
  },
  stopWhen: stepCountIs(5),
});

console.log(text);
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.