{"record":{"id":"daa3abe66b837cf0","repo":"chroma-core/chroma","slug":"the-self-api-key-env-var-environment-variable-is-daa3ab","errorCode":null,"errorMessage":"The {self.api_key_env_var} environment variable is not set.","messagePattern":"The (.+?) environment variable is not set\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"chromadb/utils/embedding_functions/google_embedding_function.py","lineNumber":258,"sourceCode":"        except ImportError:\n            raise ValueError(\n                \"The Google Generative AI python package is not installed. Please install it with `pip install google-generativeai`\"\n            )\n\n        if api_key is not None:\n            warnings.warn(\n                \"Direct api_key configuration will not be persisted. \"\n                \"Please use environment variables via api_key_env_var for persistent storage.\",\n                DeprecationWarning,\n            )\n        if os.getenv(\"GOOGLE_API_KEY\") is not None:\n            self.api_key_env_var = \"GOOGLE_API_KEY\"\n        else:\n            self.api_key_env_var = api_key_env_var\n\n        self.api_key = api_key or os.getenv(self.api_key_env_var)\n        if not self.api_key:\n            raise ValueError(\n                f\"The {self.api_key_env_var} environment variable is not set.\"\n            )\n\n        self.model_name = model_name\n        self.task_type = task_type\n        self.dimension = dimension\n\n        genai.configure(\n            api_key=self.api_key,\n            client_options={\"headers\": {\"x-goog-api-client\": f\"chroma/{__version__}\"}},\n        )\n        self._genai = genai\n\n    def __call__(self, input: Documents) -> Embeddings:\n        \"\"\"\n        Generate embeddings for the given documents.\n\n        Args:","sourceCodeStart":240,"sourceCodeEnd":276,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/chromadb/utils/embedding_functions/google_embedding_function.py#L240-L276","documentation":"The legacy GoogleGenerativeAiEmbeddingFunction resolves its credential in priority order: explicit api_key argument (deprecated, emits DeprecationWarning), then GOOGLE_API_KEY if that env var is set (it then takes over api_key_env_var), then the variable named by api_key_env_var (default GEMINI_API_KEY). If none yields a key, initialization fails with this message naming the variable that was finally checked.","triggerScenarios":"Constructing with neither GOOGLE_API_KEY nor GEMINI_API_KEY exported and no api_key argument; passing api_key_env_var='MY_KEY' when MY_KEY is unset while GOOGLE_API_KEY is also absent; env present in the login shell but missing in the actual process (docker exec, cron, systemd, notebook kernel started earlier).","commonSituations":"Local-vs-deployed env drift; secrets not mounted into containers; .env not loaded via python-dotenv; accidentally unsetting GOOGLE_API_KEY that a shared module relied on.","solutions":["Export one of the recognized variables: export GEMINI_API_KEY=... (or GOOGLE_API_KEY, which takes precedence)","Pass api_key_env_var pointing at a variable your platform actually injects","For quick scripts only: pass api_key='...' (deprecated - not persisted in config)","Migrate to GoogleGeminiEmbeddingFunction, the supported class"],"exampleFix":"# before\nfrom chromadb.utils.embedding_functions import GoogleGenerativeAiEmbeddingFunction\nef = GoogleGenerativeAiEmbeddingFunction()  # ValueError: The GEMINI_API_KEY environment variable is not set.\n\n# after\nimport os\nfrom dotenv import load_dotenv\nload_dotenv()  # .env has GEMINI_API_KEY=...\nef = GoogleGenerativeAiEmbeddingFunction()","handlingStrategy":"validation","validationCode":"import os\nfrom dotenv import load_dotenv\n\nload_dotenv()\napi_key_env = \"GOOGLE_API_KEY\" if os.getenv(\"GOOGLE_API_KEY\") else \"GEMINI_API_KEY\"\nassert os.getenv(api_key_env), f\"Set {api_key_env} before starting\"\n\nfrom chromadb.utils.embedding_functions import GoogleGenerativeAiEmbeddingFunction\nef = GoogleGenerativeAiEmbeddingFunction(api_key_env_var=api_key_env)","typeGuard":null,"tryCatchPattern":"try:\n    ef = GoogleGenerativeAiEmbeddingFunction()\nexcept ValueError as e:\n    if \"environment variable is not set\" in str(e):\n        raise SystemExit(f\"Embedding auth missing: {e}\") from e\n    raise","preventionTips":["Set GEMINI_API_KEY (or GOOGLE_API_KEY, which takes precedence) via your secret manager for every environment","Load .env at process entry, before any embedding function is constructed","Remember the precedence: explicit api_key arg > GOOGLE_API_KEY > api_key_env_var"],"tags":["google-generativeai","api-key","environment-variable","chroma"],"backgroundTag":"missing-api-key-env-var","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}