---
title: "Vercel AI SDK · Scrape.ly Docs"
description: "Use Scrape.ly tools with generateText and streamText."
url: https://scrape.ly/docs/vercel-ai-sdk
markdown: https://scrape.ly/docs/vercel-ai-sdk.md
---

# Vercel AI SDK

> Use Scrape.ly tools with generateText and streamText.

Use Scrape.ly as tools in the Vercel AI SDK: the model can search the Store, run Actors, wait for their runs, and read the results. The SDK connects to the hosted [MCP server](https://scrape.ly/docs/mcp.md), so there is no Scrape.ly package to install.

```bash
npm install ai @ai-sdk/mcp
```

Create an API token in the [dashboard](https://my.scrape.ly) under **Settings → API & Integrations** and set it as `SCRAPELY_TOKEN`. The model can do anything the token can, including starting paid runs, so give it a scoped key: `actors:run`, `runs:read`, and `datasets:read`, with a **Max charge per day**. See [API keys & permissions](https://scrape.ly/docs/api-keys.md).

## Use the tools with generateText

Create an MCP client for the server, pass its tools to `generateText`, and close the client when you are done. `stopWhen` lets the model call several tools in a row (find an Actor, run it, read the results) before it answers.

```ts
import { createMCPClient } from '@ai-sdk/mcp';
import { generateText, isStepCount } from 'ai';

const scrapely = await createMCPClient({
  transport: {
    type: 'http',
    url: 'https://mcp.scrape.ly',
    headers: { Authorization: `Bearer ${process.env.SCRAPELY_TOKEN}` },
  },
});

try {
  const { text } = await generateText({
    model: 'anthropic/claude-sonnet-5.5',
    tools: await scrapely.tools(),
    stopWhen: isStepCount(10),
    prompt:
      "Find an Actor that scrapes Google Maps, run it for 'coffee shops in Berlin' with at most 20 results, " +
      'and list the name, rating, and address of each place.',
  });
  console.log(text);
} finally {
  await scrapely.close();
}
```

Any model the AI SDK supports works. With `streamText`, close the client when the stream finishes (in `onFinish`) instead of in `finally`.

## What the model can do

The model gets the MCP server's default tools. The ones used most:

| Tool | What it does |
| --- | --- |
| `search-actors` | Find Actors in the Store by keywords. |
| `fetch-actor-details` | Read an Actor's input schema, README, and pricing before running it. |
| `call-actor` | Run an Actor with a JSON input, optionally with `maxItems` and `maxTotalChargeUsd`. |
| `get-actor-run` | Wait for a run and check its status. |
| `get-actor-output` | Read a run's results, paged and kept compact. |

The full list, including saved inputs and automations, is on the [MCP server](https://scrape.ly/docs/mcp.md#tools) page. To run one Actor you already know, name it in the prompt, for example `Run username/actor-name`, so the model skips the search.

**Costs**: runs started by the model are billed like any run. Put the limits in the prompt (such as "at most 20 results"), and keep a **Max charge per day** on the key.

---

- Previous: [CrewAI](https://scrape.ly/docs/crewai.md)
- Next: [Mastra](https://scrape.ly/docs/mastra.md)
- All docs: [Docs index](https://scrape.ly/docs.md), [llms.txt](https://scrape.ly/llms.txt)
