{"record":{"id":"889b643fca1ca096","repo":"thedotmack/claude-mem","slug":"missing-api-key-889b64","errorCode":"missing_api_key","errorMessage":"Server API key is not configured (CLAUDE_MEM_SERVER_API_KEY).","messagePattern":"Server API key is not configured \\(CLAUDE_MEM_SERVER_API_KEY\\)\\.","errorType":"exception","errorClass":"ServerClientError","httpStatus":null,"severity":"critical","filePath":"src/services/hooks/server-client.ts","lineNumber":357,"sourceCode":"      projectId: input.projectId,\n      sourceType: input.sourceType,\n      eventType: input.eventType,\n      occurredAtEpoch: input.occurredAtEpoch,\n      ...(input.serverSessionId !== undefined ? { serverSessionId: input.serverSessionId } : {}),\n      ...(input.contentSessionId !== undefined ? { contentSessionId: input.contentSessionId } : {}),\n      ...(input.memorySessionId !== undefined ? { memorySessionId: input.memorySessionId } : {}),\n      ...(input.platformSource !== undefined ? { platformSource: normalizePlatformSourceField(input.platformSource) } : {}),\n      ...(input.payload !== undefined ? { payload: input.payload } : {}),\n    };\n  }\n\n  private async request<T>(\n    method: 'GET' | 'POST',\n    path: string,\n    body?: unknown,\n  ): Promise<T> {\n    if (!this.apiKey || !this.apiKey.trim()) {\n      throw new ServerClientError(\n        'missing_api_key',\n        'Server API key is not configured (CLAUDE_MEM_SERVER_API_KEY).',\n      );\n    }\n\n    const url = `${this.baseUrl}${path}`;\n    const init: RequestInit = {\n      method,\n      headers: {\n        'Content-Type': 'application/json',\n        Authorization: `Bearer ${this.apiKey}`,\n      },\n    };\n    if (body !== undefined) {\n      init.body = JSON.stringify(body);\n    }\n\n    let response: Response;","sourceCodeStart":339,"sourceCodeEnd":375,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/d8bc9755e74915e5c3b999181e10a67c889bce2a/src/services/hooks/server-client.ts#L339-L375","documentation":"The ServerClient's request method refuses to send anything when no API key was configured (empty, whitespace-only, or unset). Every server call (startSession, recordEvent, endSession, addObservation, searchObservations, contextObservations) funnels through request, so all of them fail with code 'missing_api_key'.","triggerScenarios":"Constructing ServerClient without an apiKey (or with '' / whitespace) and then invoking any of its public methods, typically because CLAUDE_MEM_SERVER_API_KEY was not set in the environment when the client was created.","commonSituations":"Running hooks/server mode locally without the API key exported, .env not loaded at client-construction time, or pointing a client at a server deployment that requires keys while configuring none.","solutions":["Export CLAUDE_MEM_SERVER_API_KEY with a valid server API key before starting the process.","If using bootstrap, run the server-key bootstrap flow (requires CLAUDE_MEM_SERVER_DATABASE_URL) to generate and store a key.","Confirm the .env file is loaded before ServerClient is constructed, not after.","Check the value with trim(): a whitespace-only key is treated as missing."],"exampleFix":"// before\nconst client = new ServerClient({ baseUrl, apiKey: process.env.CLAUDE_MEM_SERVER_API_KEY }); // undefined\n\n// after\nconst apiKey = process.env.CLAUDE_MEM_SERVER_API_KEY;\nif (!apiKey?.trim()) throw new Error('Set CLAUDE_MEM_SERVER_API_KEY before using ServerClient');\nconst client = new ServerClient({ baseUrl, apiKey });","handlingStrategy":"validation","validationCode":"const apiKey = process.env.CLAUDE_MEM_SERVER_API_KEY;\nif (!apiKey || !apiKey.trim()) throw new Error('CLAUDE_MEM_SERVER_API_KEY is not set');","typeGuard":null,"tryCatchPattern":"try {\n  await client.startSession(input);\n} catch (e) {\n  if (e instanceof ServerClientError && e.code === 'missing_api_key') {\n    logger.warn('Server mode disabled: no API key configured');\n    return null;\n  } throw e;\n}","preventionTips":["Bootstrap/generate an API key once and store it in the environment.","Check key presence at client construction time, not at first request.","Treat whitespace-only keys as missing (trim before checking)."],"tags":["authentication","configuration","api-key","env-var"],"backgroundTag":"missing-api-key","analyzedSha":"d8bc9755e74915e5c3b999181e10a67c889bce2a","analyzedAt":"2026-09-17T16:40:26.182Z","contentChangedAt":"2026-09-17T16:40:26.182Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}