{"record":{"id":"17260accd9fb5cd3","repo":"Mintplex-Labs/anything-llm","slug":"error-generating-api-key","errorCode":null,"errorMessage":"Error generating api key.","messagePattern":"Error generating api key\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"frontend/src/models/system.js","lineNumber":570,"sourceCode":"        if (!res.ok) {\n          throw new Error(res.statusText || \"Error fetching api key.\");\n        }\n        return res.json();\n      })\n      .catch((e) => {\n        console.error(e);\n        return { apiKey: null, error: e.message };\n      });\n  },\n  generateApiKey: async function (data = {}) {\n    return fetch(`${API_BASE}/system/generate-api-key`, {\n      method: \"POST\",\n      headers: baseHeaders(),\n      body: JSON.stringify(data),\n    })\n      .then((res) => {\n        if (!res.ok) {\n          throw new Error(res.statusText || \"Error generating api key.\");\n        }\n        return res.json();\n      })\n      .catch((e) => {\n        console.error(e);\n        return { apiKey: null, error: e.message };\n      });\n  },\n  deleteApiKey: async function (apiKeyId = \"\") {\n    return fetch(`${API_BASE}/system/api-key/${apiKeyId}`, {\n      method: \"DELETE\",\n      headers: baseHeaders(),\n    })\n      .then((res) => res.ok)\n      .catch((e) => {\n        console.error(e);\n        return false;\n      });","sourceCodeStart":552,"sourceCodeEnd":588,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/frontend/src/models/system.js#L552-L588","documentation":"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.","triggerScenarios":"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.","commonSituations":"SQLite database file locked by a concurrent backup; container upgraded without running migrations; long-lived session that expired between page load and the click.","solutions":["Check server logs for the actual 500 cause (database connection, missing table).","Run pending database migrations after upgrading the server.","Re-login if the request returned 401, then retry generation.","If statusText came back empty through a proxy, correlate with the status code in the Network tab."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"const { apiKey, error } = await System.generateApiKey(data);\nif (!apiKey) {\n  // error is statusText or 'Error generating api key.' — server logs hold the cause\n  showApiKeyError(error);\n  return;\n}","preventionTips":["Run database migrations after every server upgrade so the api_keys table exists.","Keep an eye on DB connectivity (locked SQLite files during backups) when generation suddenly fails.","Do not parse the message for specifics — log the HTTP status alongside it."],"tags":["anythingllm","api-keys","database","http"],"backgroundTag":"http-request-failed","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}