{"record":{"id":"4963beeb63241ed5","repo":"chroma-core/chroma","slug":"the-self-api-key-env-var-environment-variable-is-4963be","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/cohere_embedding_function.py","lineNumber":53,"sourceCode":"        except ImportError:\n            raise ValueError(\n                \"The PIL python package is not installed. Please install it with `pip install pillow`\"\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(\"COHERE_API_KEY\") is not None:\n            self.api_key_env_var = \"COHERE_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\n        self.client = cohere.Client(self.api_key)\n\n    def __call__(self, input: Embeddable) -> Embeddings:\n        \"\"\"\n        Generate embeddings for the given documents.\n\n        Args:\n            input: Documents or images to generate embeddings for.\n\n        Returns:\n            Embeddings for the documents.\n        \"\"\"\n","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/chromadb/utils/embedding_functions/cohere_embedding_function.py#L35-L71","documentation":"The constructor resolves its key as api_key or os.getenv(api_key_env_var), where api_key_env_var becomes COHERE_API_KEY automatically if that variable is set, otherwise the value you passed (default CHROMA_COHERE_API_KEY). With neither an explicit key nor any populated variable it raises this ValueError before creating cohere.Client. Passing api_key directly works but emits a DeprecationWarning since raw keys are not persisted.","triggerScenarios":"Constructing CohereEmbeddingFunction with no api_key= argument while neither COHERE_API_KEY nor CHROMA_COHERE_API_KEY (or your custom api_key_env_var) is set in the process environment.","commonSituations":"The key is in .env but load_dotenv() runs after the EF is created; CI/production secrets configured under a different variable name; local works (variable exported in .bashrc) but the container fails.","solutions":["export COHERE_API_KEY=<key> - it is auto-detected by the constructor.","Or export CHROMA_COHERE_API_KEY (the default api_key_env_var) or your custom variable name exactly as passed.","Call load_dotenv() before constructing the function; for throwaway tests pass api_key='...' despite the DeprecationWarning."],"exampleFix":"# before\nfrom chromadb.utils.embedding_functions import CohereEmbeddingFunction\nef = CohereEmbeddingFunction()  # ValueError: CHROMA_COHERE_API_KEY is not set\n\n# after\nfrom dotenv import load_dotenv\nload_dotenv()  # .env: COHERE_API_KEY=...\nfrom chromadb.utils.embedding_functions import CohereEmbeddingFunction\nef = CohereEmbeddingFunction()  # auto-detects COHERE_API_KEY","handlingStrategy":"validation","validationCode":"import os\nif not (os.getenv('COHERE_API_KEY') or os.getenv('CHROMA_COHERE_API_KEY')):\n    raise SystemExit('Cohere credential missing: set COHERE_API_KEY (auto-detected) or CHROMA_COHERE_API_KEY')","typeGuard":null,"tryCatchPattern":"try:\n    ef = CohereEmbeddingFunction()\nexcept ValueError as e:\n    if 'environment variable is not set' in str(e):\n        raise SystemExit(f'Missing credential: {e}') from e\n    raise","preventionTips":["Call load_dotenv() at process start, before any embedding function is constructed.","Fail fast on missing secrets in a boot check instead of deep in library code.","Use COHERE_API_KEY so Chroma auto-detects it regardless of the api_key_env_var passed."],"tags":["chroma","cohere","api-key","environment-variable","credentials"],"backgroundTag":"missing-env-var","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}