mem0ai/mem0 · error · ValueError
Zero Entropy API key is required. Set ZERO_ENTROPY_API_KEY e
Error message
Zero Entropy API key is required. Set ZERO_ENTROPY_API_KEY environment variable or pass api_key in config.
What it means
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.
Source
Thrown at mem0/reranker/zero_entropy_reranker.py:32
class ZeroEntropyReranker(BaseReranker):
"""Zero Entropy-based reranker implementation."""
def __init__(self, config):
"""
Initialize Zero Entropy reranker.
Args:
config: ZeroEntropyRerankerConfig object with configuration parameters
"""
if not ZERO_ENTROPY_AVAILABLE:
raise ImportError("zeroentropy package is required for ZeroEntropyReranker. Install with: pip install zeroentropy")
self.config = config
self.api_key = config.api_key or os.getenv("ZERO_ENTROPY_API_KEY")
if not self.api_key:
raise ValueError("Zero Entropy API key is required. Set ZERO_ENTROPY_API_KEY environment variable or pass api_key in config.")
self.model = config.model or "zerank-1"
# Initialize Zero Entropy client
if self.api_key:
self.client = ZeroEntropy(api_key=self.api_key)
else:
self.client = ZeroEntropy() # Will use ZERO_ENTROPY_API_KEY from environment
def rerank(self, query: str, documents: List[Dict[str, Any]], top_k: int = None) -> List[Dict[str, Any]]:
"""
Rerank documents using Zero Entropy's rerank API.
Args:
query: The search query
documents: List of documents to rerank
top_k: Number of top documents to return
View on GitHub (pinned to 001c235229)
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
Example fix
# before
config = {"reranker": {"provider": "zeroentropy", "config": {"model": "zerank-1"}}}
# ValueError: key required
# after
import os
key = os.environ["ZERO_ENTROPY_API_KEY"]
config = {"reranker": {"provider": "zeroentropy", "config": {"model": "zerank-1", "api_key": key}}} Defensive patterns
Strategy: validation
Validate before calling
import os
key = os.getenv("ZERO_ENTROPY_API_KEY")
if not key:
raise RuntimeError("ZERO_ENTROPY_API_KEY not set; refusing to build zeroentropy reranker") Prevention
- 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
When it happens
Trigger: 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.
Common situations: Deploying with secret managers where the env var name changed; local-to-prod config drift; CI lacking secrets for optional integrations.
Related errors
- Zero Entropy API key is required. Set ZERO_ENTROPY_API_KEY e
- Cohere API key is required. Set COHERE_API_KEY environment v
- Cohere API key is required. Set COHERE_API_KEY environment v
- Pinecone API key required: pass apiKey or set PINECONE_API_K
- Mem0 API key is required
AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15).
Data as JSON: /api/errors/9f84bd2b12d5174b.
Report an issue: GitHub.