{"record":{"id":"72f37cd6ebea5a28","repo":"firecrawl/open-lovable","slug":"firecrawl-api-key-environment-variable-is-not-set","errorCode":null,"errorMessage":"FIRECRAWL_API_KEY environment variable is not set","messagePattern":"FIRECRAWL_API_KEY environment variable is not set","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"app/api/scrape-url-enhanced/route.ts","lineNumber":34,"sourceCode":"    .replace(/[\\u00A0]/g, ' '); // Non-breaking space\n}\n\nexport async function POST(request: NextRequest) {\n  try {\n    const { url } = await request.json();\n    \n    if (!url) {\n      return NextResponse.json({\n        success: false,\n        error: 'URL is required'\n      }, { status: 400 });\n    }\n    \n    console.log('[scrape-url-enhanced] Scraping with Firecrawl:', url);\n    \n    const FIRECRAWL_API_KEY = process.env.FIRECRAWL_API_KEY;\n    if (!FIRECRAWL_API_KEY) {\n      throw new Error('FIRECRAWL_API_KEY environment variable is not set');\n    }\n    \n    // Make request to Firecrawl API with maxAge for 500% faster scraping\n    const firecrawlResponse = await fetch('https://api.firecrawl.dev/v1/scrape', {\n      method: 'POST',\n      headers: {\n        'Authorization': `Bearer ${FIRECRAWL_API_KEY}`,\n        'Content-Type': 'application/json'\n      },\n      body: JSON.stringify({\n        url,\n        formats: ['markdown', 'html', 'screenshot'],\n        waitFor: 3000,\n        timeout: 30000,\n        blockAds: true,\n        maxAge: 3600000, // Use cached data if less than 1 hour old (500% faster!)\n        actions: [\n          {","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/firecrawl/open-lovable/blob/69bd93bae7a9c97ef989eb70aabe6797fb3dac89/app/api/scrape-url-enhanced/route.ts#L16-L52","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Add FIRECRAWL_API_KEY to .env.local (dev) or the hosting provider's environment settings (prod) and restart/redeploy","Confirm the exact variable name and that the value is non-empty","Verify env loading: log `Boolean(process.env.FIRECRAWL_API_KEY)` at boot to catch load-order issues","Generate a fresh key at firecrawl.dev if the old one is invalid — then also fix error [4]-style 401s"],"exampleFix":"// .env.local\n// before\n# (missing)\n// after\nFIRECRAWL_API_KEY=fc-your-key-here","handlingStrategy":"validation","validationCode":"if (!process.env.FIRECRAWL_API_KEY) {\n  throw new Error('FIRECRAWL_API_KEY is required before scraping');\n}","typeGuard":"function hasFirecrawlKey(env: NodeJS.ProcessEnv): env is NodeJS.ProcessEnv & { FIRECRAWL_API_KEY: string } {\n  return typeof env.FIRECRAWL_API_KEY === 'string' && env.FIRECRAWL_API_KEY.length > 0;\n}","tryCatchPattern":"try {\n  const data = await scrapeUrlEnhanced(url);\n} catch (e) {\n  if (e.message.includes('environment variable is not set')) {\n    // show setup docs / disable the feature flag; do not retry\n  }\n  throw e;\n}","preventionTips":["Set FIRECRAWL_API_KEY in .env.local and the production hosting env; redeploy after adding","Run a startup env-var validation that lists any missing required keys","Inject the secret in CI/preview environments so tests don't silently skip scraping","Check with console.log(Boolean(process.env.FIRECRAWL_API_KEY)) if errors persist after configuration"],"tags":["configuration","env-var","firecrawl"],"backgroundTag":"missing-env-var","analyzedSha":"69bd93bae7a9c97ef989eb70aabe6797fb3dac89","analyzedAt":"2026-08-28T22:20:32.339Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}