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
RoboflowEmbeddingFunction.__init__ resolves its API key as api_key or os.getenv(api_key_env_var) and raises this ValueError when neither yields a value. The default variable is ROBOFLOW_API_KEY, and if ROBOFLOW_API_KEY is set it always wins as the chosen env var name; otherwise the api_key_env_var parameter applies. The check runs before the Pillow/httpx imports, so it is the first failure you see when the key is missing.
Source
Thrown at chromadb/utils/embedding_functions/roboflow_embedding_function.py:55
Defaults to "CHROMA_ROBOFLOW_API_KEY".
api_url (str, optional): The URL of the Roboflow API.
Defaults to "https://infer.roboflow.com".
"""
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("ROBOFLOW_API_KEY") is not None:
self.api_key_env_var = "ROBOFLOW_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.api_url = api_url
try:
self._PILImage = importlib.import_module("PIL.Image")
except ImportError:
raise ValueError(
"The PIL python package is not installed. Please install it with `pip install pillow`"
)
self._httpx = importlib.import_module("httpx")
def __call__(self, input: Embeddable) -> Embeddings:
"""
Generate embeddings for the given documents or images.
View on GitHub (pinned to aecdd12c8a)
Solutions
- Create an API key in Roboflow (Settings -> API Key) and export ROBOFLOW_API_KEY=... in the runtime environment, then restart the process.
- Use a custom name if your platform already standardizes one: RoboflowEmbeddingFunction(api_key_env_var="ROBOFLOW_KEY").
- Pass api_key directly for local experiments (note the DeprecationWarning; prefer env vars for anything persisted).
- In Docker/K8s/CI, inject the variable via secrets (environment: in compose, Secret/env in K8s, masked variable in CI).
Example fix
// before
ref = RoboflowEmbeddingFunction() # ValueError: The ROBOFLOW_API_KEY environment variable is not set.
# after
import os
assert os.getenv("ROBOFLOW_API_KEY"), "Set ROBOFLOW_API_KEY from Roboflow Settings -> API Key"
ref = RoboflowEmbeddingFunction(api_key_env_var="ROBOFLOW_API_KEY") Defensive patterns
Strategy: validation
Validate before calling
import os
if not os.getenv("ROBOFLOW_API_KEY"):
raise RuntimeError(
"ROBOFLOW_API_KEY is not set — create one at Roboflow Settings -> API Key and export it"
)
ref = RoboflowEmbeddingFunction() Type guard
def has_roboflow_key() -> bool:
return bool(os.getenv("ROBOFLOW_API_KEY")) Try / catch
try:
ref = RoboflowEmbeddingFunction()
except ValueError as e:
if "environment variable is not set" in str(e):
raise RuntimeError("Missing Roboflow credentials — set ROBOFLOW_API_KEY") from e
raise Prevention
- Provision the Roboflow API key when the project starts, not when first embedding fails.
- Inject it via Docker/K8s/CI secrets so every runtime (local, container, CI) has it.
- Distinguish the personal API key from per-workflow keys — only the account API key works here.
When it happens
Trigger: Constructing RoboflowEmbeddingFunction() without api_key in an environment where ROBOFLOW_API_KEY is unset; or api_key_env_var="ROBOFLOW_KEY" with that custom variable not exported. Common when embedding images right after `pip install chromadb` without any Roboflow setup.
Common situations: The key exists in the Roboflow web UI but was never exported to the shell/container; a private Roboflow workflow key is confused with the personal API key; multi-service deployments where the inference service has the key but the indexing worker does not; CI secrets not wired to the job.
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 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
AI-assisted analysis of chroma-core/chroma@aecdd12c8a (2026-08-16).
Data as JSON: /api/errors/790591c3e7da27a2.
Report an issue: GitHub.