{"record":{"id":"3deceb63110c0494","repo":"vercel/ai","slug":"description-api-key-must-be-a-string","errorCode":null,"errorMessage":"${description} API key must be a string.","messagePattern":"(.+?) API key must be a string\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/fal/src/fal-provider.ts","lineNumber":100,"sourceCode":"   */\n  textEmbeddingModel(modelId: string): never;\n}\n\nconst 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  }","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/fal/src/fal-provider.ts#L82-L118","documentation":"loadFalApiKey throws a plain Error when the apiKey parameter is provided but is not a string (e.g. a number, object, or boolean). The fal provider requires the API key to be a string whether passed explicitly or loaded from the environment.","triggerScenarios":"createFal({ apiKey: 12345 }) or createFal({ apiKey: someConfigObject }) where the value is non-null and not a string.","commonSituations":"Config values read from JSON/YAML that yield numbers, or passing a credentials object instead of the key string.","solutions":["Pass the API key as a string: createFal({ apiKey: '...' }).","Coerce/validate the config value with String(apiKey) only after confirming it is scalar and correct.","Remove the apiKey param entirely to fall back to FAL_API_KEY/FAL_KEY env vars."],"exampleFix":"// before\ncreateFal({ apiKey: process.env.FAL_KEY as unknown as number })\n// after\nconst apiKey = process.env.FAL_KEY;\nif (typeof apiKey !== 'string') throw new Error('FAL key missing');\ncreateFal({ apiKey })","handlingStrategy":"validation","validationCode":"const key: unknown = config.falApiKey;\nif (key != null && typeof key !== 'string') {\n  throw new Error('fal apiKey config must be a string');\n}","typeGuard":"function isApiKey(v: unknown): v is string {\n  return typeof v === 'string' && v.length > 0;\n}","tryCatchPattern":null,"preventionTips":["Type your config as `apiKey?: string` so TS catches non-string values.","Validate config at startup with zod or similar.","Never pass raw JSON/YAML values without parsing them into strings."],"tags":["fal","api-key","configuration","type-error"],"backgroundTag":"invalid-api-key","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}