Mintplex-Labs/anything-llm · error
Not Found
Error message
Not Found
What it means
Returned by POST /export-chat/:type when the workspaceSlug supplied in the request body does not resolve to a workspace. In single-user mode Workspace.get({slug}) returns null; in multi-user mode Workspace.getWithUser(user,{slug}) also returns null when the user lacks membership. The 404 is an explicit resource-existence guard before the expensive chat-history query is run.
Source
Thrown at server/endpoints/utils.js:53
app.post(
"/export-chat/:type",
[validatedRequest, flexUserRoleValid([ROLES.all])],
async (request, response) => {
try {
const { type } = request.params;
if (!validExportTypes.includes(type))
return response.sendStatus(400).end();
const { workspaceSlug, threadSlug } = reqBody(request);
const { Workspace } = require("../models/workspace");
const { WorkspaceThread } = require("../models/workspaceThread");
const { WorkspaceChats } = require("../models/workspaceChats");
const user = await userFromSession(request, response);
const workspace = multiUserMode(response)
? await Workspace.getWithUser(user, { slug: String(workspaceSlug) })
: await Workspace.get({ slug: String(workspaceSlug) });
if (!workspace) return response.sendStatus(404).end();
let thread;
if (threadSlug) {
thread = await WorkspaceThread.get({
slug: String(threadSlug),
user_id: user?.id || null,
});
if (!thread) return response.sendStatus(404).end();
}
const chats = await WorkspaceChats.where({
workspaceId: workspace.id,
user_id: user?.id || null,
thread_id: thread?.id || null,
});
if (chats.length === 0) return response.sendStatus(400).end();
const meta = {View on GitHub (pinned to 526360e320)
Solutions
- Call GET /workspace/:slug first and confirm it returns 200 before issuing the export POST.
- In multi-user mode, verify the authenticated user is a member of the target workspace.
- Ensure the request body includes a non-empty workspaceSlug string that matches an existing workspace slug.
Example fix
// before
POST /export-chat/json
{ "workspaceSlug": "my-workspce" } // typo → 404
// after
POST /export-chat/json
{ "workspaceSlug": "my-workspace" } Defensive patterns
Strategy: validation
Validate before calling
// Before calling POST /export-chat/:type, confirm the workspace exists:
async function workspaceExists(api, workspaceSlug) {
const res = await api.get(`/workspace/${encodeURIComponent(workspaceSlug)}`);
return res.status === 200 && !!res.data?.workspace;
}
if (!(await workspaceExists(api, workspaceSlug))) {
throw new Error(`Workspace '${workspaceSlug}' not found or inaccessible`);
} Type guard
function isValidWorkspaceSlug(slug) {
return typeof slug === 'string' && slug.trim().length > 0 && /^[a-z0-9-]+$/i.test(slug);
} Try / catch
try {
const res = await api.post('/export-chat/json', { workspaceSlug });
} catch (e) {
if (e.response?.status === 404) {
// workspace not found — prompt user to select a valid workspace
} else { throw e; }
} Prevention
- Fetch the workspace list once and populate a dropdown so users pick valid slugs.
- In multi-user mode, filter the list to workspaces the user can access.
- Validate the slug format client-side before making the request.
When it happens
Trigger: POST /export-chat/json (or csv/jsonl) with a workspaceSlug that is misspelled, belongs to another user under multi-user mode, references a deleted workspace, or is undefined (coerced to the literal string 'undefined').
Common situations: Frontend cached a stale workspace slug after the workspace was renamed or deleted; multi-user mode was toggled on and the caller is no longer a member; copy-paste typo in the slug.
Related errors
- Bad Request
- res.statusText || "Error setting watch status for document."
- Error setting suggested messages.
- Failed to create workspace
- File not found
AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13).
Data as JSON: /api/errors/572b9abd926688d6.
Report an issue: GitHub.