{"record":{"id":"c0a2824d7a9a4ca3","repo":"mem0ai/mem0","slug":"zero-entropy-api-key-is-required-set-zero-entropy","errorCode":null,"errorMessage":"Zero Entropy API key is required. Set ZERO_ENTROPY_API_KEY environment variable or pass apiKey in config.","messagePattern":"Zero Entropy API key is required\\. Set ZERO_ENTROPY_API_KEY environment variable or pass apiKey in config\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"mem0-ts/src/oss/src/rerankers/zeroentropy.ts","lineNumber":17,"sourceCode":"import { RerankerConfig } from \"../types\";\nimport { Reranker, RerankResult } from \"./base\";\nimport { loadPeer } from \"../utils/load_peer\";\n\nconst DEFAULT_MODEL = \"zerank-1\";\n\nexport class ZeroEntropyReranker implements Reranker {\n  private clientInstance?: any;\n  private clientPromise?: Promise<any>;\n  private readonly apiKey: string;\n  private model: string;\n  private topK?: number;\n\n  constructor(config: RerankerConfig) {\n    const apiKey = config.apiKey || process.env.ZERO_ENTROPY_API_KEY;\n    if (!apiKey) {\n      throw new Error(\n        \"Zero Entropy API key is required. Set ZERO_ENTROPY_API_KEY environment variable or pass apiKey in config.\",\n      );\n    }\n    this.apiKey = apiKey;\n    this.model = config.model || DEFAULT_MODEL;\n    this.topK = config.topK;\n  }\n\n  /**\n   * Lazily construct (or reuse) the ZeroEntropy client, importing the\n   * optional `zeroentropy` peer only when the reranker is first used so\n   * consumers that never touch ZeroEntropy don't need it installed.\n   */\n  private async getClient(): Promise<any> {\n    if (this.clientInstance) return this.clientInstance;\n    if (!this.clientPromise) {\n      this.clientPromise = this.createClient();\n    }","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/rerankers/zeroentropy.ts#L1-L35","documentation":"Thrown by the ZeroEntropyReranker constructor when neither config.apiKey nor the ZERO_ENTROPY_API_KEY environment variable is set. ZeroEntropy's rerank API (default model zerank-1) requires authentication; the check happens at construction time when RerankerFactory builds the reranker from the memory config. The zeroentropy npm peer dependency is imported lazily, so the key is the only early failure.","triggerScenarios":"Configuring reranker: { provider: 'zeroentropy', config: {...} } with no apiKey while ZERO_ENTROPY_API_KEY is absent from the process environment — env var missing in the deployed container, set in a shell the process never inherited, or misnamed.","commonSituations":"Secrets defined locally but not in Docker/CI/production; .env loaded after Memory construction; key name typo (ZEROENTROPY_API_KEY); new deployment target without copied secrets.","solutions":["Set ZERO_ENTROPY_API_KEY in the runtime environment of the process","Or pass it explicitly: reranker: { provider: 'zeroentropy', config: { apiKey: process.env.ZERO_ENTROPY_API_KEY } }","Add a boot-time env assertion so misconfiguration fails at startup, not at first rerank"],"exampleFix":"// before\nconst memory = new Memory({ reranker: { provider: 'zeroentropy', config: {} } });\n\n// after\nconst memory = new Memory({\n  reranker: { provider: 'zeroentropy', config: { apiKey: process.env.ZERO_ENTROPY_API_KEY } },\n});","handlingStrategy":"validation","validationCode":"if (!process.env.ZERO_ENTROPY_API_KEY) {\n  throw new Error('ZERO_ENTROPY_API_KEY is not set — reranker unavailable');\n}","typeGuard":null,"tryCatchPattern":"try { new Memory({ ...config, reranker: { provider: 'zeroentropy', config: {} } }); } catch (e) { if (e instanceof Error && e.message.includes('ZERO_ENTROPY_API_KEY')) { /* degrade to no reranker */ } else throw e; }","preventionTips":["Fail fast on missing secrets at boot with a startup checklist","Copy the exact env var name (ZERO_ENTROPY_API_KEY with underscores) into every deployment target"],"tags":["configuration","zeroentropy","reranker","environment","secrets"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}