Skip to main content
Integrate Firecrawl with Vercel AI SDK to build AI applications powered by web data.

Setup

npm install ai @ai-sdk/openai @mendable/firecrawl-js 
Create .env file:
FIRECRAWL_API_KEY=your_firecrawl_key
OPENAI_API_KEY=your_openai_key
Note: If using Node < 20, install dotenv and add import 'dotenv/config' to your code.

Scrape + Generate Text

This example demonstrates a simple workflow: scrape a website and generate text using the Vercel AI SDK.
import FirecrawlApp from '@mendable/firecrawl-js';
import { openai } from '@ai-sdk/openai';
import { generateText } from 'ai';

const firecrawl = new FirecrawlApp({ apiKey: process.env.FIRECRAWL_API_KEY });

const scrapeResult = await firecrawl.scrape('https://firecrawl.dev', {
    formats: ['markdown']
});

console.log('Scraped content length:', scrapeResult.markdown?.length);

const { text } = await generateText({
    model: openai('gpt-5-nano'),
    prompt: `Summarize: ${scrapeResult.markdown}`
});

console.log('Summary:', text);

Scrape + Stream Text

This example shows how to stream AI responses for better user experience.
import FirecrawlApp from '@mendable/firecrawl-js';
import { openai } from '@ai-sdk/openai';
import { streamText } from 'ai';

const firecrawl = new FirecrawlApp({ apiKey: process.env.FIRECRAWL_API_KEY });

const scrapeResult = await firecrawl.scrape('https://stripe.com', {
    formats: ['markdown']
});

console.log('Scraped content length:', scrapeResult.markdown?.length);

const { textStream } = await streamText({
    model: openai('gpt-5-nano'),
    prompt: `Analyze this company and list key products: ${scrapeResult.markdown}`
});

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

Tool Calling

This example demonstrates how to use Vercel AI SDK’s tool calling feature to let the model decide when to scrape websites.
import FirecrawlApp from '@mendable/firecrawl-js';
import { openai } from '@ai-sdk/openai';
import { generateText, tool } from 'ai';
import { z } from 'zod';

console.log('Initializing Firecrawl...');
const firecrawl = new FirecrawlApp({ apiKey: process.env.FIRECRAWL_API_KEY });

const scrapeWebsiteTool = tool({
    description: 'Scrape content from any website URL',
    inputSchema: z.object({
        url: z.string().url().describe('The URL to scrape')
    }),
    execute: async ({ url }) => {
        console.log('Scraping:', url);
        const result = await firecrawl.scrape(url, {
            formats: ['markdown']
        });
        console.log('Scraped content preview:', result.markdown?.slice(0, 200) + '...');
        return { content: result.markdown };
    }
});

console.log('Generating text with AI...');

const { text, toolCalls } = await generateText({
    model: openai('gpt-5-nano'),
    prompt: 'What is Firecrawl? Visit firecrawl.dev and tell me about it.',
    tools: {
        scrapeWebsite: scrapeWebsiteTool
    },
});

console.log('Tool calls:', toolCalls);
// Continue the conversation OR use the text for something else

Structured Data Extraction

This example shows how to extract structured data using Vercel AI SDK’s structured output feature.
import FirecrawlApp from '@mendable/firecrawl-js';
import { openai } from '@ai-sdk/openai';
import { generateObject } from 'ai';
import { z } from 'zod';

const firecrawl = new FirecrawlApp({ apiKey: process.env.FIRECRAWL_API_KEY });

const scrapeResult = await firecrawl.scrape('https://stripe.com', {
    formats: ['markdown']
});

console.log('Scraped content length:', scrapeResult.markdown?.length);

const CompanyInfoSchema = z.object({
    name: z.string(),
    industry: z.string(),
    description: z.string(),
    products: z.array(z.string())
});

const { object } = await generateObject({
    model: openai('gpt-5-nano'),
    schema: CompanyInfoSchema,
    prompt: `Extract company information from this website content: ${scrapeResult.markdown}`
});

console.log('Extracted company info:', object);
For more examples, check the Vercel AI SDK documentation.
I