{"record":{"id":"8284c971086f1bf1","repo":"vercel/ai","slug":"description-api-key-must-be-a-string-the-value","errorCode":null,"errorMessage":"${description} API key must be a string. The value of the environment variable is not a string.","messagePattern":"(.+?) API key must be a string\\. The value of the environment variable is not a string\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/fal/src/fal-provider.ts","lineNumber":121,"sourceCode":"  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.`,\n    );\n  }\n\n  return envApiKey;\n}\n\n/**\n * Create a fal.ai provider instance.\n */\nexport function createFal(options: FalProviderSettings = {}): FalProvider {\n  const baseURL = withoutTrailingSlash(options.baseURL ?? defaultBaseURL);\n  const getHeaders = () =>\n    withUserAgentSuffix(\n      {\n        Authorization: `Key ${loadFalApiKey({\n          apiKey: options.apiKey,\n        })}`,","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/fal/src/fal-provider.ts#L103-L139","documentation":"loadFalApiKey throws this when the resolved environment variable (FAL_API_KEY or FAL_KEY) exists but its value is not a string. This guards against non-string env values that some runtimes or test setups can inject.","triggerScenarios":"process.env.FAL_API_KEY or FAL_KEY is set to a non-string value (e.g. an object assigned directly in tests or a runtime exposing non-string env entries).","commonSituations":"Test code that mocks process.env with non-string values, or exotic runtime environments where env entries are not plain strings.","solutions":["Set the env variable to a plain string value.","Fix test mocks so process.env.FAL_API_KEY is a string.","Bypass env lookup by passing createFal({ apiKey: '...' }) with an explicit string."],"exampleFix":"// before (test mock)\nprocess.env.FAL_API_KEY = { token: 'x' } as any;\n// after\nprocess.env.FAL_API_KEY = 'fal_key_string';","handlingStrategy":"type-guard","validationCode":"const envKey: unknown = process.env.FAL_API_KEY ?? process.env.FAL_KEY;\nif (envKey != null && typeof envKey !== 'string') {\n  throw new Error('FAL_API_KEY/FAL_KEY env value must be a string');\n}","typeGuard":"function isStringEnvValue(v: unknown): v is string {\n  return typeof v === 'string';\n}","tryCatchPattern":null,"preventionTips":["Mock process.env only with string values in tests.","Restore env vars after each test (afterEach / vi.unstubAllEnvs).","Avoid assigning objects into process.env anywhere in app code."],"tags":["fal","api-key","environment","type-error"],"backgroundTag":"invalid-api-key","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}