# Vercel AI SDK integration: scrape, crawl and search tools | Spider

Give a Vercel AI SDK model four Spider tools: scrape, crawl, search and links. Install @spider-cloud/ai-sdk, set SPIDER_API_KEY and pass spiderTools().

Canonical: https://spider.cloud/docs/integrations/ai-sdk/

`@spider-cloud/ai-sdk` gives a model in the [Vercel AI SDK](https://ai-sdk.dev) four tools that call the Spider API: scrape, crawl, search and links. The package has no runtime dependencies. It calls the API with `fetch` and declares `ai` and `zod` as peer dependencies.

## Install

This example uses AI SDK 7 and requires Node.js 22+. Install the package with `ai` and `zod`, then set `SPIDER_API_KEY` to a key from [your API keys page](/api-keys). The string model ID uses [Vercel AI Gateway](https://ai-sdk.dev/unauthenticated-ai-gateway). For local runs, also set `AI_GATEWAY_API_KEY` to a Gateway key.

Install

```
npm install @spider-cloud/ai-sdk ai@7 zod
```

Set the keys

```
export SPIDER_API_KEY=your-spider-key
export AI_GATEWAY_API_KEY=your-gateway-key
```

## Give a model every tool

`spiderTools()` returns all four tools. The model picks which to call.

Search, read and summarize

```
import { generateText, isStepCount } from "ai";
import { spiderTools } from "@spider-cloud/ai-sdk";

const { text } = await generateText({
  model: "openai/gpt-5-mini",
  prompt: "Find the latest Rust release notes and summarize the main changes.",
  tools: spiderTools(),
  stopWhen: isStepCount(5),
});

console.log(text);
```

## Pick single tools

Import only the tools the model needs, each with its own options. Fewer tools keep the prompt shorter.

Search and scrape only

```
import { spiderScrape, spiderSearch } from "@spider-cloud/ai-sdk";

const tools = {
  search: spiderSearch({ maxResults: 5 }),
  scrape: spiderScrape({ maxContentChars: 20_000 }),
};
```

## Tools

Each tool calls one API route.

| Tool   | Route        | What the model gets                                                            |
| ------ | ------------ | ------------------------------------------------------------------------------ |
| scrape | POST /scrape | One page as markdown, text or raw HTML.                                        |
| crawl  | POST /crawl  | The content of each page found from a start URL.                               |
| search | POST /search | Ranked results with title, description and URL, or each result's page content. |
| links  | POST /links  | The URLs linked from a page or a short crawl.                                  |

## Options

Every tool factory takes these options. `spiderCrawl` and `spiderLinks` also take `maxPages`, which defaults to 20, to validate an explicit `limit` on each call. `spiderSearch` takes `maxResults`, which defaults to 10, for an explicit `search_limit`. The schema rejects supplied values above these maxima before sending a request. If the model omits the argument, crawl uses 5 pages, search uses 5 results and links uses 1 page, even when the configured maximum is lower. These checks do not cap total pages or results across multiple tool calls.

| Option          | Default                    | Meaning                                                                                                                                                                                                                                                                                                                                       |
| --------------- | -------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| apiKey          | process.env.SPIDER_API_KEY | Spider API key.                                                                                                                                                                                                                                                                                                                               |
| baseUrl         | https\://api.spider.cloud  | API base URL.                                                                                                                                                                                                                                                                                                                                 |
| fetch           | global fetch               | Custom fetch, for tests or proxies.                                                                                                                                                                                                                                                                                                           |
| headers         | none                       | Extra headers on every request.                                                                                                                                                                                                                                                                                                               |
| maxContentChars | no limit                   | Cut each page's content to this length before it reaches the model.                                                                                                                                                                                                                                                                           |
| params          | none                       | Spider request fields sent on every call, such as { return_format: "markdown", readability: true }. Model arguments override them. Crawl overwrites params.limit with 5, links with 1, and search overwrites params.search_limit with 5, unless the model supplies that argument. Search always sets the search field from the model's query. |

## Errors

A non 2xx answer throws `SpiderApiError` with `status`, `body` and, on 429, `retryAfter` in seconds from the `Retry-After` header. The AI SDK passes the error message to the model as a tool error. `crawl`, `search` and `links` throw before sending a request when no key is set.

## Compatibility

The package builds against `ai` 5, 6 and 7, and its tests run against `ai` 7. Source and issues are on [GitHub](https://github.com/spider-rs/spider-clients/tree/main/ai-sdk). Every request field is in the [API reference](/docs/api).
