> ## Documentation Index
> Fetch the complete documentation index at: https://student-213fb9fc.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Vercel AI SDK

> 适用于 Vercel AI SDK 的 Firecrawl 工具，为 AI 应用提供网页抓取、搜索、浏览和数据提取能力。

适用于 Vercel AI SDK 的 Firecrawl 工具，为 AI 应用提供网页抓取、搜索、浏览和数据提取能力。

<div id="install">
  ## 安装
</div>

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

设置环境变量：

```bash theme={null}
FIRECRAWL_API_KEY=fc-your-key
OPENAI_API_KEY=sk-your-key
```

<Note>
  这些示例使用的是 OpenAI，但 Firecrawl 工具适用于 Vercel AI SDK 支持的任意提供商，包括 Anthropic、Google、Mistral 等。请参阅[支持的提供商完整列表](https://ai-sdk.dev/providers/ai-sdk-providers)。
</Note>

<div id="quick-start">
  ## 快速上手
</div>

```typescript theme={null}
import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { scrapeTool } from 'firecrawl-aisdk';

const { text } = await generateText({
  model: openai('gpt-5-mini'),
  prompt: '抓取 https://firecrawl.dev 并总结其功能',
  tools: { scrape: scrapeTool },
});
```

<div id="available-tools">
  ## 可用工具
</div>

```typescript theme={null}
import {
  scrapeTool,         // Scrape single URL
  searchTool,         // Search the web
  browserTool,        // 交互式浏览器会话
  agentTool,          // Autonomous web agent
  mapTool,            // Discover URLs on a site
  crawlTool,          // Crawl multiple pages
  batchScrapeTool,    // Scrape multiple URLs
  extractTool,        // Extract structured data
  pollTool,           // Poll async jobs
  statusTool,         // Check job status
  cancelTool,         // Cancel jobs
} from 'firecrawl-aisdk';
```

<div id="examples">
  ## 示例
</div>

<div id="scrape">
  ### 爬取
</div>

```typescript theme={null}
import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { scrapeTool } from 'firecrawl-aisdk';

const { text } = await generateText({
  model: openai('gpt-5-mini'),
  prompt: '抓取 https://firecrawl.dev 并总结它的作用',
  tools: { scrape: scrapeTool },
});

console.log(text);
```

<div id="search">
  ### 搜索
</div>

```typescript theme={null}
import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { searchTool } from 'firecrawl-aisdk';

const { text } = await generateText({
  model: openai('gpt-5-mini'),
  prompt: '搜索 Firecrawl 并总结你的发现',
  tools: { search: searchTool },
});

console.log(text);
```

<div id="map">
  ### 映射
</div>

```typescript theme={null}
import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { mapTool } from 'firecrawl-aisdk';

const { text } = await generateText({
  model: openai('gpt-5-mini'),
  prompt: 'Map https://docs.firecrawl.dev and list the main sections',
  tools: { map: mapTool },
});

console.log(text);
```

<div id="crawl">
  ### Crawl
</div>

异步操作——请包含 `pollTool` 以检查任务状态。

```typescript theme={null}
import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { crawlTool, pollTool } from 'firecrawl-aisdk';

const { text } = await generateText({
  model: openai('gpt-5-mini'),
  prompt: '爬取 https://docs.firecrawl.dev（限制 3 页）并总结',
  tools: { crawl: crawlTool, poll: pollTool },
});

console.log(text);
```

<div id="batch-scrape">
  ### 批量抓取
</div>

异步操作——请使用 `pollTool` 轮询检查任务状态。

```typescript theme={null}
import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { batchScrapeTool, pollTool } from 'firecrawl-aisdk';

const { text } = await generateText({
  model: openai('gpt-5-mini'),
  prompt: 'Scrape https://firecrawl.dev and https://docs.firecrawl.dev, then compare',
  tools: { batchScrape: batchScrapeTool, poll: pollTool },
});

console.log(text);
```

<div id="extract">
  ### 提取
</div>

异步操作——包含 `pollTool` 来检查任务状态。

```typescript theme={null}
import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { extractTool, pollTool } from 'firecrawl-aisdk';

const { text } = await generateText({
  model: openai('gpt-5-mini'),
  prompt: '从 https://firecrawl.dev 提取主要功能',
  tools: { extract: extractTool, poll: pollTool },
});

console.log(text);
```

<div id="search-scrape">
  ### 搜索 + 抓取
</div>

```typescript theme={null}
import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { searchTool, scrapeTool } from 'firecrawl-aisdk';

const { text } = await generateText({
  model: openai('gpt-5-mini'),
  prompt: '搜索 Firecrawl,抓取首个结果,并说明其功能',
  tools: { search: searchTool, scrape: scrapeTool },
});

console.log(text);
```

<div id="stream">
  ### 流式
</div>

```typescript theme={null}
import { streamText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { scrapeTool } from 'firecrawl-aisdk';

const result = streamText({
  model: openai('gpt-5-mini'),
  prompt: '抓取 https://firecrawl.dev 并解释它的功能',
  tools: { scrape: scrapeTool },
});

for await (const chunk of result.textStream) {
  process.stdout.write(chunk);
}
```

<div id="browser">
  ### 浏览器
</div>

将 `browserTool` 与 `ToolLoopAgent` 搭配使用，以实现交互式网页浏览。该 agent 可以在页面之间跳转、点击元素、填写表单并提取数据。

```typescript theme={null}
import { ToolLoopAgent, stepCountIs } from 'ai';
import { openai } from '@ai-sdk/openai';
import { browserTool } from 'firecrawl-aisdk';

const { text } = await new ToolLoopAgent({
  model: openai('gpt-5-mini'),
  tools: { browserTool },
  stopWhen: stepCountIs(25),
}).generate({
  prompt: 'Go to https://news.ycombinator.com, get the top 3 stories with their titles, points, and links.',
});

console.log(text);
```

<div id="browser-search">
  ### 浏览器 + 搜索
</div>

将 `browserTool` 与 `searchTool` 结合，适用于从搜索起步并通过交互式浏览继续的工作流。

```typescript theme={null}
import { ToolLoopAgent, stepCountIs } from 'ai';
import { openai } from '@ai-sdk/openai';
import { browserTool, searchTool } from 'firecrawl-aisdk';

const { text } = await new ToolLoopAgent({
  model: openai('gpt-5-mini'),
  tools: { browserTool, searchTool },
  stopWhen: stepCountIs(25),
}).generate({
  prompt: '搜索本周顶级 AI 论文,浏览并总结其核心发现。',
});

console.log(text);
```

<div id="agent">
  ### Agent
</div>

使用 `agentTool` 实现自动化网页数据采集。该 Agent 能自行搜索、浏览并提取数据。

```typescript theme={null}
import { generateText, stepCountIs } from 'ai';
import { openai } from '@ai-sdk/openai';
import { agentTool, pollTool } from 'firecrawl-aisdk';

const { text } = await generateText({
  model: openai('gpt-5-mini'),
  prompt: 'Find the founders of Firecrawl, their roles, and their backgrounds',
  tools: { agent: agentTool, poll: pollTool },
  stopWhen: stepCountIs(10),
});

console.log(text);
```
