{"record":{"id":"1ff26b8cd726ef5f","repo":"Mintplex-Labs/anything-llm","slug":"could-not-find-an-api-keys","errorCode":null,"errorMessage":"Could not find an API Keys.","messagePattern":"Could not find an API Keys\\.","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"server/endpoints/admin.js","lineNumber":511,"sourceCode":"        console.error(e);\n        response.sendStatus(500).end();\n      }\n    }\n  );\n\n  app.get(\n    \"/admin/api-keys\",\n    [validatedRequest, strictMultiUserRoleValid([ROLES.admin])],\n    async (_request, response) => {\n      try {\n        const apiKeys = await ApiKey.whereWithUser({});\n        return response.status(200).json({\n          apiKeys,\n          error: null,\n        });\n      } catch (error) {\n        console.error(error);\n        response.status(500).json({\n          apiKey: null,\n          error: \"Could not find an API Keys.\",\n        });\n      }\n    }\n  );\n\n  app.post(\n    \"/admin/generate-api-key\",\n    [validatedRequest, strictMultiUserRoleValid([ROLES.admin])],\n    async (request, response) => {\n      try {\n        const user = await userFromSession(request, response);\n        const { name = null } = reqBody(request);\n        const { apiKey, error } = await ApiKey.create(user.id, name);\n        await EventLogs.logEvent(\n          \"api_key_created\",\n          { createdBy: user?.username, name: apiKey?.name },","sourceCodeStart":493,"sourceCodeEnd":529,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/endpoints/admin.js#L493-L529","documentation":"Returned (HTTP 500) by GET /admin/api-keys when the ApiKey.whereWithUser({}) query throws. Despite the message, an empty key list is NOT an error — it returns 200 with apiKeys: []. This 500 means the database query itself failed (connection down, api_keys table or the joined user columns missing, model/dialect mismatch). The real cause is printed by console.error on the server; the response text is generic and misleading.","triggerScenarios":"GET /admin/api-keys as an authenticated admin while the database is unreachable; the api_keys table or the user-join view does not exist because migrations never ran; an upgrade changed the ApiKey schema (new column in whereWithUser's select) without re-migrating; sqlite file path env pointing at a fresh/empty file.","commonSituations":"Fresh installs that skipped the migration step; DATABASE_PATH/env var drift between environments; DB container not up when the API started; version upgrades where whereWithUser's query references columns absent in the old schema.","solutions":["Read the server console — the console.error above the response shows the actual DB error (table missing, connection refused, no such column)","Run the project's database migrations so api_keys and the joined user columns exist","Verify DB connection settings (path/host/credentials) resolve from the API server process","Retry the endpoint only after the underlying error in the logs is resolved"],"exampleFix":"// before (admin.js) — misleading generic message hides the cause\nresponse.status(500).json({ apiKey: null, error: 'Could not find an API Keys.' });\n\n// after — surface the real failure class to the admin UI\nresponse.status(500).json({\n  apiKey: null,\n  error: 'Failed to list API keys',\n  detail: error.message, // e.g. 'SQLITE_ERROR: no such table: api_keys'\n});","handlingStrategy":"try-catch","validationCode":"// Operator-side: verify the query target before trusting the endpoint\n// e.g. sqlite3 \"$DATABASE_PATH\" '.schema api_keys' must show the table and joined user columns","typeGuard":null,"tryCatchPattern":"try {\n  const res = await fetch('/admin/api-keys', {credentials: 'include'});\n  const body = await res.json();\n  if (res.status === 500) {\n    // body.error === 'Could not find an API Keys.' is misleading:\n    // it means the DB query threw — check server console.error output\n    console.error('api-keys list failed; inspect server logs');\n  }\n} catch (e) {\n  // network failure reaching the admin API\n}","preventionTips":["Run migrations as part of every deploy so api_keys and joined columns exist","Verify DB connectivity env vars from the API process before opening admin pages","Never read this message literally — empty lists return 200; a 500 here always means check the server log"],"tags":["http-500","database","admin","api-keys","misleading-message"],"backgroundTag":"database-query-failed","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}