Passer au contenu principal
Outils Firecrawl pour Vercel AI SDK. Effectuez des recherches, faites du scraping, Interact avec des pages et effectuez un crawl du web dans vos applications d’IA.”

Installation

npm install firecrawl-aisdk ai
Configurez les variables d’environnement :
FIRECRAWL_API_KEY=fc-your-key       # https://firecrawl.dev
AI_GATEWAY_API_KEY=your-key         # https://vercel.com/ai-gateway
Ces exemples utilisent le format de modèle en chaîne de caractères du Vercel AI Gateway, mais les outils Firecrawl fonctionnent avec n’importe quel fournisseur de SDK d’IA. Vous pouvez également utiliser des imports de fournisseur comme anthropic('claude-sonnet-4-5-20250514') depuis @ai-sdk/anthropic.

Démarrage rapide

FirecrawlTools() inclut search, scrape et interact par défaut.
import { generateText, stepCountIs } from 'ai';
import { FirecrawlTools } from 'firecrawl-aisdk';

const { text } = await generateText({
  model: 'anthropic/claude-sonnet-4-5',
  tools: FirecrawlTools(),
  stopWhen: stepCountIs(30),
  prompt: `
    1. Use interact on Hacker News to identify the top story
    2. Search for other perspectives on the same topic
    3. Scrape the most relevant pages you found
    4. Summarize everything you found
  `,
});

FirecrawlTools

FirecrawlTools() vous fournit les outils par défaut ainsi qu’un systemPrompt généré automatiquement, que vous pouvez transmettre à generateText.
import { generateText, stepCountIs } from 'ai';
import { FirecrawlTools } from 'firecrawl-aisdk';

const tools = FirecrawlTools();

const { text } = await generateText({
  model: 'anthropic/claude-sonnet-4-5',
  system: `${tools.systemPrompt}\n\nAnswer with citations when possible.`,
  tools,
  stopWhen: stepCountIs(20),
  prompt: 'Find the current Firecrawl pricing page and explain the available plans.',
});
Vous pouvez personnaliser les paramètres par défaut, activer les outils asynchrones ou désactiver certains outils :
const tools = FirecrawlTools({
  search: { limit: 5 },
  scrape: { formats: ['markdown'], onlyMainContent: true },
  interact: { profile: { name: 'my-session', saveChanges: true } },
  crawl: true,
  agent: true,
});
// Désactiver interact, conserver search + scrape
FirecrawlTools({ interact: false });

// Activer la compatibilité Browser dépréciée
FirecrawlTools({ browser: {} });

// Inclure tous les outils disponibles
FirecrawlTools({ all: true });
Pour faire du scraping afin de répondre à une question sur une page, privilégiez le format query :
formats: [{ type: 'query', prompt: 'What does this page say about pricing and rate limits?' }]
Utilisez formats: ['markdown'] uniquement si vous avez besoin de tout le contenu de la page.

Outils individuels

Chaque outil peut être utilisé directement ou appelé en lui passant des options :
import { generateText } from 'ai';
import { scrape, search } from 'firecrawl-aisdk';

const { text } = await generateText({
  model: 'anthropic/claude-sonnet-4-5',
  prompt: 'Search for Firecrawl, then scrape the most relevant result.',
  tools: { search, scrape },
});

const customScrape = scrape({ apiKey: 'fc-custom-key', apiUrl: 'https://api.firecrawl.dev' });

Recherche + Scraping

import { generateText } from 'ai';
import { search, scrape } from 'firecrawl-aisdk';

const { text } = await generateText({
  model: 'anthropic/claude-sonnet-4-5',
  prompt: 'Recherche Firecrawl, scrape le premier résultat officiel et explique ce que ça fait.',
  tools: { search, scrape },
});

Cartographie

import { generateText } from 'ai';
import { map } from 'firecrawl-aisdk';

const { text } = await generateText({
  model: 'anthropic/claude-sonnet-4-5',
  prompt: 'Map https://docs.firecrawl.dev and list the main sections.',
  tools: { map },
});

