firecrawl/open-lovable · error · Error

FIRECRAWL_API_KEY environment variable is not set

Error message

FIRECRAWL_API_KEY environment variable is not set

What it means

Guard-clause error thrown before the network call when `process.env.FIRECRAWL_API_KEY` is unset. The enhanced scrape route requires the key to authenticate against api.firecrawl.dev and fails fast with an explicit configuration message rather than a downstream 401.

Source

Thrown at app/api/scrape-url-enhanced/route.ts:34

    .replace(/[\u00A0]/g, ' '); // Non-breaking space
}

export async function POST(request: NextRequest) {
  try {
    const { url } = await request.json();
    
    if (!url) {
      return NextResponse.json({
        success: false,
        error: 'URL is required'
      }, { status: 400 });
    }
    
    console.log('[scrape-url-enhanced] Scraping with Firecrawl:', url);
    
    const FIRECRAWL_API_KEY = process.env.FIRECRAWL_API_KEY;
    if (!FIRECRAWL_API_KEY) {
      throw new Error('FIRECRAWL_API_KEY environment variable is not set');
    }
    
    // Make request to Firecrawl API with maxAge for 500% faster scraping
    const firecrawlResponse = await fetch('https://api.firecrawl.dev/v1/scrape', {
      method: 'POST',
      headers: {
        'Authorization': `Bearer ${FIRECRAWL_API_KEY}`,
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        url,
        formats: ['markdown', 'html', 'screenshot'],
        waitFor: 3000,
        timeout: 30000,
        blockAds: true,
        maxAge: 3600000, // Use cached data if less than 1 hour old (500% faster!)
        actions: [
          {

View on GitHub (pinned to 69bd93bae7)

Solutions

  1. Add FIRECRAWL_API_KEY to .env.local (dev) or the hosting provider's environment settings (prod) and restart/redeploy
  2. Confirm the exact variable name and that the value is non-empty
  3. Verify env loading: log `Boolean(process.env.FIRECRAWL_API_KEY)` at boot to catch load-order issues
  4. Generate a fresh key at firecrawl.dev if the old one is invalid — then also fix error [4]-style 401s

Example fix

// .env.local
// before
# (missing)
// after
FIRECRAWL_API_KEY=fc-your-key-here
Defensive patterns

Strategy: validation

Validate before calling

if (!process.env.FIRECRAWL_API_KEY) {
  throw new Error('FIRECRAWL_API_KEY is required before scraping');
}

Type guard

function hasFirecrawlKey(env: NodeJS.ProcessEnv): env is NodeJS.ProcessEnv & { FIRECRAWL_API_KEY: string } {
  return typeof env.FIRECRAWL_API_KEY === 'string' && env.FIRECRAWL_API_KEY.length > 0;
}

Try / catch

try {
  const data = await scrapeUrlEnhanced(url);
} catch (e) {
  if (e.message.includes('environment variable is not set')) {
    // show setup docs / disable the feature flag; do not retry
  }
  throw e;
}

Prevention

When it happens

Trigger: POST /api/scrape-url-enhanced where FIRECRAWL_API_KEY is missing from the process environment (not loaded, not deployed, or set as an empty string).

Common situations: Missing .env.local in local dev; env var not configured in the production hosting dashboard; server started before the env file was added; CI environments without the secret injected.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of firecrawl/open-lovable@69bd93bae7 (2026-08-28). Data as JSON: /api/errors/72f37cd6ebea5a28. Report an issue: GitHub.