Mintplex-Labs/anything-llm · error
Failed to create API key
Error message
Failed to create API key
What it means
500 from POST /browser-extension/api-keys/new. BrowserExtensionApiKey.create either throws or returns {error}, which the handler re-throws; key generation (uuid/crypto) almost never fails, so this is an INSERT failure into browser_extension_api_keys - locked DB (SQLITE_BUSY from a concurrent write), missing table after partial migration, or a full/read-only disk.
Source
Thrown at server/endpoints/browserExtension.js:190
}
);
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,
});
} catch (error) {
console.error(error);
response.status(500).json({ error: "Failed to create API key" });
}
}
);
app.delete(
"/browser-extension/api-keys/:id",
[validatedRequest, flexUserRoleValid([ROLES.admin, ROLES.manager])],
async (request, response) => {
try {
const { id } = request.params;
const user = await userFromSession(request, response);
if (multiUserMode(response) && user.role !== ROLES.admin) {
const apiKey = await BrowserExtensionApiKey.get({
id: parseInt(id),
user_id: user?.id,
});
if (!apiKey) {View on GitHub (pinned to 3aec848f28)
Solutions
- Read server logs - the re-thrown Error carries the create() error string (e.g. 'database is locked').
- Retry the create after a few seconds; SQLITE_BUSY is transient.
- Free disk space / fix volume permissions if the error is IO-related.
- If the table is missing, restart so migrations re-run.
Defensive patterns
Strategy: retry
Validate before calling
if (!await isAdminSession()) throw new Error('Only admin/manager sessions can create keys'); Try / catch
for (let attempt = 1; attempt <= 3; attempt++) {
try { return await createExtensionApiKey(); }
catch (e) {
if (e.status !== 500) throw e;
await sleep(400 * attempt); // SQLITE_BUSY on INSERT is transient
}
}
throw new Error('Key creation failed after retries - check server logs'); Prevention
- Serialize admin key-management actions instead of racing multiple tabs.
- Keep container disk space and volume write permissions healthy.
When it happens
Trigger: Two admins creating/deleting keys at the same instant so one INSERT hits SQLITE_BUSY; table missing after a failed upgrade; container disk exhausted or volume mounted read-only.
Common situations: Multi-tab admin UIs racing writes; low-disk containers; backups locking the SQLite file at the wrong moment.
Related errors
- Failed to fetch API keys
- Failed to revoke API key
- Could not find an API Keys.
- Failed to fetch workspaces
- Failed to disconnect and revoke API key
AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18).
Data as JSON: /api/errors/094d264adc752bfc.
Report an issue: GitHub.