Mintplex-Labs/anything-llm · error
Could not find an API Keys.
Error message
Could not find an API Keys.
What it means
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.
Source
Thrown at server/endpoints/admin.js:511
console.error(e);
response.sendStatus(500).end();
}
}
);
app.get(
"/admin/api-keys",
[validatedRequest, strictMultiUserRoleValid([ROLES.admin])],
async (_request, response) => {
try {
const apiKeys = await ApiKey.whereWithUser({});
return response.status(200).json({
apiKeys,
error: null,
});
} catch (error) {
console.error(error);
response.status(500).json({
apiKey: null,
error: "Could not find an API Keys.",
});
}
}
);
app.post(
"/admin/generate-api-key",
[validatedRequest, strictMultiUserRoleValid([ROLES.admin])],
async (request, response) => {
try {
const user = await userFromSession(request, response);
const { name = null } = reqBody(request);
const { apiKey, error } = await ApiKey.create(user.id, name);
await EventLogs.logEvent(
"api_key_created",
{ createdBy: user?.username, name: apiKey?.name },View on GitHub (pinned to 3aec848f28)
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
Example fix
// before (admin.js) — misleading generic message hides the cause
response.status(500).json({ apiKey: null, error: 'Could not find an API Keys.' });
// after — surface the real failure class to the admin UI
response.status(500).json({
apiKey: null,
error: 'Failed to list API keys',
detail: error.message, // e.g. 'SQLITE_ERROR: no such table: api_keys'
}); Defensive patterns
Strategy: try-catch
Validate before calling
// Operator-side: verify the query target before trusting the endpoint // e.g. sqlite3 "$DATABASE_PATH" '.schema api_keys' must show the table and joined user columns
Try / catch
try {
const res = await fetch('/admin/api-keys', {credentials: 'include'});
const body = await res.json();
if (res.status === 500) {
// body.error === 'Could not find an API Keys.' is misleading:
// it means the DB query threw — check server console.error output
console.error('api-keys list failed; inspect server logs');
}
} catch (e) {
// network failure reaching the admin API
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Error generating api key.
- Failed to fetch workspaces
- Failed to fetch API keys
- Failed to create API key
- Failed to revoke API key
AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18).
Data as JSON: /api/errors/1ff26b8cd726ef5f.
Report an issue: GitHub.