Streaming

import { streamText, stepCountIs } from 'ai';
import { scrape } from 'firecrawl-aisdk';

const result = streamText({
  model: 'anthropic/claude-sonnet-4-5',
  prompt: 'What is the first 100 words of firecrawl.dev?',
  tools: { scrape },
  stopWhen: stepCountIs(3),
});

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

await result.fullStream;

Interact

interact() crée une session interactive basée sur le scraping. Appelez start(url) pour initialiser une session et obtenir une URL de vue en direct, puis laissez le modèle réutiliser cette session via l’outil interact.
import { generateText, stepCountIs } from 'ai';
import { interact, search } from 'firecrawl-aisdk';

const interactTool = interact();
console.log('Live view:', await interactTool.start('https://news.ycombinator.com'));

const { text } = await generateText({
  model: 'anthropic/claude-sonnet-4-5',
  tools: { interact: interactTool, search },
  stopWhen: stepCountIs(25),
  prompt: 'Use interact on the current Hacker News session, find the top story, then search for more context.',
});

await interactTool.close();
Si vous avez besoin de l’URL de la vue en direct après le démarrage, utilisez interactTool.interactiveLiveViewUrl. Réutilisez l’état du navigateur d’une session à l’autre avec des profils :
const interactTool = interact({
  profile: { name: 'my-session', saveChanges: true },
});
browser() est déprécié. Préférez interact().

Outils asynchrones

Crawl, extraction par lot et agent renvoient un ID de tâche. Associez-les à poll.

Crawl

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 },
});

Extraction par lot

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 them.',
  tools: { batchScrape, poll },
});

Agent

Collecte autonome de données sur le web qui recherche, navigue et extrait des données en toute autonomie.
import { generateText, stepCountIs } from 'ai';
import { agent, poll } from 'firecrawl-aisdk';

const { text } = await generateText({
  model: 'anthropic/claude-sonnet-4-5',
  prompt: 'Trouve les fondateurs de Firecrawl, leurs rôles et leurs parcours.',
  tools: { agent, poll },
  stopWhen: stepCountIs(10),
});

Journalisation

import { generateText } from 'ai';
import { logStep, scrape, stepLogger } from 'firecrawl-aisdk';

const logger = stepLogger();

const { text, usage } = await generateText({
  model: 'anthropic/claude-sonnet-4-5',
  prompt: 'Scrape https://firecrawl.dev and summarize it.',
  tools: { scrape },
  onStepFinish: logger.onStep,
  experimental_onToolCallFinish: logger.onToolCallFinish,
});

logger.close();
logger.summary(usage);

await generateText({
  model: 'anthropic/claude-sonnet-4-5',
  prompt: 'Scrape https://firecrawl.dev and summarize it again.',
  tools: { scrape },
  onStepFinish: logStep,
});

Tous les exports

import {
  // Outils principaux
  search,             // Rechercher sur le web
  scrape,             // Faire du scraping sur une seule URL
  map,                // Découvrir les URLs d'un site
  crawl,              // Crawler plusieurs pages (async, utiliser poll)
  batchScrape,        // Faire du scraping sur plusieurs URLs (async, utiliser poll)
  agent,              // Recherche web autonome (async, utiliser poll)

  // Gestion des tâches
  poll,               // Interroger les tâches async pour récupérer les résultats
  status,             // Vérifier l'état d'une tâche
  cancel,             // Annuler les tâches en cours

  // Outils Browser/session
  interact,           // interact({ profile: { name: '...' } })
  browser,            // export de compatibilité déprécié

  // Bundle tout-en-un
  FirecrawlTools,     // FirecrawlTools({ search, scrape, interact, crawl, agent })

  // Utilitaires
  stepLogger,         // Statistiques de tokens par appel d'outil
  logStep,            // Journalisation simple en une ligne
} from 'firecrawl-aisdk';