Mintplex-Labs/anything-llm · warning
Bad Request
Error message
Bad Request
What it means
Returned by DELETE /v1/workspace/:slug as HTTP 400 when Workspace.get({ slug }) returns null, meaning no workspace exists with the given slug. The handler at server/endpoints/api/workspace/index.js:252 explicitly checks `if (!workspace)` and sends `response.sendStatus(400).end()`. This is a client-side error — the slug in the URL path does not match any workspace in the database. Note this route also passes through the workspaceDeletionProtection middleware which can return 403 if WORKSPACE_DELETION_PROTECTION is set.
Source
Thrown at server/endpoints/api/workspace/index.js:253
#swagger.parameters['slug'] = {
in: 'path',
description: 'Unique slug of workspace to delete',
required: true,
type: 'string'
}
#swagger.responses[403] = {
schema: {
"$ref": "#/definitions/InvalidAPIKey"
}
}
*/
try {
const { slug = "" } = request.params;
const VectorDb = getVectorDbClass();
const workspace = await Workspace.get({ slug: String(slug) });
if (!workspace) {
response.sendStatus(400).end();
return;
}
const workspaceId = Number(workspace.id);
await WorkspaceChats.delete({ workspaceId: workspaceId });
await DocumentVectors.deleteForWorkspace(workspaceId);
await Document.delete({ workspaceId: workspaceId });
await Workspace.delete({ id: workspaceId });
await EventLogs.logEvent("api_workspace_deleted", {
workspaceName: workspace?.name || "Unknown Workspace",
});
try {
await VectorDb["delete-namespace"]({ namespace: slug });
} catch (e) {
console.error(e.message);
}
response.sendStatus(200).end();View on GitHub (pinned to 526360e320)
Solutions
- Verify the slug exists first: call GET /v1/workspaces to list all valid slugs.
- Ensure you are using the `slug` field (e.g., 'my-workspace'), not the workspace `name` or `id`.
- Check for URL-encoding issues: if the slug contains special characters, ensure they are properly percent-encoded.
- Strip any trailing slashes or whitespace from the slug in your URL path.
- Handle 400 gracefully in your client — it means the resource is already gone, which may be acceptable for a delete operation (treat as idempotent success).
Example fix
// before — using workspace name instead of slug
await fetch('/v1/workspace/My%20Workspace', { method: 'DELETE' });
// after — fetch the correct slug first
const { workspaces } = await (await fetch('/v1/workspaces', {
headers: { Authorization: `Bearer ${API_KEY}` }
})).json();
const target = workspaces.find(w => w.name === 'My Workspace');
await fetch(`/v1/workspace/${target.slug}`, { method: 'DELETE' }); Defensive patterns
Strategy: validation
Validate before calling
// Verify the workspace slug exists before attempting deletion
async function ensureWorkspaceExists(slug, apiKey) {
const res = await fetch('/v1/workspaces', {
headers: { Authorization: `Bearer ${apiKey}` }
});
if (!res.ok) throw new Error('Cannot verify workspace list');
const { workspaces } = await res.json();
return workspaces.some(w => w.slug === slug);
} Try / catch
try {
const exists = await ensureWorkspaceExists(slug, API_KEY);
if (!exists) {
console.log(`Workspace '${slug}' does not exist — treating delete as idempotent success`);
return;
}
const res = await fetch(`/v1/workspace/${slug}`, {
method: 'DELETE',
headers: { Authorization: `Bearer ${API_KEY}` }
});
if (res.status === 400) {
// Workspace gone — treat as success for idempotent delete
return;
}
if (res.status === 403) throw new Error('Deletion blocked by WORKSPACE_DELETION_PROTECTION');
} catch (e) { console.error(e); } Prevention
- Treat 400 on DELETE as idempotent success — the workspace is already gone.
- Always verify the slug via GET /v1/workspaces before deletion to catch typos.
- Be aware of the WORKSPACE_DELETION_PROTECTION env var which blocks deletion with 403.
- Use the workspace `slug`, never the `name` or `id`, in the URL path.
When it happens
Trigger: DELETE /v1/workspace/non-existent-slug where 'non-existent-slug' has never been created or was already deleted. Also triggered by typos in the slug, URL-encoding issues (spaces or special characters in the slug not properly encoded), or by using the workspace name instead of the slug.
Common situations: Attempting to delete a workspace that was already deleted in a previous request. Using the workspace display name (e.g., 'My Workspace') instead of the slug (e.g., 'my-workspace-abc123'). Copy-pasting a slug from the UI that includes trailing whitespace or a trailing slash. Race condition where another admin deleted the workspace between your GET and DELETE.
Related errors
AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13).
Data as JSON: /api/errors/01e22d64672b8166.
Report an issue: GitHub.