{"record":{"id":"5c7e74f17d6e7d61","repo":"Mintplex-Labs/anything-llm","slug":"e-message-5c7e74","errorCode":null,"errorMessage":"e.message","messagePattern":"e\\.message","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"server/endpoints/api/workspace/index.js","lineNumber":724,"sourceCode":"          attachments,\n          reset,\n        });\n\n        await Telemetry.sendTelemetry(\"sent_chat\", {\n          LLMSelection:\n            workspace.chatProvider ?? process.env.LLM_PROVIDER ?? \"openai\",\n          Embedder: process.env.EMBEDDING_ENGINE || \"inherit\",\n          VectorDbSelection: process.env.VECTOR_DB || \"lancedb\",\n          TTSSelection: process.env.TTS_PROVIDER || \"native\",\n        });\n        await EventLogs.logEvent(\"api_sent_chat\", {\n          workspaceName: workspace?.name,\n          chatModel: workspace?.chatModel || \"System Default\",\n        });\n        return response.status(200).json({ ...result });\n      } catch (e) {\n        console.error(e.message, e);\n        response.status(500).json({\n          id: uuidv4(),\n          type: \"abort\",\n          textResponse: null,\n          sources: [],\n          close: true,\n          error: e.message,\n        });\n      }\n    }\n  );\n\n  app.post(\n    \"/v1/workspace/:slug/stream-chat\",\n    [validApiKey],\n    async (request, response) => {\n      /*\n   #swagger.tags = ['Workspaces']\n   #swagger.description = 'Execute a streamable chat with a workspace'","sourceCodeStart":706,"sourceCodeEnd":742,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/endpoints/api/workspace/index.js#L706-L742","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nawait fetch(`${BASE}/api/v1/workspace/${slug}/chat`, {\n  method: 'POST',\n  headers: { Authorization: `Bearer ${API_KEY}`, 'Content-Type': 'application/json' },\n  body: JSON.stringify({ message: 'Summarize the docs' })\n});\n// after - surface the server's abort payload instead of throwing a generic Error\nconst res = await fetch(`${BASE}/api/v1/workspace/${slug}/chat`, { /* same */ });\nconst data = await res.json();\nif (!res.ok || data.type === 'abort')\n  throw new Error(`workspace chat failed: ${data.error ?? res.status}`);","handlingStrategy":"try-catch","validationCode":"const ws = await fetch(`${BASE}/api/v1/workspace/${slug}`, { headers: AUTH }).then(r => r.ok);\nif (!ws) throw new Error('workspace missing or unreachable - fix before chat');","typeGuard":"function isAbortPayload(data) {\n  return typeof data === 'object' && data !== null && data.type === 'abort' && typeof data.error === 'string';\n}","tryCatchPattern":"try {\n  const res = await chat(slug, body);\n  const data = await res.json();\n  if (isAbortPayload(data)) throw new Error(data.error); // carries the provider's real message\n} catch (e) {\n  if (/api key|unauthorized|401/i.test(e.message)) fixProviderKey(); else throw e;\n}","preventionTips":["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"],"tags":["anythingllm","developer-api","chat","llm-provider","http-500","catch-all"],"backgroundTag":"http-500-internal-server-error","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}