{"record":{"id":"790591c3e7da27a2","repo":"chroma-core/chroma","slug":"the-self-api-key-env-var-environment-variable-is-790591","errorCode":null,"errorMessage":"The {self.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/roboflow_embedding_function.py","lineNumber":55,"sourceCode":"                Defaults to \"CHROMA_ROBOFLOW_API_KEY\".\n            api_url (str, optional): The URL of the Roboflow API.\n                Defaults to \"https://infer.roboflow.com\".\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(\"ROBOFLOW_API_KEY\") is not None:\n            self.api_key_env_var = \"ROBOFLOW_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.api_url = api_url\n\n        try:\n            self._PILImage = importlib.import_module(\"PIL.Image\")\n        except ImportError:\n            raise ValueError(\n                \"The PIL python package is not installed. Please install it with `pip install pillow`\"\n            )\n\n        self._httpx = importlib.import_module(\"httpx\")\n\n    def __call__(self, input: Embeddable) -> Embeddings:\n        \"\"\"\n        Generate embeddings for the given documents or images.\n","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/chromadb/utils/embedding_functions/roboflow_embedding_function.py#L37-L73","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"// before\nref = RoboflowEmbeddingFunction()  # ValueError: The ROBOFLOW_API_KEY environment variable is not set.\n\n# after\nimport os\nassert os.getenv(\"ROBOFLOW_API_KEY\"), \"Set ROBOFLOW_API_KEY from Roboflow Settings -> API Key\"\nref = RoboflowEmbeddingFunction(api_key_env_var=\"ROBOFLOW_API_KEY\")","handlingStrategy":"validation","validationCode":"import os\n\nif not os.getenv(\"ROBOFLOW_API_KEY\"):\n    raise RuntimeError(\n        \"ROBOFLOW_API_KEY is not set — create one at Roboflow Settings -> API Key and export it\"\n    )\n\nref = RoboflowEmbeddingFunction()","typeGuard":"def has_roboflow_key() -> bool:\n    return bool(os.getenv(\"ROBOFLOW_API_KEY\"))","tryCatchPattern":"try:\n    ref = RoboflowEmbeddingFunction()\nexcept ValueError as e:\n    if \"environment variable is not set\" in str(e):\n        raise RuntimeError(\"Missing Roboflow credentials — set ROBOFLOW_API_KEY\") from e\n    raise","preventionTips":["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."],"tags":["roboflow","embedding","api-key","environment-variable","chroma"],"backgroundTag":"missing-api-key-env-var","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}