Mintplex-Labs/anything-llm · error

Failed to fetch API keys

Error message

Failed to fetch API keys

What it means

500 from GET /browser-extension/api-keys (admin/manager session required). The try block covers userFromSession and BrowserExtensionApiKey.whereWithUser/where, so a failure here is a database-level problem reading the browser_extension_api_keys table (missing table after a broken migration, locked DB file) or session resolution blowing up - never an auth problem, since auth is enforced by middleware before the handler.

Source

Thrown at server/endpoints/browserExtension.js:169

    }
  );

  // Internal endpoints for managing API keys
  app.get(
    "/browser-extension/api-keys",
    [validatedRequest, flexUserRoleValid([ROLES.admin, ROLES.manager])],
    async (request, response) => {
      try {
        const user = await userFromSession(request, response);
        const apiKeys = multiUserMode(response)
          ? await BrowserExtensionApiKey.whereWithUser(user)
          : await BrowserExtensionApiKey.where();

        response.status(200).json({ success: true, apiKeys });
      } catch (error) {
        console.error(error);
        response
          .status(500)
          .json({ success: false, error: "Failed to fetch API keys" });
      }
    }
  );

  app.post(
    "/browser-extension/api-keys/new",
    [validatedRequest, flexUserRoleValid([ROLES.admin, ROLES.manager])],
    async (request, response) => {
      try {
        const user = await userFromSession(request, response);
        const { apiKey, error } = await BrowserExtensionApiKey.create(
          user?.id || null
        );
        if (error) throw new Error(error);
        response.status(200).json({
          apiKey: apiKey.key,
        });

View on GitHub (pinned to 3aec848f28)

Solutions

  1. Read server logs for the underlying SQLite error.
  2. Restart the server so boot migrations re-run and recreate the table if it is missing.
  3. Confirm the DB file is writable and not held by another process.
Defensive patterns

Strategy: try-catch

Validate before calling

await ensureAdminSession(); // validatedRequest cookie must be present and admin/manager role before the call

Try / catch

try { const { apiKeys } = await listExtensionApiKeys(); }
catch (e) {
  if (e.status === 500) throw new Error('Key listing failed at the DB layer - check server logs / migrate');
  if (e.status === 401 || e.status === 403) throw new Error('Session lacks admin/manager role');
  throw e;
}

Prevention

When it happens

Trigger: browser_extension_api_keys table absent after an interrupted upgrade/migration; SQLITE_BUSY while another writer holds the DB; corrupted session/user row making userFromSession throw.

Common situations: Upgrading an instance whose storage volume was partially persisted; running backups that lock the SQLite file; multi-admin sessions racing.

Related errors


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