{"record":{"id":"772e16dcbd50852b","repo":"chroma-core/chroma","slug":"the-self-api-key-env-var-environment-variable-is-772e16","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/perplexity_embedding_function.py","lineNumber":59,"sourceCode":"            raise ValueError(\n                \"The perplexityai python package is not installed. Please install it with `pip install perplexityai`\"\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\n        if os.getenv(\"PERPLEXITY_API_KEY\") is not None:\n            self.api_key_env_var = \"PERPLEXITY_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        self.dimensions = dimensions\n        self._client = perplexity.Perplexity(api_key=self.api_key)\n\n    def __call__(self, input: Documents) -> Embeddings:\n        \"\"\"\n        Generate embeddings for the given documents.\n\n        Args:\n            input: Documents to generate embeddings for.\n\n        Returns:\n            Embeddings for the documents.\n        \"\"\"\n        response = self._client.embeddings.create(","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/chromadb/utils/embedding_functions/perplexity_embedding_function.py#L41-L77","documentation":"PerplexityEmbeddingFunction.__init__ resolves its API key as api_key or os.getenv(api_key_env_var) and raises this ValueError when the result is empty. The env var name defaults to PERPLEXITY_API_KEY, and the constructor hard-preferences PERPLEXITY_API_KEY when it is set (otherwise it uses the api_key_env_var parameter). Passing api_key directly works but now triggers a DeprecationWarning because raw keys are not persisted in collection config.","triggerScenarios":"Constructing PerplexityEmbeddingFunction() with no api_key argument in a shell/container where PERPLEXITY_API_KEY is not exported; or passing api_key_env_var=\"MY_PPLX_KEY\" when that custom variable is unset. Because __init__ also builds perplexity.Perplexity(api_key=...) right after, failure is immediate.","commonSituations":"Key stored in .env but load_dotenv() called after construction; key present in the IDE terminal but not in the Docker/Kubernetes/CI environment; variable name typo (PERPLEXITY_KEY, PPLX_API_KEY) not matching the default; free-tier users who never created an API key in the Perplexity console.","solutions":["export PERPLEXITY_API_KEY=pplx-... in the environment that runs the process (docker-compose environment:, Kubernetes Secret -> env, CI secret variable), then restart.","Or point at a differently-named existing variable: PerplexityEmbeddingFunction(api_key_env_var=\"MY_PPLX_KEY\").","Or pass the key directly for quick tests: PerplexityEmbeddingFunction(api_key=\"pplx-...\") — expect a DeprecationWarning and avoid committing it.","If using .env, call load_dotenv() before creating the embedding function and confirm with a quick assert os.getenv(\"PERPLEXITY_API_KEY\")."],"exampleFix":"// before\nef = PerplexityEmbeddingFunction()  # ValueError: The PERPLEXITY_API_KEY environment variable is not set.\n\n# after\nimport os\nfrom dotenv import load_dotenv\nload_dotenv()\nef = PerplexityEmbeddingFunction(\n    api_key_env_var=\"PERPLEXITY_API_KEY\"  # resolves from env\n) if os.getenv(\"PERPLEXITY_API_KEY\") else PerplexityEmbeddingFunction(api_key=os.environ[\"PPLX_TOKEN\"])","handlingStrategy":"validation","validationCode":"import os\n\nPPLX_VAR = \"PERPLEXITY_API_KEY\" if os.getenv(\"PERPLEXITY_API_KEY\") else \"MY_PPLX_KEY\"\nif not os.getenv(PPLX_VAR):\n    raise RuntimeError(f\"{PPLX_VAR} is not set — export it before constructing PerplexityEmbeddingFunction\")","typeGuard":"def has_perplexity_key() -> bool:\n    return bool(os.getenv(\"PERPLEXITY_API_KEY\") or os.getenv(\"PPLX_API_KEY\"))","tryCatchPattern":"try:\n    ef = PerplexityEmbeddingFunction()\nexcept ValueError as e:\n    if \"environment variable is not set\" in str(e):\n        raise RuntimeError(\"Missing Perplexity credentials — set PERPLEXITY_API_KEY\") from e\n    raise","preventionTips":["Create the API key in the Perplexity console early and store it in your secrets manager.","Load .env files at startup, before embedding functions are built.","Standardize on one env var name across services (PERPLEXITY_API_KEY) to avoid custom-name mismatches."],"tags":["perplexity","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"}