Mintplex-Labs/anything-llm · warning

Bad Request

Error message

Bad Request

What it means

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.

Source

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

                message: null
              }
            }
          }
        }
      }
      #swagger.responses[403] = {
        schema: {
          "$ref": "#/definitions/InvalidAPIKey"
        }
      }
      */
      try {
        const wslug = request.params.slug;
        let { userId = null, name = null, slug = null } = reqBody(request);
        const workspace = await Workspace.get({ slug: String(wslug) });

        if (!workspace) {
          response.sendStatus(400).end();
          return;
        }

        // If the system is not multi-user and you pass in a userId
        // it needs to be nullified as no users exist. This can still fail validation
        // as we don't check if the userID is valid.
        if (!response.locals.multiUserMode && !!userId) userId = null;

        const { thread, message } = await WorkspaceThread.new(
          workspace,
          userId ? Number(userId) : null,
          { name, slug }
        );

        await Telemetry.sendTelemetry("workspace_thread_created", {
          multiUserMode: multiUserMode(response),
          LLMSelection: process.env.LLM_PROVIDER || "openai",
          Embedder: process.env.EMBEDDING_ENGINE || "inherit",

View on GitHub (pinned to 526360e320)

Solutions

  1. Verify the workspace slug exists: GET /v1/workspaces.
  2. Distinguish URL path `slug` (workspace) from body `slug` (thread) — they are different parameters.
  3. Use the exact workspace `slug` field from the workspace object.
  4. Handle 400 by re-fetching the workspace list and confirming the target workspace.
Defensive patterns

Strategy: validation

Validate before calling

// Verify the workspace slug exists before creating a thread
async function verifyWorkspaceForThread(slug, apiKey) {
  const res = await fetch('/v1/workspaces', {
    headers: { Authorization: `Bearer ${apiKey}` }
  });
  const { workspaces } = await res.json();
  return workspaces.some(w => w.slug === slug);
}

Try / catch

try {
  const exists = await verifyWorkspaceForThread(slug, API_KEY);
  if (!exists) throw new Error(`Workspace '${slug}' not found — cannot create thread`);
  const res = await fetch(`/v1/workspace/${slug}/thread/new`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${API_KEY}` },
    body: JSON.stringify({ name: threadName })
  });
  if (res.status === 400) throw new Error('Workspace not found');
  return await res.json();
} catch (e) { console.error(e); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13). Data as JSON: /api/errors/aa5289771e72290a. Report an issue: GitHub.