Mintplex-Labs/anything-llm · error

Could not find an API Key.

Error message

Could not find an API Key.

What it means

Catch block of GET /system/api-keys: querying ApiKey.where({}) threw (typically a database failure), so the endpoint responds 500 with this error string and a null apiKey. Also unreachable in multi-user mode, which is blocked earlier with 401.

Source

Thrown at server/endpoints/system.js:1049

    }
  );

  app.get("/system/api-keys", [validatedRequest], async (_, response) => {
    try {
      if (response.locals.multiUserMode) {
        return response.sendStatus(401).end();
      }

      const apiKeys = await ApiKey.where({});
      return response.status(200).json({
        apiKeys,
        error: null,
      });
    } catch (error) {
      console.error(error);
      response.status(500).json({
        apiKey: null,
        error: "Could not find an API Key.",
      });
    }
  });

  app.post(
    "/system/generate-api-key",
    [validatedRequest],
    async (request, response) => {
      try {
        if (response.locals.multiUserMode) {
          return response.sendStatus(401).end();
        }

        const { name = null } = reqBody(request);
        const { apiKey, error } = await ApiKey.create(null, name);
        await EventLogs.logEvent(
          "api_key_created",
          { name: apiKey?.name },

View on GitHub (pinned to 20f6d3546c)

Solutions

  1. Verify the API key ID exists before operating on it.
  2. List API keys and use a valid ID.
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at server/endpoints/system.js:1035 when the library encounters an invalid state.

Common situations: Referencing an API key that does not exist.


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