Mintplex-Labs/anything-llm · error
Internal Server Error
Error message
Internal Server Error
What it means
GET /v1/users first gates on multi-user mode (401 otherwise), then runs `User.where()` and maps rows to `{id, username, role}`. The 500 from the catch is therefore a database-layer failure reading the users table — the mapping itself cannot throw for well-formed rows. The actual Prisma error is logged server-side. Note this endpoint requires multi-user mode to be enabled on the instance.
Solutions
- Check server logs for the exact Prisma error (connection vs P2021 table-missing)
- Verify multi-user mode is enabled and the instance was restarted after enabling it, so migrations ran
- Confirm the database/storage volume belongs to the same AnythingLLM version as the running server
- Restore or re-migrate storage; on healthy instances this call is trivial and 200s immediately
Example fix
// before
const {users} = await fetch(`${base}/api/v1/users`, opts).then(r=>r.json());
// after
const res = await fetch(`${base}/api/v1/users`, opts);
if (res.status === 401) throw new Error('instance not in multi-user mode');
if (res.status === 500) throw new Error('users read failed - check DB migration state');
const {users} = await res.json(); Defensive patterns
Strategy: try-catch
Validate before calling
const probe = await fetch(`${base}/api/v1/users`, opts);
if (probe.status === 401) throw new Error('enable multi-user mode first'); Type guard
const isUserList = (d) => d && Array.isArray(d.users) && d.users.every(u => typeof u.id === 'number' && typeof u.username === 'string');
Try / catch
try { const {users} = await fetch(usersUrl, opts).then(r=>r.json()); return users; } catch { return []; } // user list is non-critical metadata Prevention
- Only call user-management APIs on multi-user instances
- Confirm SIMPLE_SSO/multi-user env before building SSO automation
- Cache the user list; it changes rarely
When it happens
Trigger: Calling GET /v1/users with a valid API key on a single-user instance that was later converted to multi-user with a broken/partial migration; users table missing after storage reset; DB unreachable at call time.
Common situations: Enabling multi-user mode on an old storage volume whose schema predates the users table; database container restarting mid-request; Prisma migration skipped because the server booted against a foreign database.
Understand the failure class
Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.
- HTTP status errors: handling 4xx and 5xx responses — how to handle 4xx and 5xx responses properly.
Related errors
AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18).
Data as JSON: /api/errors/01a2049e7c7e381b.
Report an issue: GitHub.
Appendix: source
Thrown at server/endpoints/api/userManagement/index.js:63
description: "Instance is not in Multi-User mode. Permission denied.",
}
*/
try {
if (!multiUserMode(response))
return response
.status(401)
.send("Instance is not in Multi-User mode. Permission denied.");
const users = await User.where();
const filteredUsers = users.map((user) => ({
id: user.id,
username: user.username,
role: user.role,
}));
response.status(200).json({ users: filteredUsers });
} catch (e) {
console.error(e.message, e);
response.sendStatus(500).end();
}
});
app.get(
"/v1/users/:id/issue-auth-token",
[validApiKey, simpleSSOEnabled],
async (request, response) => {
/*
#swagger.tags = ['User Management']
#swagger.description = 'Issue a temporary auth token for a user'
#swagger.parameters['id'] = {
in: 'path',
description: 'The ID of the user to issue a temporary auth token for',
required: true,
type: 'string'
}
#swagger.responses[200] = {
content: {View on GitHub (pinned to 3aec848f28)