Mintplex-Labs/anything-llm · error · Error

Error generating api key.

Error message

Error generating api key.

What it means

Thrown by generateApiKey in the AnythingLLM frontend when POST /api/system/generate-api-key responds non-2xx. The message is res.statusText with a fallback string — statusText is often just 'Internal Server Error' or empty behind some proxies, so the generic text frequently is what you see. The route inserts a new API key row, so failures are usually database-side.

Solutions

  1. Check server logs for the actual 500 cause (database connection, missing table).
  2. Run pending database migrations after upgrading the server.
  3. Re-login if the request returned 401, then retry generation.
  4. If statusText came back empty through a proxy, correlate with the status code in the Network tab.
Defensive patterns

Strategy: try-catch

Try / catch

const { apiKey, error } = await System.generateApiKey(data);
if (!apiKey) {
  // error is statusText or 'Error generating api key.' — server logs hold the cause
  showApiKeyError(error);
  return;
}

Prevention

When it happens

Trigger: Database unreachable or locked when inserting the key row (500); missing api_keys table because migrations were not run after an upgrade; expired/invalid auth token (401); a reverse proxy returning an empty statusText.

Common situations: SQLite database file locked by a concurrent backup; container upgraded without running migrations; long-lived session that expired between page load and the click.

Understand the failure class

Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@20f6d3546c (2026-08-18). Data as JSON: /api/errors/17260accd9fb5cd3. Report an issue: GitHub.

Appendix: source

Thrown at frontend/src/models/system.js:570

        if (!res.ok) {
          throw new Error(res.statusText || "Error fetching api key.");
        }
        return res.json();
      })
      .catch((e) => {
        console.error(e);
        return { apiKey: null, error: e.message };
      });
  },
  generateApiKey: async function (data = {}) {
    return fetch(`${API_BASE}/system/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}/system/api-key/${apiKeyId}`, {
      method: "DELETE",
      headers: baseHeaders(),
    })
      .then((res) => res.ok)
      .catch((e) => {
        console.error(e);
        return false;
      });

View on GitHub (pinned to 20f6d3546c)