{"record":{"id":"0efb7d578d14ec43","repo":"firecrawl/open-lovable","slug":"firecrawl-api-key-not-configured","errorCode":null,"errorMessage":"Firecrawl API key not configured","messagePattern":"Firecrawl API key not configured","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"app/api/extract-brand-styles/route.ts","lineNumber":17,"sourceCode":"import { NextRequest, NextResponse } from 'next/server';\n\nexport async function POST(request: NextRequest) {\n  try {\n    const body = await request.json();\n    const url = body.url;\n    const prompt = body.prompt;\n\n    console.log('[extract-brand-styles] Extracting brand styles for:', url);\n    console.log('[extract-brand-styles] User prompt:', prompt);\n\n    // Call Firecrawl API to extract branding information\n    const FIRECRAWL_API_KEY = process.env.FIRECRAWL_API_KEY;\n\n    if (!FIRECRAWL_API_KEY) {\n      console.error('[extract-brand-styles] No Firecrawl API key found');\n      throw new Error('Firecrawl API key not configured');\n    }\n\n    console.log('[extract-brand-styles] Calling Firecrawl branding API for:', url);\n\n    const firecrawlResponse = await fetch('https://api.firecrawl.dev/v2/scrape', {\n      method: 'POST',\n      headers: {\n        'Authorization': `Bearer ${FIRECRAWL_API_KEY}`,\n        'Content-Type': 'application/json',\n      },\n      body: JSON.stringify({\n        url: url,\n        formats: ['branding'],\n      }),\n    });\n\n    if (!firecrawlResponse.ok) {\n      const errorText = await firecrawlResponse.text();","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/firecrawl/open-lovable/blob/69bd93bae7a9c97ef989eb70aabe6797fb3dac89/app/api/extract-brand-styles/route.ts#L1-L35","documentation":"A guard-clause error thrown before any network call when `process.env.FIRECRAWL_API_KEY` is unset or empty. The route requires a Firecrawl API key to extract branding data and refuses to run without one, surfacing a clear configuration error instead of a 401 from Firecrawl.","triggerScenarios":"POST /api/extract-brand-styles where the deployment has no FIRECRAWL_API_KEY environment variable set (or it's set to an empty string), so the `if (!FIRECRAWL_API_KEY)` guard fires.","commonSituations":"Forgetting to add the key to .env.local in development; not adding it in the hosting dashboard (Vercel env vars); adding it only to a preview environment; misspelling the variable name.","solutions":["Set FIRECRAWL_API_KEY in your environment (.env.local locally, hosting provider dashboard in production) and restart the server/redeploy","Verify the variable name is spelled exactly FIRECRAWL_API_KEY with no stray spaces","Confirm the env file is actually loaded (Next.js loads .env.local at startup only, not mid-session)","Get a valid key from the Firecrawl dashboard if the existing one was revoked"],"exampleFix":"// .env.local\n// before\n# (FIRECRAWL_API_KEY missing)\n// after\nFIRECRAWL_API_KEY=fc-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","handlingStrategy":"validation","validationCode":"if (!process.env.FIRECRAWL_API_KEY) {\n  throw new Error('Set FIRECRAWL_API_KEY before calling /api/extract-brand-styles');\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 styles = await fetch('/api/extract-brand-styles', { method: 'POST', body });\n} catch (e) {\n  if (e.message.includes('API key not configured')) {\n    // surface setup instructions to the user instead of retrying\n  }\n  throw e;\n}","preventionTips":["Add FIRECRAWL_API_KEY to .env.local and your hosting env config; redeploy after changes","Validate required env vars at server startup and fail fast with a clear message","Never rename env vars without grepping all process.env usages","Keep the key in a secrets manager rather than ad-hoc shell exports"],"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"}