{"record":{"id":"063af309bbd9b9ea","repo":"Mintplex-Labs/anything-llm","slug":"failed-to-fetch-api-keys","errorCode":null,"errorMessage":"Failed to fetch API keys","messagePattern":"Failed to fetch API keys","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"server/endpoints/browserExtension.js","lineNumber":169,"sourceCode":"    }\n  );\n\n  // Internal endpoints for managing API keys\n  app.get(\n    \"/browser-extension/api-keys\",\n    [validatedRequest, flexUserRoleValid([ROLES.admin, ROLES.manager])],\n    async (request, response) => {\n      try {\n        const user = await userFromSession(request, response);\n        const apiKeys = multiUserMode(response)\n          ? await BrowserExtensionApiKey.whereWithUser(user)\n          : await BrowserExtensionApiKey.where();\n\n        response.status(200).json({ success: true, apiKeys });\n      } catch (error) {\n        console.error(error);\n        response\n          .status(500)\n          .json({ success: false, error: \"Failed to fetch API keys\" });\n      }\n    }\n  );\n\n  app.post(\n    \"/browser-extension/api-keys/new\",\n    [validatedRequest, flexUserRoleValid([ROLES.admin, ROLES.manager])],\n    async (request, response) => {\n      try {\n        const user = await userFromSession(request, response);\n        const { apiKey, error } = await BrowserExtensionApiKey.create(\n          user?.id || null\n        );\n        if (error) throw new Error(error);\n        response.status(200).json({\n          apiKey: apiKey.key,\n        });","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/endpoints/browserExtension.js#L151-L187","documentation":"500 from GET /browser-extension/api-keys (admin/manager session required). The try block covers userFromSession and BrowserExtensionApiKey.whereWithUser/where, so a failure here is a database-level problem reading the browser_extension_api_keys table (missing table after a broken migration, locked DB file) or session resolution blowing up - never an auth problem, since auth is enforced by middleware before the handler.","triggerScenarios":"browser_extension_api_keys table absent after an interrupted upgrade/migration; SQLITE_BUSY while another writer holds the DB; corrupted session/user row making userFromSession throw.","commonSituations":"Upgrading an instance whose storage volume was partially persisted; running backups that lock the SQLite file; multi-admin sessions racing.","solutions":["Read server logs for the underlying SQLite error.","Restart the server so boot migrations re-run and recreate the table if it is missing.","Confirm the DB file is writable and not held by another process."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"await ensureAdminSession(); // validatedRequest cookie must be present and admin/manager role before the call","typeGuard":null,"tryCatchPattern":"try { const { apiKeys } = await listExtensionApiKeys(); }\ncatch (e) {\n  if (e.status === 500) throw new Error('Key listing failed at the DB layer - check server logs / migrate');\n  if (e.status === 401 || e.status === 403) throw new Error('Session lacks admin/manager role');\n  throw e;\n}","preventionTips":["Apply DB migrations after every upgrade so browser_extension_api_keys exists.","Avoid concurrent admin DB-heavy actions while listing keys."],"tags":["api-keys","browser-extension","http-500","sqlite"],"backgroundTag":"database-query-failed","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}