Mintplex-Labs/anything-llm · error

e.message

Error message

e.message

What it means

Catch-all handler for POST /api/v1/workspace/:slug/thread/:threadSlug/chat. Any unhandled exception in the thread chat pipeline (thread history hydration, LLM/embedder call, attachment processing, user resolution for userId, telemetry) is returned as HTTP 500 with the raw exception message inside the abort-shaped body. userId in the body, when present, is resolved to a User row before chatting so an invalid userId can also land here.

Source

Thrown at server/endpoints/api/workspaceThread/index.js:474

          reset,
        });
        await Telemetry.sendTelemetry("sent_chat", {
          LLMSelection: process.env.LLM_PROVIDER || "openai",
          Embedder: process.env.EMBEDDING_ENGINE || "inherit",
          VectorDbSelection: process.env.VECTOR_DB || "lancedb",
          TTSSelection: process.env.TTS_PROVIDER || "native",
          LLMModel: getModelTag(),
        });
        await EventLogs.logEvent("api_sent_chat", {
          workspaceName: workspace?.name,
          chatModel: workspace?.chatModel || "System Default",
          threadName: thread?.name,
          userId: user?.id,
        });
        response.status(200).json({ ...result });
      } catch (e) {
        console.error(e.message, e);
        response.status(500).json({
          id: uuidv4(),
          type: "abort",
          textResponse: null,
          sources: [],
          close: true,
          error: e.message,
        });
      }
    }
  );

  app.post(
    "/v1/workspace/:slug/thread/:threadSlug/stream-chat",
    [validApiKey],
    async (request, response) => {
      /*
      #swagger.tags = ['Workspace Threads']
      #swagger.description = 'Stream chat with a workspace thread'

View on GitHub (pinned to 3aec848f28)

Solutions

  1. Inspect error in the 500 body plus the console.error(e.message, e) server log for the root cause
  2. Validate any userId sent in the body actually exists (or omit it)
  3. Verify provider settings the same way as for /v1/workspace/:slug/chat failures
  4. Re-send the request once to rule out transient provider/DB blips, then fix config if it repeats

Example fix

// before
body: JSON.stringify({ message, userId: 999999 }) // nonexistent user
// after
body: JSON.stringify({ message }) // omit userId unless you verified it exists
Defensive patterns

Strategy: try-catch

Validate before calling

if (userId != null && !(await userExists(userId))) throw new Error('userId invalid - omit it or send a real user id');

Type guard

function isAbortPayload(d) { return d?.type === 'abort' && typeof d.error === 'string'; }

Try / catch

try {
  const d = await threadChat(slug, threadSlug, body);
  if (isAbortPayload(d)) throw new Error(d.error);
} catch (e) {
  if (/api key|model|provider/i.test(e.message)) fixProviderConfig(); else throw e;
}

Prevention

When it happens

Trigger: LLM provider credentials invalid or model unavailable; sending userId that does not match a user row; attachments with wrong mime handling; embedder/vector DB failure when querying the thread's workspace embeddings; DB errors reading WorkspaceChats history.

Common situations: Same provider misconfiguration class as the workspace chat 500, plus passing a stale userId copied from another instance; concurrent schema changes; embedding engine swapped without re-embedding.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18). Data as JSON: /api/errors/3baba16f67e159b1. Report an issue: GitHub.