{"record":{"id":"9f84bd2b12d5174b","repo":"mem0ai/mem0","slug":"zero-entropy-api-key-is-required-set-zero-entropy-9f84bd","errorCode":null,"errorMessage":"Zero Entropy API key is required. Set ZERO_ENTROPY_API_KEY environment variable or pass api_key in config.","messagePattern":"Zero Entropy API key is required\\. Set ZERO_ENTROPY_API_KEY environment variable or pass api_key in config\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mem0/reranker/zero_entropy_reranker.py","lineNumber":32,"sourceCode":"\n\nclass ZeroEntropyReranker(BaseReranker):\n    \"\"\"Zero Entropy-based reranker implementation.\"\"\"\n    \n    def __init__(self, config):\n        \"\"\"\n        Initialize Zero Entropy reranker.\n        \n        Args:\n            config: ZeroEntropyRerankerConfig object with configuration parameters\n        \"\"\"\n        if not ZERO_ENTROPY_AVAILABLE:\n            raise ImportError(\"zeroentropy package is required for ZeroEntropyReranker. Install with: pip install zeroentropy\")\n        \n        self.config = config\n        self.api_key = config.api_key or os.getenv(\"ZERO_ENTROPY_API_KEY\")\n        if not self.api_key:\n            raise ValueError(\"Zero Entropy API key is required. Set ZERO_ENTROPY_API_KEY environment variable or pass api_key in config.\")\n            \n        self.model = config.model or \"zerank-1\"\n        \n        # Initialize Zero Entropy client\n        if self.api_key:\n            self.client = ZeroEntropy(api_key=self.api_key)\n        else:\n            self.client = ZeroEntropy()  # Will use ZERO_ENTROPY_API_KEY from environment\n        \n    def rerank(self, query: str, documents: List[Dict[str, Any]], top_k: int = None) -> List[Dict[str, Any]]:\n        \"\"\"\n        Rerank documents using Zero Entropy's rerank API.\n        \n        Args:\n            query: The search query\n            documents: List of documents to rerank\n            top_k: Number of top documents to return\n            ","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0/reranker/zero_entropy_reranker.py#L14-L50","documentation":"ZeroEntropyReranker requires an API key via config.api_key or the ZERO_ENTROPY_API_KEY environment variable; if both are empty it raises ValueError at construction. (Note the dead else-branch in the source: by that point the key is guaranteed non-None, so the key always flows into ZeroEntropy(api_key=...).) The failure is immediate and local — no API call is attempted.","triggerScenarios":"Configuring the zeroentropy reranker with no api_key and no ZERO_ENTROPY_API_KEY in the process environment; the env var set in a local .env but not loaded in Docker/systemd; api_key passed as empty string while the env var is also absent.","commonSituations":"Deploying with secret managers where the env var name changed; local-to-prod config drift; CI lacking secrets for optional integrations.","solutions":["Set ZERO_ENTROPY_API_KEY in the runtime environment or pass api_key in the reranker config","Verify inside the process: assert os.getenv('ZERO_ENTROPY_API_KEY') before constructing Memory","Store the key in a secret manager and inject at deploy; never hardcode it"],"exampleFix":"# before\nconfig = {\"reranker\": {\"provider\": \"zeroentropy\", \"config\": {\"model\": \"zerank-1\"}}}\n# ValueError: key required\n\n# after\nimport os\nkey = os.environ[\"ZERO_ENTROPY_API_KEY\"]\nconfig = {\"reranker\": {\"provider\": \"zeroentropy\", \"config\": {\"model\": \"zerank-1\", \"api_key\": key}}}","handlingStrategy":"validation","validationCode":"import os\nkey = os.getenv(\"ZERO_ENTROPY_API_KEY\")\nif not key:\n    raise RuntimeError(\"ZERO_ENTROPY_API_KEY not set; refusing to build zeroentropy reranker\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate all provider keys at startup with a single secrets check","Use consistent env var names between local .env and deploy manifests","Rotate keys via the secret manager, not by editing config files"],"tags":["reranker","zeroentropy","api-key","configuration","environment"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}