{"record":{"id":"19d3ea9d4b4fd247","repo":"chroma-core/chroma","slug":"google-api-key-is-required-please-provide-it-in-t","errorCode":null,"errorMessage":"Google API key is required. Please provide it in the constructor or set the environment variable ${apiKeyEnvVar}.","messagePattern":"Google API key is required\\. Please provide it in the constructor or set the environment variable (.+?)\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"clients/js/packages/chromadb-core/src/embeddings/GoogleGeminiEmbeddingFunction.ts","lineNumber":36,"sourceCode":"  private api_key_env_var: string;\n  private model: string;\n  private googleGenAiApi?: any;\n  private taskType: string;\n\n  constructor({\n    googleApiKey,\n    model = \"embedding-001\",\n    taskType = \"RETRIEVAL_DOCUMENT\",\n    apiKeyEnvVar = \"GOOGLE_API_KEY\",\n  }: {\n    googleApiKey?: string;\n    model?: string;\n    taskType?: string;\n    apiKeyEnvVar: string;\n  }) {\n    const apiKey = googleApiKey ?? process.env[apiKeyEnvVar];\n    if (!apiKey) {\n      throw new Error(\n        `Google API key is required. Please provide it in the constructor or set the environment variable ${apiKeyEnvVar}.`,\n      );\n    }\n\n    this.api_key = apiKey;\n    this.api_key_env_var = apiKeyEnvVar;\n    this.model = model;\n    this.taskType = taskType;\n  }\n\n  private async loadClient() {\n    if (this.googleGenAiApi) return;\n    try {\n      // eslint-disable-next-line global-require,import/no-extraneous-dependencies\n      const { googleGenAi } =\n        await GoogleGenerativeAiEmbeddingFunction.import();\n      googleGenAiApi = googleGenAi;\n      // googleGenAiApi.init(this.api_key);","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/clients/js/packages/chromadb-core/src/embeddings/GoogleGeminiEmbeddingFunction.ts#L18-L54","documentation":"GoogleGenerativeAiEmbeddingFunction requires a Gemini API key at construction time: either the explicit googleApiKey parameter or the environment variable named by apiKeyEnvVar (default GOOGLE_API_KEY). If neither yields a truthy string the constructor throws synchronously — no network call is attempted, so this fails at client-setup time, not at embed time.","triggerScenarios":"new GoogleGenerativeAiEmbeddingFunction({ model: \"embedding-001\", apiKeyEnvVar: \"GOOGLE_API_KEY\" }) with GOOGLE_API_KEY unset and no googleApiKey passed; or a custom apiKeyEnvVar name that does not match any exported variable (common in CI, cron, containers).","commonSituations":"dotenv loaded after the embedding function is constructed; custom apiKeyEnvVar name that differs from what ops exported; key present in a deploy secret but never exported into the process env; works locally (shell profile) but fails in systemd/CI where the profile is not sourced.","solutions":["Pass the key explicitly: new GoogleGenerativeAiEmbeddingFunction({ googleApiKey: process.env.GEMINI_API_KEY!, ... })","Or export the env var matching the configured name: export GOOGLE_API_KEY=... for the default","Verify visibility inside the running process: node -e \"console.log(!!process.env.GOOGLE_API_KEY)\"","Ensure import \"dotenv/config\" (or equivalent) runs before the embedding function is constructed"],"exampleFix":"// before\nconst ef = new GoogleGenerativeAiEmbeddingFunction({ model: \"embedding-001\", apiKeyEnvVar: \"GOOGLE_API_KEY\" }); // throws: env unset\n\n// after\nimport \"dotenv/config\";\nconst ef = new GoogleGenerativeAiEmbeddingFunction({\n  googleApiKey: process.env.GOOGLE_API_KEY!, // explicit; fails loudly at boot if missing\n  model: \"embedding-001\",\n});","handlingStrategy":"validation","validationCode":"function requireEnv(name: string): string {\n  const v = process.env[name];\n  if (!v) throw new Error(`Missing required env var ${name}`);\n  return v;\n}\n// before constructing:\nconst googleApiKey = requireEnv(\"GOOGLE_API_KEY\");\nconst ef = new GoogleGenerativeAiEmbeddingFunction({ googleApiKey, model: \"embedding-001\", apiKeyEnvVar: \"GOOGLE_API_KEY\" });","typeGuard":null,"tryCatchPattern":"try {\n  ef = new GoogleGenerativeAiEmbeddingFunction({ apiKeyEnvVar: \"GOOGLE_API_KEY\" });\n} catch (e) {\n  if (e instanceof Error && e.message.includes(\"API key is required\")) {\n    // configuration error: stop boot with an ops-facing message; do not retry\n  }\n  throw e;\n}","preventionTips":["Validate every required env var at process start and fail fast before any work","Load dotenv at the entrypoint's first line, before any client construction","Keep env var names in one shared constants module so code and infra cannot drift"],"tags":["api-key","env-var","google","gemini","configuration","embeddings"],"backgroundTag":"missing-api-key","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}