> ## Documentation Index
> Fetch the complete documentation index at: https://firecrawl-abimaelmartell-agent-default-model.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Vercel AI SDK

> Vercel AI SDK 向け Firecrawl ツール。AI アプリケーション向けの Web スクレイピング、検索、ブラウジング、データ抽出。

Vercel AI SDK 向け Firecrawl ツール。AI アプリケーション向けの Web スクレイピング、検索、ブラウジング、データ抽出。

<div id="install">
  ## インストール
</div>

```bash theme={null}
npm install firecrawl-aisdk ai
```

環境変数を設定する：

```bash theme={null}
FIRECRAWL_API_KEY=fc-your-key       # https://firecrawl.dev
AI_GATEWAY_API_KEY=your-key         # https://vercel.com/ai-gateway
```

<Note>
  これらの例では [Vercel AI Gateway](https://vercel.com/ai-gateway) の string モデル形式を使用していますが、Firecrawl のツールはどの AI SDK プロバイダとも動作します。`openai('gpt-5-mini')`、`anthropic('claude-sonnet-4.5')`、または任意の [対応プロバイダ](https://ai-sdk.dev/providers/ai-sdk-providers) に差し替えて使用できます。
</Note>

<div id="quick-start">
  ## クイックスタート
</div>

これが最も手軽な始め方です。`FirecrawlTools()` を使うと、検索・スクレイピング・ブラウザ操作用のツールに加え、どのツールを使うべきかをモデルに指示する自動生成のシステムプロンプトをまとめて利用できます。

```typescript theme={null}
import { generateText, stepCountIs } from 'ai';
import { FirecrawlTools } from 'firecrawl-aisdk';

const { text } = await generateText({
  model: 'anthropic/claude-sonnet-4.5',
  prompt: 'Search for Firecrawl, scrape the top result, and summarize what it does',
  tools: FirecrawlTools(),
  stopWhen: stepCountIs(5),
});
```

カスタムオプションを指定する場合:

```typescript theme={null}
const tools = FirecrawlTools({
  apiKey: 'fc-custom-key',                // 省略可能。デフォルトは環境変数
  search: { limit: 3, country: 'US' },    // デフォルトの検索オプション
  scrape: { onlyMainContent: true },       // デフォルトのスクレイプオプション
  browser: {},                             // ブラウザツールを有効化
});
```

任意のツールは `false` を渡すことで無効化できます:

```typescript theme={null}
const tools = FirecrawlTools({
  browser: false,   // 検索 + スクレイプのみ
});
```

<div id="individual-tools">
  ## 個別ツール
</div>

各ツールは **2 通りの使い方** ができます。ツールとして直接利用することも（環境変数から `FIRECRAWL_API_KEY` を読み取ります）、カスタム設定用のファクトリ関数として呼び出すこともできます。

```typescript theme={null}
import { scrape, search } from 'firecrawl-aisdk';

// 直接使用 - 環境変数からFIRECRAWL_API_KEYを読み込む
const { text } = await generateText({
  model: 'anthropic/claude-sonnet-4.5',
  tools: { scrape, search },
  prompt: '...',
});

// またはカスタム設定のファクトリとして呼び出す
const customScrape = scrape({ apiKey: 'fc-custom-key' });
const { text } = await generateText({
  model: 'anthropic/claude-sonnet-4.5',
  tools: { scrape: customScrape },
  prompt: '...',
});
```

<div id="scrape">
  ### スクレイピング
</div>

```typescript theme={null}
import { generateText } from 'ai';
import { scrape } from 'firecrawl-aisdk';

const { text } = await generateText({
  model: 'anthropic/claude-sonnet-4.5',
  prompt: 'https://firecrawl.dev をスクレイピングして、その機能を要約してください',
  tools: { scrape },
});
```

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

```typescript theme={null}
import { generateText } from 'ai';
import { search } from 'firecrawl-aisdk';

const { text } = await generateText({
  model: 'anthropic/claude-sonnet-4.5',
  prompt: 'Search for Firecrawl and summarize what you find',
  tools: { search },
});
```

<div id="search-scrape">
  ### 検索 + スクレイピング
</div>

```typescript theme={null}
import { generateText } from 'ai';
import { search, scrape } from 'firecrawl-aisdk';

const { text } = await generateText({
  model: 'anthropic/claude-sonnet-4.5',
  prompt: 'Search for Firecrawl, scrape the top result, and explain what it does',
  tools: { search, scrape },
});
```

<div id="map">
  ### マップ
</div>

```typescript theme={null}
import { generateText } from 'ai';
import { map } from 'firecrawl-aisdk';

const { text } = await generateText({
  model: 'anthropic/claude-sonnet-4.5',
  prompt: 'https://docs.firecrawl.dev をマップして主要なセクションをリストアップしてください',
  tools: { map },
});
```

<div id="stream">
  ### ストリーミング
</div>

```typescript theme={null}
import { streamText } from 'ai';
import { scrape } from 'firecrawl-aisdk';

const result = streamText({
  model: 'anthropic/claude-sonnet-4.5',
  prompt: 'https://firecrawl.dev をスクレイピングして、それが何をするものか説明してください',
  tools: { scrape },
});

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

<div id="browser">
  ## ブラウザ
</div>

`browser` ツールは、初回の利用時に自動的にクラウドセッションを作成し、プロセス終了時に自動でクリーンアップを行います。

```typescript theme={null}
import { generateText, stepCountIs } from 'ai';
import { browser } from 'firecrawl-aisdk';

const { text } = await generateText({
  model: 'anthropic/claude-sonnet-4.5',
  tools: { browser: browser() },
  stopWhen: stepCountIs(25),
  prompt: 'Go to https://news.ycombinator.com and get the top 3 stories.',
});
```

ブラウザをリアルタイムで観察できるライブビュー用URLを取得したり、セッションのライフサイクルを手動で制御したりするには、次のようにします：

```typescript theme={null}
const browserTool = browser();
console.log('Live view:', await browserTool.start());

const { text } = await generateText({
  model: 'anthropic/claude-sonnet-4.5',
  tools: { browserTool },
  stopWhen: stepCountIs(25),
  prompt: 'Go to https://news.ycombinator.com and get the top 3 stories.',
});

await browserTool.close();
```

<div id="browser-search">
  ### Browser + Search
</div>

```typescript theme={null}
import { generateText, stepCountIs } from 'ai';
import { browser, search } from 'firecrawl-aisdk';

const { text } = await generateText({
  model: 'anthropic/claude-sonnet-4.5',
  tools: { browser: browser(), search },
  stopWhen: stepCountIs(25),
  prompt: '今週のトップAI論文を検索し、閲覧して、主要な知見を要約する。',
});
```

<div id="async-tools">
  ## 非同期ツール
</div>

Crawl、batch scrape、extract、agent はジョブ ID を返します。結果を取得するには `poll` と組み合わせて使用します：

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

```typescript theme={null}
import { generateText } from 'ai';
import { crawl, poll } from 'firecrawl-aisdk';

const { text } = await generateText({
  model: 'anthropic/claude-sonnet-4.5',
  prompt: 'Crawl https://docs.firecrawl.dev (limit 3 pages) and summarize',
  tools: { crawl, poll },
});
```

<div id="batch-scrape">
  ### バッチスクレイプ
</div>

```typescript theme={null}
import { generateText } from 'ai';
import { batchScrape, poll } from 'firecrawl-aisdk';

const { text } = await generateText({
  model: 'anthropic/claude-sonnet-4.5',
  prompt: 'Scrape https://firecrawl.dev and https://docs.firecrawl.dev, then compare',
  tools: { batchScrape, poll },
});
```

<div id="agent">
  ### エージェント
</div>

自律的な Web データ収集 — 自動で検索・ページ遷移・データ抽出を行います。

```typescript theme={null}
import { generateText, stepCountIs } from 'ai';
import { agent, poll } from 'firecrawl-aisdk';

const { text } = await generateText({
  model: 'anthropic/claude-sonnet-4.5',
  prompt: 'Find the founders of Firecrawl, their roles, and their backgrounds',
  tools: { agent, poll },
  stopWhen: stepCountIs(10),
});
```

<div id="all-exports">
  ## エクスポート一覧
</div>

```typescript theme={null}
import {
  // デュアルパーパスツール（直接使用またはファクトリーとして呼び出し可能）
  scrape,             // 単一URLをスクレイプ
  search,             // ウェブを検索
  map,                // サイト上のURLを探索
  crawl,              // 複数ページをクロール（非同期）
  batchScrape,        // 複数URLをスクレイプ（非同期）
  agent,              // 自律型ウェブエージェント（非同期）
  extract,            // 構造化データを抽出（非同期）

  // ジョブ管理
  poll,               // 非同期ジョブの結果をポーリング
  status,             // ジョブのステータスを確認
  cancel,             // 実行中のジョブをキャンセル

  // ブラウザ（ファクトリー専用）
  browser,            // browser({ firecrawlApiKey: '...' })

  // オールインワンバンドル
  FirecrawlTools,     // FirecrawlTools({ apiKey, search, scrape, browser })

  // ヘルパー
  stepLogger,         // ツール呼び出しごとのトークン統計
  logStep,            // シンプルな1行ロギング
} from 'firecrawl-aisdk';
```
