chroma-core/chroma · error · ValueError
The {self.api_key_env_var} environment variable is not set.
Error message
The {self.api_key_env_var} environment variable is not set. What it means
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.
Source
Thrown at chromadb/utils/embedding_functions/google_embedding_function.py:258
except ImportError:
raise ValueError(
"The Google Generative AI python package is not installed. Please install it with `pip install google-generativeai`"
)
if api_key is not None:
warnings.warn(
"Direct api_key configuration will not be persisted. "
"Please use environment variables via api_key_env_var for persistent storage.",
DeprecationWarning,
)
if os.getenv("GOOGLE_API_KEY") is not None:
self.api_key_env_var = "GOOGLE_API_KEY"
else:
self.api_key_env_var = api_key_env_var
self.api_key = api_key or os.getenv(self.api_key_env_var)
if not self.api_key:
raise ValueError(
f"The {self.api_key_env_var} environment variable is not set."
)
self.model_name = model_name
self.task_type = task_type
self.dimension = dimension
genai.configure(
api_key=self.api_key,
client_options={"headers": {"x-goog-api-client": f"chroma/{__version__}"}},
)
self._genai = genai
def __call__(self, input: Documents) -> Embeddings:
"""
Generate embeddings for the given documents.
Args:View on GitHub (pinned to aecdd12c8a)
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
Example fix
# before from chromadb.utils.embedding_functions import GoogleGenerativeAiEmbeddingFunction ef = GoogleGenerativeAiEmbeddingFunction() # ValueError: The GEMINI_API_KEY environment variable is not set. # after import os from dotenv import load_dotenv load_dotenv() # .env has GEMINI_API_KEY=... ef = GoogleGenerativeAiEmbeddingFunction()
Defensive patterns
Strategy: validation
Validate before calling
import os
from dotenv import load_dotenv
load_dotenv()
api_key_env = "GOOGLE_API_KEY" if os.getenv("GOOGLE_API_KEY") else "GEMINI_API_KEY"
assert os.getenv(api_key_env), f"Set {api_key_env} before starting"
from chromadb.utils.embedding_functions import GoogleGenerativeAiEmbeddingFunction
ef = GoogleGenerativeAiEmbeddingFunction(api_key_env_var=api_key_env) Try / catch
try:
ef = GoogleGenerativeAiEmbeddingFunction()
except ValueError as e:
if "environment variable is not set" in str(e):
raise SystemExit(f"Embedding auth missing: {e}") from e
raise Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- The {self.api_key_env_var} environment variable is not set.
- The {self.api_key_env_var} environment variable is not set.
- The {self.api_key_env_var} environment variable must be set
- The {api_key_env_var} environment variable is not set.
- The {self.api_key_env_var} environment variable is not set.
AI-assisted analysis of chroma-core/chroma@aecdd12c8a (2026-08-16).
Data as JSON: /api/errors/daa3abe66b837cf0.
Report an issue: GitHub.