Mintplex-Labs/anything-llm · error
Internal Server Error
Error message
Internal Server Error
What it means
POST /v1/workspace/new calls `Workspace.new(name, null, additionalFields)`; expected validation failures (missing/invalid name) return 400 with a message, so the sendStatus 500 from this catch means Workspace.new threw — typically a Prisma write error such as a unique-slug collision race or DB unavailability, or an unexpected type in additionalFields. Post-creation telemetry is internally try/caught, but the EventLogs insert and any Prisma throw also land here. The real error is on the server console.
Solutions
- Check server logs for the Prisma error code (P2002 = duplicate slug, P1001 = connection)
- If duplicate slug: fetch GET /v1/workspaces and either reuse the existing workspace or send a more unique name
- Send only known workspace fields (name, openAiTemp, openAiHistory, openAiPrompt, similarityThreshold, chatProvider, chatModel) with correct types
- Retry after confirming DB health with GET /v1/system
Example fix
// before
const res = await fetch(`${base}/api/v1/workspace/new`, {method:'POST', headers, body: JSON.stringify({name:'Test'})});
// after
const name = `Test-${Date.now()}`; // avoid slug collisions on concurrent creates
const res = await fetch(`${base}/api/v1/workspace/new`, {method:'POST', headers, body: JSON.stringify({name})});
if (res.status === 400) throw new Error((await res.json()).message); // validation
if (res.status === 500) throw new Error('workspace create threw - check server log'); Defensive patterns
Strategy: validation
Validate before calling
const nameOk = typeof name === 'string' && name.trim().length > 0 && name.length <= 100;
if (!nameOk) throw new Error('workspace name required'); Type guard
const isWorkspaceCreateBody = (b) => b != null && typeof b.name === 'string' && b.name.trim().length > 0;
Try / catch
try { const r = await post(newWorkspaceUrl, {name}); if (r.status===400) throw new Error((await r.json()).message); if (r.status===500) throw new Error('create threw (duplicate slug / DB) - retry with unique name'); } catch (e) { throw e; } Prevention
- Generate unique names (suffix timestamp/uuid) when creating in bulk
- Send only known workspace fields with native types
- Store returned slug immediately - it is the key for all later calls
When it happens
Trigger: Two concurrent creations resolving to the same slugified name (unique constraint P2002); database unreachable at insert time; passing additionalFields containing keys with wrong types (e.g. openAiHistory: 'many') that violate the column type.
Common situations: Automation scripts creating many similarly-named workspaces ('Test', 'Test 2') racing slug generation; DB restarts during bulk provisioning; clients forwarding arbitrary JSON into the body which is spread into Workspace.new.
Understand the failure class
- HTTP status errors: handling 4xx and 5xx responses — how to handle 4xx and 5xx responses properly.
Related errors
AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18).
Data as JSON: /api/errors/719cc46c8e8dfb58.
Report an issue: GitHub.
Appendix: source
Thrown at server/endpoints/api/workspace/index.js:105
response.status(400).json({ workspace: null, message });
return;
}
await Telemetry.sendTelemetry("workspace_created", {
multiUserMode: multiUserMode(response),
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_workspace_created", {
workspaceName: workspace?.name || "Unknown Workspace",
});
response.status(200).json({ workspace, message });
} catch (e) {
console.error(e.message, e);
response.sendStatus(500).end();
}
});
app.get("/v1/workspaces", [validApiKey], async (request, response) => {
/*
#swagger.tags = ['Workspaces']
#swagger.description = 'List all current workspaces'
#swagger.responses[200] = {
content: {
"application/json": {
schema: {
type: 'object',
example: {
workspaces: [
{
"id": 79,
"name": "Sample workspace",
"slug": "sample-workspace",View on GitHub (pinned to 3aec848f28)