{"record":{"id":"aa5289771e72290a","repo":"Mintplex-Labs/anything-llm","slug":"bad-request-aa5289","errorCode":null,"errorMessage":"Bad Request","messagePattern":"Bad Request","errorType":"http","errorClass":null,"httpStatus":400,"severity":"warning","filePath":"server/endpoints/api/workspaceThread/index.js","lineNumber":78,"sourceCode":"                message: null\n              }\n            }\n          }\n        }\n      }\n      #swagger.responses[403] = {\n        schema: {\n          \"$ref\": \"#/definitions/InvalidAPIKey\"\n        }\n      }\n      */\n      try {\n        const wslug = request.params.slug;\n        let { userId = null, name = null, slug = null } = reqBody(request);\n        const workspace = await Workspace.get({ slug: String(wslug) });\n\n        if (!workspace) {\n          response.sendStatus(400).end();\n          return;\n        }\n\n        // If the system is not multi-user and you pass in a userId\n        // it needs to be nullified as no users exist. This can still fail validation\n        // as we don't check if the userID is valid.\n        if (!response.locals.multiUserMode && !!userId) userId = null;\n\n        const { thread, message } = await WorkspaceThread.new(\n          workspace,\n          userId ? Number(userId) : null,\n          { name, slug }\n        );\n\n        await Telemetry.sendTelemetry(\"workspace_thread_created\", {\n          multiUserMode: multiUserMode(response),\n          LLMSelection: process.env.LLM_PROVIDER || \"openai\",\n          Embedder: process.env.EMBEDDING_ENGINE || \"inherit\",","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/endpoints/api/workspaceThread/index.js#L60-L96","documentation":"Returned by POST /v1/workspace/:slug/thread/new as HTTP 400 when Workspace.get({ slug }) returns null. The handler at server/endpoints/api/workspaceThread/index.js:77 checks `if (!workspace)` and sends `response.sendStatus(400).end()`. The workspace slug in the URL path does not match any existing workspace. A thread cannot be created in a workspace that does not exist.","triggerScenarios":"POST /v1/workspace/nonexistent-slug/thread/new with { userId, name, slug } when the workspace slug does not exist. Also triggered by using the workspace name or numeric ID instead of the slug, or by URL-encoding problems. Note that the `name` and `slug` in the request body refer to the thread, while the `slug` in the URL path refers to the workspace — confusing these is a common source of this error.","commonSituations":"Creating a thread in a workspace that was deleted. Using the workspace name instead of its slug in the URL. Confusing the workspace slug (URL path param) with the thread slug (body param). The workspace exists in a different database/instance.","solutions":["Verify the workspace slug exists: GET /v1/workspaces.","Distinguish URL path `slug` (workspace) from body `slug` (thread) — they are different parameters.","Use the exact workspace `slug` field from the workspace object.","Handle 400 by re-fetching the workspace list and confirming the target workspace."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Verify the workspace slug exists before creating a thread\nasync function verifyWorkspaceForThread(slug, apiKey) {\n  const res = await fetch('/v1/workspaces', {\n    headers: { Authorization: `Bearer ${apiKey}` }\n  });\n  const { workspaces } = await res.json();\n  return workspaces.some(w => w.slug === slug);\n}","typeGuard":null,"tryCatchPattern":"try {\n  const exists = await verifyWorkspaceForThread(slug, API_KEY);\n  if (!exists) throw new Error(`Workspace '${slug}' not found — cannot create thread`);\n  const res = await fetch(`/v1/workspace/${slug}/thread/new`, {\n    method: 'POST',\n    headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${API_KEY}` },\n    body: JSON.stringify({ name: threadName })\n  });\n  if (res.status === 400) throw new Error('Workspace not found');\n  return await res.json();\n} catch (e) { console.error(e); }","preventionTips":["Distinguish the URL path `slug` (workspace) from the body `slug` (thread) — they are different parameters.","Verify the workspace slug exists via GET /v1/workspaces before creating a thread.","Omit the body `slug` to let the system auto-generate a unique thread slug.","Use the workspace `slug`, never its `name` or `id`."],"tags":["workspace","workspace-thread","express","anythingllm","request-validation","not-found"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}