Passer au contenu principal
Outils Evocrawl 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://evocrawl.com
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 Evocrawl 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

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

const { text } = await generateText({
  model: 'anthropic/claude-sonnet-4-5',
  tools: EvocrawlTools(),
  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
  `,
});

EvocrawlTools

EvocrawlTools() 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 { EvocrawlTools } from 'firecrawl-aisdk';

const tools = EvocrawlTools();

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 Evocrawl 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 = EvocrawlTools({
  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
EvocrawlTools({ interact: false });

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

// Inclure tous les outils disponibles
EvocrawlTools({ 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 Evocrawl, then scrape the most relevant result.',
  tools: { search, scrape },
});

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

Recherche + Scraping

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

const { text } = await generateText({
  model: 'anthropic/claude-sonnet-4-5',
  prompt: 'Recherche Evocrawl, 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.evocrawl.com 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 evocrawl.com?',
  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.evocrawl.com (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://evocrawl.com and https://docs.evocrawl.com, 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 Evocrawl, 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://evocrawl.com 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://evocrawl.com 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
  EvocrawlTools,     // EvocrawlTools({ search, scrape, interact, crawl, agent })

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