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

# Olostep + Vercel AI SDK Integration

> Give AI SDK agents live web search, scraping, crawling and cited answers with ready-made Olostep tools

The Olostep AI SDK integration gives agents built with the [Vercel AI SDK](https://ai-sdk.dev) ready-made tools for live web data. [Olostep](https://www.olostep.com) is web data infrastructure for AI agents and enterprise AI workflows. Its APIs provide live web search, scraping and crawling to extract, clean and structure data from the web. Pass the tools to `generateText` or `streamText` and the model decides when to search, scrape or crawl.

[Install from npm →](https://www.npmjs.com/package/@olostep/ai-sdk)

## Why Olostep

* Web data infrastructure for developers and enterprises
* Scales to hundreds of millions to billions of requests per customer per month
* The most performant, reliable and cost-effective API on the market
* Used by the fastest-growing AI companies

From extracting data from a handful of URLs to crawling hundreds of millions of pages, Olostep gives developers and AI companies reliable, scalable and highly cost-effective access to clean, structured web data.

## Features

The package provides 7 tools:

> [card] Scrape
>
> Scrape any URL and return clean markdown, with JavaScript rendering

> [card] Search
>
> Search the live web and return titles, URLs and descriptions

> [card] Answer
>
> Answer a question from the live web, with source URLs

> [card] Map
>
> List the URLs on a website, optionally ranked by a query

> [card] Crawl
>
> Crawl a site from a starting URL and return the markdown of each page

> [card] Batch
>
> Scrape up to 100k URLs in one batch and return the markdown of each page

> [card] Results
>
> Get the remaining pages of a crawl or batch

## Installation

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

```bash yarn theme={null}
yarn add @olostep/ai-sdk ai zod
```

```bash pnpm theme={null}
pnpm add @olostep/ai-sdk ai zod
```

Works with AI SDK 5, 6 and 7, Zod 3.25+ or 4, and Node.js 18+.

## Setup

Set your Olostep API key as an environment variable:

```bash theme={null}
export OLOSTEP_API_KEY=your-api-key-here
```

Or in your `.env` file:

```
OLOSTEP_API_KEY=your-api-key-here
```

Get your API key from the [Olostep Dashboard](https://www.olostep.com/dashboard).

## Quick Start

Pass all Olostep tools to the model with `olostepTools()`:

```typescript theme={null}
import { generateText, stepCountIs } from 'ai';
import { olostepTools } from '@olostep/ai-sdk';

const { text } = await generateText({
  model: 'openai/gpt-5-mini',
  tools: olostepTools(),
  stopWhen: stepCountIs(5),
  prompt: 'Read the Next.js 15 release notes and list the breaking changes, with sources.',
});

console.log(text);
```

`stopWhen` lets the model call tools over several steps, for example search first and then scrape the best result. The model string uses the [Vercel AI Gateway](https://vercel.com/docs/ai-gateway). You can also pass any AI SDK provider model, such as `openai('gpt-5-mini')` from `@ai-sdk/openai`.

### Pick Individual Tools

Only give the model the tools it needs:

```typescript theme={null}
import { olostepScrape, olostepSearch } from '@olostep/ai-sdk';

const tools = {
  scrape: olostepScrape(),
  search: olostepSearch(),
};
```

## Available Tools

The tool names below are the keys used by `olostepTools()`.

### scrape

`olostepScrape()`. Scrape a single URL and return its content as markdown.

**Input:**

**url** `string` *required*

The URL of the page to scrape

**waitBeforeScraping** `number`

Milliseconds to wait for JavaScript-heavy pages to render (0 to 10000)

**Returns:** `{ url, markdown }`

### search

`olostepSearch()`. Search the live web.

**Input:**

**query** `string` *required*

The search query

**limit** `number` (default: 10)

Maximum number of results (1 to 25)

**Returns:** `{ query, results: [{ title, url, description }] }`

### answer

`olostepAnswer()`. Search and read the live web to answer a question, with sources.

**Input:**

**task** `string` *required*

The question or research task

**Returns:** `{ answer, sources }`

### map

`olostepMap()`. Discover the URLs on a website.

**Input:**

**url** `string` *required*

The website to map

**searchQuery** `string`

Rank URLs by relevance to this query

**topN** `number`

Maximum number of URLs to return (1 to 100k)

**Returns:** `{ url, urls }`

### crawl

`olostepCrawl()`. Crawl a website from a starting URL and return each page's markdown. The tool waits for the crawl, up to `timeoutSeconds`, then returns the first set of pages.

**Input:**

**url** `string` *required*

The URL to start crawling from

**maxPages** `number` (default: 5)

Maximum pages to crawl (1 to 100k)

**includeUrls** `array`

Only crawl URLs matching these glob patterns, e.g. `["/docs/**"]`

**Returns:** `{ id, status, pages: [{ url, markdown }], nextCursor, message }`

### batch

`olostepBatch()`. Scrape up to 100k URLs in one batch and return each page's markdown. The tool waits for the batch, up to `timeoutSeconds`, then returns the first set of pages.

**Input:**

**urls** `array` *required*

The URLs to scrape (1 to 100k)

**Returns:** `{ id, status, pages: [{ url, markdown }], nextCursor, message }`

### results

`olostepResults()`. Get the pages of a crawl or batch by its id. Use it when the crawl or batch tool returned `in_progress` or a `nextCursor`.

**Input:**

**id** `string` *required*

The crawl or batch id, starting with `crawl_` or `batch_`

**cursor** `string`

The `nextCursor` from a previous result. Leave empty for the first pages.

**Returns:** `{ id, status, pages: [{ url, markdown }], nextCursor, message }`

> [!NOTE]
>
> Page content goes to the model, so crawl and batch results come back 20 pages at a time by default. If a job is still running when the wait ends, the tool returns its `id` with `status` set to `in_progress`. If more pages are available, the result includes `nextCursor`. Pass the `id` and `nextCursor` to `olostepResults` to get the next pages, until you have every page.
>
> Batches go up to 100k URLs. New accounts start at 100 URLs per batch, and [info@olostep.com](mailto:info@olostep.com) can lift this.

## Options

Every tool, and `olostepTools()`, accepts the same options:

```typescript theme={null}
olostepTools({
  apiKey: 'olostep_...',   // defaults to process.env.OLOSTEP_API_KEY
  maxCharacters: 20_000,   // max page content returned to the model, per page
  timeoutSeconds: 300,     // how long crawl and batch tools wait for the job to finish
  pagesPerCall: 20,        // pages returned per call, up to 100
});
```

**apiKey** `string`

Olostep API key. Defaults to the `OLOSTEP_API_KEY` environment variable.

**maxCharacters** `number` (default: 20000)

Maximum characters of page content returned to the model per page. Longer pages are truncated.

**timeoutSeconds** `number` (default: 300)

How long the crawl and batch tools wait for the job to finish, in seconds.

**pagesPerCall** `number` (default: 20)

How many pages the crawl, batch and results tools return per call, up to 100.

**apiBaseUrl** `string` (default: [https://api.olostep.com/v1](https://api.olostep.com/v1))

Olostep API base URL.

## Streaming Example

Use the same tools with `streamText`, for example in a Next.js route handler:

```typescript app/api/chat/route.ts theme={null}
import { convertToModelMessages, streamText, stepCountIs, type UIMessage } from 'ai';
import { olostepTools } from '@olostep/ai-sdk';

export async function POST(req: Request) {
  const { messages }: { messages: UIMessage[] } = await req.json();

  const result = streamText({
    model: 'openai/gpt-5-mini',
    system: 'You are a research assistant. Use the web tools and cite your sources.',
    messages: await convertToModelMessages(messages),
    tools: olostepTools(),
    stopWhen: stepCountIs(5),
  });

  return result.toUIMessageStreamResponse();
}
```

## Popular Use Cases

> [accordion] Research Assistant
>
> 1. The model uses `search` or `answer` to find sources
> 2. It uses `scrape` to read the most relevant pages
> 3. It returns a summary with source URLs

> [accordion] Docs-Aware Coding Agent
>
> 1. The model uses `map` with a `searchQuery` to find the right docs pages
> 2. It uses `batch` or `crawl` to read them
> 3. It writes code against the current API instead of guessing

> [accordion] Competitor and Price Monitoring
>
> 1. A scheduled job calls `generateText` with `scrape` and `batch`
> 2. The model extracts prices or changes from each page
> 3. Your code compares them with the last run and sends alerts

## Best Practices

> [accordion] Only Pass the Tools You Need
>
> Each tool's description is sent to the model. Fewer tools means fewer tokens and fewer wrong tool choices. For a chat that only reads pages, `scrape` and `search` are often enough.

> [accordion] Set a Step Limit
>
> Always set `stopWhen` (for example `stepCountIs(5)`) so the model can chain tool calls but cannot loop forever.

> [accordion] Lower maxCharacters for Long Pages
>
> Page content is the biggest part of the token bill. If you crawl or batch many pages, lower `maxCharacters` or `pagesPerCall` so all results fit in the model's context window.

> [accordion] Use results for Big Crawls and Batches
>
> Crawl and batch tools wait up to `timeoutSeconds`. Big jobs can run longer, so the tool returns an `id`. Use `olostepResults` with that `id` to get the pages when the job is done.

## Troubleshooting

> [accordion] Authentication Failed
>
> **Error**: "Invalid API key"
>
> **Solutions**:
>
> * Check your API key in the [dashboard](https://www.olostep.com/dashboard)
> * Make sure `OLOSTEP_API_KEY` is set where your code runs (for example in your Vercel project's environment variables)
> * Or pass the key directly with `olostepTools({ apiKey })`

> [accordion] The Model Doesn't Call the Tools
>
> **Solutions**:
>
> * Set `stopWhen`, otherwise generation stops after the first step
> * Use a model that supports tool calling
> * Mention the web in your prompt or system message, for example "use the web tools and cite your sources"

> [accordion] Crawl or Batch Returns in\_progress
>
> The job is still running, which is normal for large jobs.
>
> **Solutions**:
>
> * Call `olostepResults` with the `id` once the job has finished
> * Raise `timeoutSeconds` to wait longer
> * On serverless functions, make sure the function's own time limit is longer than `timeoutSeconds`

> [accordion] Context Length Exceeded
>
> **Solutions**:
>
> * Lower `maxCharacters` or `pagesPerCall`
> * Use `map` with `searchQuery` to pick fewer, more relevant pages before reading them

## Pricing

Olostep charges based on API usage, independent of the AI SDK:

* **Scrapes**: Pay per scrape
* **Searches and Answers**: Pay per request
* **Batches**: Pay per URL in batch
* **Crawls**: Pay per page crawled
* **Maps**: Pay per map operation

Check current pricing at [olostep.com/pricing](https://www.olostep.com/pricing).

## Support

> [card] [GitHub](https://github.com/olostep-api/olostep-ai-sdk)
>
> Source code and issues

> [card] [Support Email](mailto:info@olostep.com)
>
> Email: [info@olostep.com](mailto:info@olostep.com)

> [card] [AI SDK Docs](https://ai-sdk.dev/docs)
>
> Learn about the Vercel AI SDK

> [card] [Documentation](https://docs.olostep.com)
>
> Browse complete API docs

## Related Resources

> [card] [Scrapes API](https://docs.olostep.com/features/scrapes.md)
>
> Learn about the Scrapes endpoint

> [card] [Crawls API](https://docs.olostep.com/features/crawls.md)
>
> Learn about the Crawls endpoint

> [card] [Mastra Integration](https://docs.olostep.com/integrations/mastra.md)
>
> Build agents with Mastra

> [card] [LangChain Integration](https://docs.olostep.com/integrations/langchain.md)
>
> Build AI agents with LangChain


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