firecrawl/open-lovable · error · Error
Firecrawl API key not configured
Error message
Firecrawl API key not configured
What it means
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.
Source
Thrown at app/api/extract-brand-styles/route.ts:17
import { NextRequest, NextResponse } from 'next/server';
export async function POST(request: NextRequest) {
try {
const body = await request.json();
const url = body.url;
const prompt = body.prompt;
console.log('[extract-brand-styles] Extracting brand styles for:', url);
console.log('[extract-brand-styles] User prompt:', prompt);
// Call Firecrawl API to extract branding information
const FIRECRAWL_API_KEY = process.env.FIRECRAWL_API_KEY;
if (!FIRECRAWL_API_KEY) {
console.error('[extract-brand-styles] No Firecrawl API key found');
throw new Error('Firecrawl API key not configured');
}
console.log('[extract-brand-styles] Calling Firecrawl branding API for:', url);
const firecrawlResponse = await fetch('https://api.firecrawl.dev/v2/scrape', {
method: 'POST',
headers: {
'Authorization': `Bearer ${FIRECRAWL_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
url: url,
formats: ['branding'],
}),
});
if (!firecrawlResponse.ok) {
const errorText = await firecrawlResponse.text();View on GitHub (pinned to 69bd93bae7)
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
Example fix
// .env.local // before # (FIRECRAWL_API_KEY missing) // after FIRECRAWL_API_KEY=fc-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Defensive patterns
Strategy: validation
Validate before calling
if (!process.env.FIRECRAWL_API_KEY) {
throw new Error('Set FIRECRAWL_API_KEY before calling /api/extract-brand-styles');
} 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 styles = await fetch('/api/extract-brand-styles', { method: 'POST', body });
} catch (e) {
if (e.message.includes('API key not configured')) {
// surface setup instructions to the user instead of retrying
}
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
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
- FIRECRAWL_API_KEY environment variable is not set
- MORPH_API_KEY is not set
- Firecrawl API returned ${firecrawlResponse.status}
- No branding data in Firecrawl response
- Failed to capture screenshot
AI-assisted analysis of firecrawl/open-lovable@69bd93bae7 (2026-08-28).
Data as JSON: /api/errors/0efb7d578d14ec43.
Report an issue: GitHub.