Mintplex-Labs/anything-llm · error
e.message
Error message
e.message
What it means
Catch-all handler for POST /api/v1/workspace/:slug/chat in AnythingLLM's Developer API. Any exception thrown while running the chat pipeline (LLM provider call, embedding lookup, vector DB query, attachment processing, telemetry/event logging) is returned as HTTP 500 with the raw exception message in an abort-shaped body {id, type:'abort', textResponse:null, sources:[], close:true, error}. The shape intentionally mimics a streaming abort event so clients can reuse one parser for stream and non-stream endpoints.
Source
Thrown at server/endpoints/api/workspace/index.js:724
attachments,
reset,
});
await Telemetry.sendTelemetry("sent_chat", {
LLMSelection:
workspace.chatProvider ?? process.env.LLM_PROVIDER ?? "openai",
Embedder: process.env.EMBEDDING_ENGINE || "inherit",
VectorDbSelection: process.env.VECTOR_DB || "lancedb",
TTSSelection: process.env.TTS_PROVIDER || "native",
});
await EventLogs.logEvent("api_sent_chat", {
workspaceName: workspace?.name,
chatModel: workspace?.chatModel || "System Default",
});
return 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/stream-chat",
[validApiKey],
async (request, response) => {
/*
#swagger.tags = ['Workspaces']
#swagger.description = 'Execute a streamable chat with a workspace'View on GitHub (pinned to 3aec848f28)
Solutions
- Read the error field of the 500 body and the server console line (console.error(e.message, e)) - the underlying provider message names the real cause
- Verify the LLM provider credentials and model in the UI under System Preferences, or check env: LLM_PROVIDER, OPEN_AI_KEY (or the matching provider key), EMBEDDING_ENGINE
- Send the same prompt from the workspace chat UI; if the UI also fails, the problem is provider config, not the API call
- If the failure is attachment-related, send documents with Content-Type 'application/anythingllm-document' so they are parsed as text, not images
- If the embedder or vector DB was changed, re-embed the workspace documents
Example fix
// before
await fetch(`${BASE}/api/v1/workspace/${slug}/chat`, {
method: 'POST',
headers: { Authorization: `Bearer ${API_KEY}`, 'Content-Type': 'application/json' },
body: JSON.stringify({ message: 'Summarize the docs' })
});
// after - surface the server's abort payload instead of throwing a generic Error
const res = await fetch(`${BASE}/api/v1/workspace/${slug}/chat`, { /* same */ });
const data = await res.json();
if (!res.ok || data.type === 'abort')
throw new Error(`workspace chat failed: ${data.error ?? res.status}`); Defensive patterns
Strategy: try-catch
Validate before calling
const ws = await fetch(`${BASE}/api/v1/workspace/${slug}`, { headers: AUTH }).then(r => r.ok);
if (!ws) throw new Error('workspace missing or unreachable - fix before chat'); Type guard
function isAbortPayload(data) {
return typeof data === 'object' && data !== null && data.type === 'abort' && typeof data.error === 'string';
} Try / catch
try {
const res = await chat(slug, body);
const data = await res.json();
if (isAbortPayload(data)) throw new Error(data.error); // carries the provider's real message
} catch (e) {
if (/api key|unauthorized|401/i.test(e.message)) fixProviderKey(); else throw e;
} Prevention
- Validate provider credentials with a one-token chat before integrating
- Keep workspace.chatModel in sync with the provider's current model list
- Send document attachments with mime application/anythingllm-document
- Wrap every /chat call in a handler that understands the abort-shaped error body
When it happens
Trigger: POST /api/v1/workspace/:slug/chat where: the configured LLM provider key is invalid/missing (e.g. LLM_PROVIDER=openai with no OPEN_AI_KEY); workspace.chatModel points to a model the provider no longer serves; the embedder was changed without re-embedding; a document attachment is sent with a non 'application/anythingllm-document' mime type and the LLM rejects it; the vector DB (e.g. lancedb) files are corrupted or unreadable.
Common situations: Switching LLM_PROVIDER/env vars without updating the workspace's saved chatModel; Docker container missing provider env vars after an image upgrade; database migration skipped after upgrading AnythingLLM; hitting the API before finishing first-run provider setup in the UI.
Related errors
- e.message
- Workspace ${slug} not found.
- Thread ${threadSlug} not found.
- Message is empty
- ${resolvedMode} is not a valid mode.
AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18).
Data as JSON: /api/errors/5c7e74f17d6e7d61.
Report an issue: GitHub.