{"record":{"id":"d93e6acb5a431306","repo":"vercel/ai","slug":"description-api-key-is-missing-pass-it-using-t","errorCode":null,"errorMessage":"${description} API key is missing. Pass it using the 'apiKey' parameter. Environment variables are not supported in this environment.","messagePattern":"(.+?) API key is missing\\. Pass it using the 'apiKey' parameter\\. Environment variables are not supported in this environment\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/fal/src/fal-provider.ts","lineNumber":104,"sourceCode":"const defaultBaseURL = 'https://fal.run';\n\nfunction loadFalApiKey({\n  apiKey,\n  description = 'fal.ai',\n}: {\n  apiKey: string | undefined;\n  description?: string;\n}): string {\n  if (typeof apiKey === 'string') {\n    return apiKey;\n  }\n\n  if (apiKey != null) {\n    throw new Error(`${description} API key must be a string.`);\n  }\n\n  if (typeof process === 'undefined') {\n    throw new Error(\n      `${description} API key is missing. Pass it using the 'apiKey' parameter. Environment variables are not supported in this environment.`,\n    );\n  }\n\n  let envApiKey = process.env.FAL_API_KEY;\n  if (envApiKey == null) {\n    envApiKey = process.env.FAL_KEY;\n  }\n\n  if (envApiKey == null) {\n    throw new Error(\n      `${description} API key is missing. Pass it using the 'apiKey' parameter or set either the FAL_API_KEY or FAL_KEY environment variable.`,\n    );\n  }\n\n  if (typeof envApiKey !== 'string') {\n    throw new Error(\n      `${description} API key must be a string. The value of the environment variable is not a string.`,","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/fal/src/fal-provider.ts#L86-L122","documentation":"loadFalApiKey throws this when no apiKey parameter was given and `typeof process === 'undefined'`, meaning environment variables are unavailable (edge runtimes, browsers). The fal provider cannot resolve a key in such environments, so it fails fast with a targeted message.","triggerScenarios":"Calling createFal() with no apiKey in an edge runtime (Vercel Edge, Cloudflare Workers) or browser bundle where `process` is not defined.","commonSituations":"Deploying fal-based routes to edge functions without supplying the key via parameter or runtime env binding.","solutions":["Pass the key explicitly: createFal({ apiKey: 'your-fal-key' }).","In edge runtimes, read your platform env binding and pass it as apiKey.","Ensure the bundler polyfills `process.env` if you must rely on env vars."],"exampleFix":"// before (edge runtime)\nconst fal = createFal();\n// after\nconst fal = createFal({ apiKey: env.FAL_KEY });","handlingStrategy":"validation","validationCode":"function resolveFalKey(envBinding?: string): string {\n  const key = envBinding ?? (typeof process !== 'undefined' ? process.env.FAL_API_KEY ?? process.env.FAL_KEY : undefined);\n  if (!key) throw new Error('fal API key required: pass apiKey or set FAL_API_KEY/FAL_KEY');\n  return key;\n}\nconst fal = createFal({ apiKey: resolveFalKey(edgeEnv.FAL_KEY) });","typeGuard":null,"tryCatchPattern":"let fal;\ntry {\n  fal = createFal();\n} catch (e) {\n  if ((e as Error).message.includes('API key is missing')) {\n    fal = createFal({ apiKey: runtimeEnv.FAL_KEY });\n  } else throw e;\n}","preventionTips":["Always pass apiKey explicitly when targeting edge/browser runtimes.","Detect `typeof process === 'undefined'` in bootstrap code and supply platform env bindings.","Document required env vars per deployment target."],"tags":["fal","api-key","edge-runtime","missing-env-var"],"backgroundTag":"missing-api-key","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}