Mintplex-Labs/anything-llm · error · Error

res.statusText || "Error generating api key."

Error message

res.statusText || "Error generating api key."

What it means

The Qdrant 'namespace-stats' developer-API handler destructures { namespace = null } from the request body and throws immediately when falsy — request validation only, no Qdrant traffic. In this codebase namespaces map to Qdrant collections named after workspace slugs, so the caller must send the slug of an embedded workspace.

Solutions

  1. Send { "namespace": "<workspace-slug>" } as JSON with Content-Type: application/json.
  2. List valid slugs via the namespaces developer endpoint (or check the Qdrant console's collections list) before querying stats.
  3. Match the slug exactly — lowercase, dashes for spaces.
  4. If wrapping the API in code, validate the body locally first and fail with a clearer message.

Example fix

# before
curl -X POST http://localhost:3001/api/ext/vectors/namespace-stats \
  -H "Authorization: Bearer $API_KEY"

# after
curl -X POST http://localhost:3001/api/ext/vectors/namespace-stats \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"namespace": "my-workspace"}'
Defensive patterns

Strategy: validation

Validate before calling

function isValidNamespaceStatsBody(body) {
  return body != null && typeof body === 'object' &&
    typeof body.namespace === 'string' && body.namespace.trim().length > 0;
}

if (!isValidNamespaceStatsBody(req.body)) {
  return res.status(400).json({ error: 'namespace (workspace slug) is required' });
}
await client.post('/api/ext/vectors/namespace-stats', req.body);

Type guard

function isNamespaceRequest(body) {
  return (
    typeof body === 'object' && body !== null &&
    typeof body.namespace === 'string' &&
    body.namespace.length > 0
  );
}

Try / catch

try {
  const stats = await client.post('/api/ext/vectors/namespace-stats', { namespace });
} catch (e) {
  if (/namespace required/.test(e.message)) {
    // caller bug: empty body or wrong key — fix the request, do not retry
    throw new Error('Send { "namespace": "<workspace-slug>" } as JSON with Content-Type: application/json');
  }
  throw e;
}

Prevention

When it happens

Trigger: POSTing to /api/ext/vectors/namespace-stats without a namespace field, with null/''/undefined, with a wrong key ('workspace', 'collection'), or with a body that never parsed because Content-Type wasn't application/json.

Common situations: Hand-written curl missing --data; API client built from the wrong docs version; automation assuming a default workspace; JSON key typo after copy-paste from another endpoint.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18). Data as JSON: /api/errors/458cc79b4374715a. Report an issue: GitHub.

Appendix: source

Thrown at frontend/src/models/admin.js:216

        if (!res.ok) {
          throw new Error(res.statusText || "Error fetching api keys.");
        }
        return res.json();
      })
      .catch((e) => {
        console.error(e);
        return { apiKeys: [], error: e.message };
      });
  },
  generateApiKey: async function (data = {}) {
    return fetch(`${API_BASE}/admin/generate-api-key`, {
      method: "POST",
      headers: baseHeaders(),
      body: JSON.stringify(data),
    })
      .then((res) => {
        if (!res.ok) {
          throw new Error(res.statusText || "Error generating api key.");
        }
        return res.json();
      })
      .catch((e) => {
        console.error(e);
        return { apiKey: null, error: e.message };
      });
  },
  deleteApiKey: async function (apiKeyId = "") {
    return fetch(`${API_BASE}/admin/delete-api-key/${apiKeyId}`, {
      method: "DELETE",
      headers: baseHeaders(),
    })
      .then((res) => res.ok)
      .catch((e) => {
        console.error(e);
        return false;
      });

View on GitHub (pinned to 3aec848f28)