Mintplex-Labs/anything-llm · error
Internal Server Error
Error message
Internal Server Error
What it means
AnythingLLM's OpenAI-compatible GET /v1/openai/models handler returns this 500 from its catch-all after `response.sendStatus(500)` when building the model list from `Workspace.where()` (a Prisma query over the workspaces table) throws. The handler maps each workspace row to `{id: workspace.slug, created: Math.floor(Number(new Date(workspace.createdAt))/1000), owned_by}`, so any database read failure or an unexpected row shape aborts the whole list. The real exception is printed server-side by `console.error(e.message, e)` — the HTTP body carries no detail.
Solutions
- Check the server console — the actual exception is logged right before the 500 is sent; identify whether it is a Prisma connection error, a lock, or a schema error
- Probe database health with GET /v1/system (system/index.js:70): if that also returns 500, the fault is the database, not this endpoint
- Verify STORAGE_DIR exists, is writable, and persists across container restarts so the SQLite DB is not recreated mid-request
- If schema drift is indicated, re-run the server so boot-time migrations apply, or restore the DB from a backup taken on the same AnythingLLM version
Example fix
// before
const res = await fetch('https://host/api/v1/openai/models', {headers:{Authorization:'Bearer key'}});
const models = await res.json(); // throws on 500 'Internal Server Error' body
// after
const res = await fetch('https://host/api/v1/openai/models', {headers:{Authorization:'Bearer key'}});
if (res.status === 500) throw new Error('models list failed - check AnythingLLM server logs (DB likely unreachable)');
if (!res.ok) throw new Error(`models list failed: HTTP ${res.status}`);
const models = await res.json(); Defensive patterns
Strategy: try-catch
Validate before calling
const health = await fetch(`${base}/api/v1/system`, opts);
if (health.status !== 200) throw new Error('AnythingLLM DB layer unhealthy - /v1/openai/models will 500'); Type guard
null
Try / catch
try { const r = await fetch(modelsUrl, opts); if (r.status===500) throw new Error('DB read failed server-side'); return await r.json(); } catch (e) { logger.error('list models failed', e.message); return []; } Prevention
- Wrap every developer-API call in a status-checking helper that surfaces 500 separately from 401/403
- Monitor the AnythingLLM server log; the true exception is only printed there
- Keep the database on a persistent, writable volume so Workspace.where() never fails
When it happens
Trigger: Calling GET /v1/openai/models with a valid API key while the database is unreachable, locked, or schema-drifted (e.g. SQLite file on a stale volume, Postgres container down). Also triggered by a workspace row with a null slug/createdAt if mapping code path throws during serialization.
Common situations: STORAGE_DIR on a read-only or full Docker volume; container killed mid-write corrupting anythingllm.db; upgrading/downgrading AnythingLLM without running Prisma migrations so the workspaces table no longer matches the entity model.
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
- Failed to fetch workspaces
- Internal Server Error
- Internal Server Error
- Internal Server Error
- Could not find a document by id
AI-assisted analysis of Mintplex-Labs/anything-llm@f92433b4ea (2026-08-18).
Data as JSON: /api/errors/b6368d21a082879f.
Report an issue: GitHub.
Appendix: source
Thrown at server/endpoints/api/openai/index.js:72
*/
try {
const data = [];
const workspaces = await Workspace.where();
for (const workspace of workspaces) {
data.push({
id: workspace.slug,
object: "model",
created: Math.floor(Number(new Date(workspace.createdAt)) / 1000),
owned_by: workspace?.chatProvider || process.env.LLM_PROVIDER,
});
}
return response.status(200).json({
object: "list",
data,
});
} catch (e) {
console.error(e.message, e);
response.sendStatus(500).end();
}
});
app.post(
"/v1/openai/chat/completions",
[validApiKey],
async (request, response) => {
/*
#swagger.tags = ['OpenAI Compatible Endpoints']
#swagger.description = 'Execute a chat with a workspace with OpenAI compatibility. Supports streaming as well. Model must be a workspace slug from /models.'
#swagger.requestBody = {
description: 'Send a prompt to the workspace with full use of documents as if sending a chat in AnythingLLM. Only supports some values of OpenAI API. See example below.',
required: true,
content: {
"application/json": {
example: {
messages: [
{"role":"system", content: "You are a helpful assistant"},View on GitHub (pinned to f92433b4ea)