{"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/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/endpoints/api/openai/index.js#L54-L90","documentation":"HTTP 500 returned by GET /v1/openai/models in AnythingLLM. The handler maps workspaces into OpenAI-shaped model objects ({id: workspace.slug, object:'model', created, owned_by}) and returns {object:'list', data}. A 500 means the workspace query or the map threw - DB error, schema drift, or a property access on a null workspace.","triggerScenarios":"Database unreachable so the workspace findMany throws; workspace.createdAt or workspace.chatProvider access failing because of an unexpected null; Prisma schema/version mismatch; extremely large workspace set causing memory issues during mapping.","commonSituations":"DB outage at call time; partial migration leaving workspaces without createdAt; Prisma client out of sync with the schema; reverse proxy timeout on huge model lists.","solutions":["Confirm the database is reachable and Prisma migrations are applied.","Inspect the server log for the workspace query/map error.","Verify the Prisma client version matches the schema (esp. for createdAt/chatProvider fields).","If the workspace list is huge, consider whether a proxy timeout is masquerading as 500.","Restart the server to re-establish the DB/Prisma client after a migration."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// No request body to validate; depend on backend health.\nconst probe = await fetch('/v1/system/vector-count');\nif (!probe.ok) throw new Error('backend unhealthy; /v1/openai/models likely to fail');","typeGuard":"function isModelsList(v) {\n  return v != null && typeof v === 'object' && v.object === 'list' && Array.isArray(v.data) && v.data.every(m =>\n    m && typeof m.id === 'string' && m.object === 'model'\n  );\n}","tryCatchPattern":"try {\n  const r = await fetch('/v1/openai/models');\n  if (r.status === 500) throw new Error('models list failed - check Prisma/DB and workspace schema');\n  const json = await r.json();\n  if (!isModelsList(json)) throw new Error('unexpected models payload');\n} catch (e) { throw e; }","preventionTips":["Keep Prisma migrations applied so workspace.createdAt/chatProvider are never unexpectedly null.","Monitor DB connectivity; this endpoint breaks when the DB is down.","Keep the Prisma client version aligned with the schema.","Restart the server after a DB migration to refresh the client."],"tags":["anythingllm","openai-compatible","models","prisma","database","express","http-500"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}