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

> ## Agent Instructions
> Decodo provides web scraping and proxy infrastructure. For agent-specific guidance - which endpoint to call, how to authenticate, and the usage rules - read https://help.decodo.com/docs/for-agents.md.
> Add .md to any page URL on this site to get its Markdown source.
> Search these docs live over MCP at https://help.decodo.com/mcp.

# Vercel AI SDK

> The @decodo/ai-sdk package: Decodo scrape, search, map, and crawl tools for the Vercel AI SDK, so any model can read live web data.

`@decodo/ai-sdk` is the npm package that gives [**Vercel AI SDK**](https://ai-sdk.dev) models live web data. It adds tools that scrape a page as Markdown, search the web, map a site's URLs, and crawl a site. All of them run on the [**Web Data API**](https://help.decodo.com/docs/web-data-api-introduction.md) and work with any AI SDK model provider.

> [!NOTE]
>
> View the [**ai-sdk repository**](https://github.com/Decodo/ai-sdk) for the source code, examples, and latest releases.

## Features

* **Web scraping** – fetch one page as Markdown, optionally rendering JavaScript first
* **Search** – search the web and get ranked results
* **Site mapping** – list a site's URLs without fetching their content
* **Crawling** – start a crawl, poll its status, read the pages as Markdown, or cancel it
* **AI SDK integration** – `decodoTools()` returns standard AI SDK tools you pass to `generateText` or pick one by one
* **Errors the model can act on** – a failed call reaches the model as a tool error, and `generateText` keeps running

## Requirements

* Node.js 18 or newer
* `ai` v6 or v7, which is a peer dependency
* A Decodo [**Web Data API plan**](https://dashboard.decodo.com/web-data/pricing). Free trials are available on the [**dashboard**](https://dashboard.decodo.com/).

## Installation

```bash theme={null}
npm install @decodo/ai-sdk ai @ai-sdk/anthropic
```

The examples on this page use `@ai-sdk/anthropic` and read `ANTHROPIC_API_KEY`. Any AI SDK model provider works.

## Authentication

Copy your API key from your Web Data API subscription in the [**Web Data API playground**](https://dashboard.decodo.com/web-data/playground) and store it in the `DECODO_API_KEY` environment variable:

```bash theme={null}
export DECODO_API_KEY=your_api_key
```

You can also pass it directly:

```typescript theme={null}
decodoTools({ apiKey: 'your_api_key' });
```

`decodoTools()` throws right away when the API key is missing, or when it contains a line break, space, or other character that can't be sent in a header.

## Usage

Pass all the tools to `generateText`:

```typescript theme={null}
import { anthropic } from '@ai-sdk/anthropic';
import { decodoTools } from '@decodo/ai-sdk';
import { generateText, stepCountIs } from 'ai';

const { text } = await generateText({
  model: anthropic('claude-sonnet-5-5'),
  tools: decodoTools({ apiKey: process.env.DECODO_API_KEY }),
  stopWhen: stepCountIs(5),
  prompt: 'Scrape https://ip.decodo.com and tell me the country of the IP in one sentence.',
});

console.log(text);
```

To give the model only some of the tools, destructure them. For example, a crawl needs `crawl_start`, `crawl_status`, and `crawl_results`:

```typescript theme={null}
const { crawl_start, crawl_status, crawl_results } = decodoTools();
const { text } = await generateText({
  model: anthropic('claude-sonnet-5-5'),
  tools: { crawl_start, crawl_status, crawl_results },
  stopWhen: stepCountIs(30),
  prompt: 'Crawl 5 pages of https://decodo.com and summarise what the company sells.',
});
```

The model polls `crawl_status` by calling it again, and each call uses a step, so give crawling prompts a higher `stepCountIs`. While a crawl is pending, `crawl_status` waits 5 seconds before answering. This slows polling and keeps a long crawl from using up the steps.

## Available tools

| Tool | What the model gets |
| - | - |
| `scrape` | One page as Markdown, with `truncated`. Content over 45,000 characters is cut, and `totalLength` then says how long the page was |
| `search` | Ranked organic results, plus the answer box, top stories, people-also-ask, and related searches when the engine returns them |
| `map` | A site's URLs, 10 by default and at most 500 |
| `crawl_start` | A `crawl_id` right away. Crawls 10 pages by default and at most 100 |
| `crawl_status` | Status and page counts. The crawl is finished once `status` is no longer `pending` |
| `crawl_results` | Crawled pages as Markdown, about 45,000 characters per call, with `nextCursor` for the rest |
| `crawl_cancel` | Stops a crawl. Pages crawled so far stay readable |

A crawled page too long for one call is split across calls, and each part carries `contentPart` with its character range. Every page also comes back with its `url`, `depth`, `status`, and `content_error`, and the response carries `total`, so the model can tell how much is left to read.

### Inputs

Inputs are strict: a field that isn't listed is refused rather than ignored.

| Tool | Inputs |
| - | - |
| `scrape` | `url` (required), `geo`, `locale`, and `headless: 'html'` to render JavaScript first |
| `search` | `query` (required), `geo`, `locale`, `page` |
| `map` | `url` (required), `limit`, `sitemap`, `domain_filter`, `select_paths`, `exclude_paths`, `geo`, `locale` |
| `crawl_start` | The `map` inputs, plus `max_depth` |
| `crawl_status`, `crawl_cancel` | `crawl_id` |
| `crawl_results` | `crawl_id`, `cursor` |

`limit`, `max_depth`, `select_paths`, and `exclude_paths` keep a crawl off the parts of a site you don't need, so they're worth setting in the prompt.

## Errors

A failed call reaches the model as a tool error it can read and act on, and `generateText` keeps running:

* A rejected API key names `DECODO_API_KEY`.
* Rate limits and `5xx` responses tell the model to retry later.
* A timeout tells the model to retry later, except on `scrape` and `crawl_start`. Those requests may still have run, so the model is told not to send them again unless asked.
* Validation errors tell the model to change the input.
* A page that couldn't be scraped is an error, even when the API answered `200`.

For the full list of API parameters behind these tools, see [**Parameters**](https://help.decodo.com/docs/web-scraping-api-parameters-overview.md).

***

## Related

* [**TypeScript SDK**](https://help.decodo.com/docs/typescript-sdk.md) – The SDK these tools are built on.
* [**LangChain (TypeScript)**](https://help.decodo.com/docs/langchain.md) – Decodo tools for LangChain agents in Node.js.
* [**MCP Server**](https://help.decodo.com/docs/mcp.md) – Connect AI agents and MCP-compatible tools to Decodo.
* [GitHub repository](https://github.com/Decodo/ai-sdk) – View the source code, examples, and latest releases.

***

> [card] [Support](https://direct.lc.chat/12092754)
>
> Need help or just want to say hello? Our support is available 24/7. \
> You can also reach us anytime via email at [support@decodo.com](mailto:support@decodo.com).

> [card] [Feedback](mailto:feedback@decodo.com)
>
> Can't find what you're looking for? Request an article! \
> Have feedback? Share your thoughts on how we can improve.


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