{"record":{"id":"b6368d21a082879f","repo":"Mintplex-Labs/anything-llm","slug":"internal-server-error-b6368d","errorCode":null,"errorMessage":"Internal Server Error","messagePattern":"Internal Server Error","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"server/endpoints/api/openai/index.js","lineNumber":72,"sourceCode":"    */\n    try {\n      const data = [];\n      const workspaces = await Workspace.where();\n      for (const workspace of workspaces) {\n        data.push({\n          id: workspace.slug,\n          object: \"model\",\n          created: Math.floor(Number(new Date(workspace.createdAt)) / 1000),\n          owned_by: workspace?.chatProvider || process.env.LLM_PROVIDER,\n        });\n      }\n      return response.status(200).json({\n        object: \"list\",\n        data,\n      });\n    } catch (e) {\n      console.error(e.message, e);\n      response.sendStatus(500).end();\n    }\n  });\n\n  app.post(\n    \"/v1/openai/chat/completions\",\n    [validApiKey],\n    async (request, response) => {\n      /*\n      #swagger.tags = ['OpenAI Compatible Endpoints']\n      #swagger.description = 'Execute a chat with a workspace with OpenAI compatibility. Supports streaming as well. Model must be a workspace slug from /models.'\n      #swagger.requestBody = {\n          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.',\n          required: true,\n          content: {\n            \"application/json\": {\n              example: {\n                messages: [\n                {\"role\":\"system\", content: \"You are a helpful assistant\"},","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/f92433b4ea0598492a1e6645ea22addbb4dd1287/server/endpoints/api/openai/index.js#L54-L90","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nconst res = await fetch('https://host/api/v1/openai/models', {headers:{Authorization:'Bearer key'}});\nconst models = await res.json(); // throws on 500 'Internal Server Error' body\n\n// after\nconst res = await fetch('https://host/api/v1/openai/models', {headers:{Authorization:'Bearer key'}});\nif (res.status === 500) throw new Error('models list failed - check AnythingLLM server logs (DB likely unreachable)');\nif (!res.ok) throw new Error(`models list failed: HTTP ${res.status}`);\nconst models = await res.json();","handlingStrategy":"try-catch","validationCode":"const health = await fetch(`${base}/api/v1/system`, opts);\nif (health.status !== 200) throw new Error('AnythingLLM DB layer unhealthy - /v1/openai/models will 500');","typeGuard":"null","tryCatchPattern":"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 []; }","preventionTips":["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"],"tags":["anythingllm","openai-compatible","prisma","database","http-500"],"backgroundTag":"database-query-failed","analyzedSha":"f92433b4ea0598492a1e6645ea22addbb4dd1287","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}