{"record":{"id":"829c56ebd3f1695b","repo":"chroma-core/chroma","slug":"the-api-key-env-var-environment-variable-is-not","errorCode":null,"errorMessage":"The {api_key_env_var} environment variable is not set.","messagePattern":"The (.+?) environment variable is not set\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"chromadb/utils/embedding_functions/mistral_embedding_function.py","lineNumber":31,"sourceCode":"    ):\n        \"\"\"\n        Initialize the MistralEmbeddingFunction.\n\n        Args:\n            model (str): The name of the model to use for text embeddings.\n            api_key_env_var (str): The environment variable name for the Mistral API key.\n        \"\"\"\n        try:\n            from mistralai import Mistral\n        except ImportError:\n            raise ValueError(\n                \"The mistralai python package is not installed. Please install it with `pip install mistralai`\"\n            )\n        self.model = model\n        self.api_key_env_var = api_key_env_var\n        self.api_key = os.getenv(api_key_env_var)\n        if not self.api_key:\n            raise ValueError(f\"The {api_key_env_var} environment variable is not set.\")\n        self.client = Mistral(api_key=self.api_key)\n\n    def __call__(self, input: Documents) -> Embeddings:\n        \"\"\"\n        Get the embeddings for a list of texts.\n\n        Args:\n            input (Documents): A list of texts to get embeddings for.\n        \"\"\"\n        if not all(isinstance(item, str) for item in input):\n            raise ValueError(\"Mistral only supports text documents, not images\")\n        output = self.client.embeddings.create(\n            model=self.model,\n            inputs=input,\n        )\n\n        # Extract embeddings from the response\n        return [np.array(data.embedding) for data in output.data]","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/chromadb/utils/embedding_functions/mistral_embedding_function.py#L13-L49","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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')\""],"exampleFix":"# before\nfrom chromadb.utils.embedding_functions import MistralEmbeddingFunction\nef = MistralEmbeddingFunction(model=\"mistral-embed\")  # ValueError: env var not set\n\n# after\nimport os\nfrom dotenv import load_dotenv\nload_dotenv()\nassert os.getenv(\"MISTRAL_API_KEY\"), \"MISTRAL_API_KEY missing\"\nef = MistralEmbeddingFunction(model=\"mistral-embed\")","handlingStrategy":"validation","validationCode":"import os\n\nif not os.getenv(\"MISTRAL_API_KEY\"):\n    raise SystemExit(\"MISTRAL_API_KEY is required for MistralEmbeddingFunction\")\n\nfrom chromadb.utils.embedding_functions import MistralEmbeddingFunction\nef = MistralEmbeddingFunction(model=\"mistral-embed\")","typeGuard":null,"tryCatchPattern":"try:\n    ef = MistralEmbeddingFunction(model=\"mistral-embed\")\nexcept ValueError as e:\n    if \"environment variable is not set\" in str(e):\n        raise RuntimeError(\"Set MISTRAL_API_KEY in the process environment\") from e\n    raise","preventionTips":["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"],"tags":["python","authentication","environment-variables","mistral","api-key"],"backgroundTag":"missing-env-var","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}