Mintplex-Labs/anything-llm · error

Internal Server Error

Error message

Internal Server Error

What it means

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.

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 526360e320)

Solutions

  1. Confirm the database is reachable and Prisma migrations are applied.
  2. Inspect the server log for the workspace query/map error.
  3. Verify the Prisma client version matches the schema (esp. for createdAt/chatProvider fields).
  4. If the workspace list is huge, consider whether a proxy timeout is masquerading as 500.
  5. Restart the server to re-establish the DB/Prisma client after a migration.
Defensive patterns

Strategy: try-catch

Validate before calling

// No request body to validate; depend on backend health.
const probe = await fetch('/v1/system/vector-count');
if (!probe.ok) throw new Error('backend unhealthy; /v1/openai/models likely to fail');

Type guard

function isModelsList(v) {
  return v != null && typeof v === 'object' && v.object === 'list' && Array.isArray(v.data) && v.data.every(m =>
    m && typeof m.id === 'string' && m.object === 'model'
  );
}

Try / catch

try {
  const r = await fetch('/v1/openai/models');
  if (r.status === 500) throw new Error('models list failed - check Prisma/DB and workspace schema');
  const json = await r.json();
  if (!isModelsList(json)) throw new Error('unexpected models payload');
} catch (e) { throw e; }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13). Data as JSON: /api/errors/b6368d21a082879f. Report an issue: GitHub.