chroma-core/chroma · error · ValueError
The {api_key_env_var} environment variable is not set.
Error message
The {api_key_env_var} environment variable is not set. What it means
MistralEmbeddingFunction reads os.getenv(api_key_env_var) (default 'MISTRAL_API_KEY') in __init__ and raises this ValueError when the variable is empty/unset — there is no api_key constructor parameter at all, the env var is the only key-injection path. The Mistral embeddings API requires a bearer token, so the EF refuses to construct without one.
Source
Thrown at chromadb/utils/embedding_functions/mistral_embedding_function.py:31
):
"""
Initialize the MistralEmbeddingFunction.
Args:
model (str): The name of the model to use for text embeddings.
api_key_env_var (str): The environment variable name for the Mistral API key.
"""
try:
from mistralai import Mistral
except ImportError:
raise ValueError(
"The mistralai python package is not installed. Please install it with `pip install mistralai`"
)
self.model = model
self.api_key_env_var = api_key_env_var
self.api_key = os.getenv(api_key_env_var)
if not self.api_key:
raise ValueError(f"The {api_key_env_var} environment variable is not set.")
self.client = Mistral(api_key=self.api_key)
def __call__(self, input: Documents) -> Embeddings:
"""
Get the embeddings for a list of texts.
Args:
input (Documents): A list of texts to get embeddings for.
"""
if not all(isinstance(item, str) for item in input):
raise ValueError("Mistral only supports text documents, not images")
output = self.client.embeddings.create(
model=self.model,
inputs=input,
)
# Extract embeddings from the response
return [np.array(data.embedding) for data in output.data]View on GitHub (pinned to aecdd12c8a)
Solutions
- export MISTRAL_API_KEY=... in the launching environment
- For a custom var name: MistralEmbeddingFunction(model='mistral-embed', api_key_env_var='MY_MISTRAL_KEY')
- Load .env before construction: from dotenv import load_dotenv; load_dotenv()
- Preflight: python -c "import os; assert os.getenv('MISTRAL_API_KEY')"
Example fix
# before
from chromadb.utils.embedding_functions import MistralEmbeddingFunction
ef = MistralEmbeddingFunction(model="mistral-embed") # ValueError: env var not set
# after
import os
from dotenv import load_dotenv
load_dotenv()
assert os.getenv("MISTRAL_API_KEY"), "MISTRAL_API_KEY missing"
ef = MistralEmbeddingFunction(model="mistral-embed") Defensive patterns
Strategy: validation
Validate before calling
import os
if not os.getenv("MISTRAL_API_KEY"):
raise SystemExit("MISTRAL_API_KEY is required for MistralEmbeddingFunction")
from chromadb.utils.embedding_functions import MistralEmbeddingFunction
ef = MistralEmbeddingFunction(model="mistral-embed") Try / catch
try:
ef = MistralEmbeddingFunction(model="mistral-embed")
except ValueError as e:
if "environment variable is not set" in str(e):
raise RuntimeError("Set MISTRAL_API_KEY in the process environment") from e
raise Prevention
- This EF has no api_key parameter — the env var is the only path, so wire it into the deployment spec
- load_dotenv() before EF construction
- Assert the env var in a startup preflight to fail before serving traffic
When it happens
Trigger: MistralEmbeddingFunction(model='mistral-embed') with MISTRAL_API_KEY unset; running under docker/systemd/github-actions where the secret env var was not declared; setting the var with a typo (e.g. MISTRALAPI_KEY) or only in the interactive shell that did not launch the process.
Common situations: CI jobs missing the secret; containers without env passthrough; .env loaded after EF construction; keys defined per-project but the app runs in another directory.
Related errors
- The {self.api_key_env_var} environment variable is not set.
- The {api_key_env_var} environment variable is not set.
- Missing required arguments: {', '.join([arg.name for arg in
- API key not provided and {self.api_key_env_var} environment
- Mistral only supports text documents, not images
AI-assisted analysis of chroma-core/chroma@aecdd12c8a (2026-08-16).
Data as JSON: /api/errors/829c56ebd3f1695b.
Report an issue: GitHub.