langfuse/langfuse · error
Internal server error
Error message
Internal server error
What it means
500 catch-all for the apiKeys collection handler. Any unhandled exception from the entitlement check onward — Prisma errors in handleGetApiKeys/handleCreateApiKey, invalid body shapes, unique constraint violations on new keys — surfaces here after being logged.
Source
Thrown at web/src/pages/api/admin/organizations/[organizationId]/apiKeys/index.ts:65
});
if (!organization) {
return res.status(404).json({ error: "Organization not found" });
}
// Handle different HTTP methods
switch (req.method) {
case "GET":
return await handleGetApiKeys(req, res, organizationId);
case "POST":
return await handleCreateApiKey(req, res, organizationId);
default:
res.status(405).json({ error: "Method Not Allowed" });
return;
}
} catch (e) {
logger.error("Failed to process organization API key request", e);
res.status(500).json({ error: "Internal server error" });
}
}
View on GitHub (pinned to 59d92c7cf3)
Solutions
- Read the logged exception ('Failed to process organization API key request') to identify the sub-handler that threw
- Validate the POST body against the route's expected schema before sending
- Run prisma migrations if the schema is out of date
- Handle 409/unique conflicts by regenerating the key id and retrying
Example fix
// before
const res = await fetch(url, { method: 'POST', body: JSON.stringify(maybeWrongShape) });
// after
const body = { note: 'my key' }; // match route schema
const res = await fetch(url, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) });
if (!res.ok) throw new Error(`admin api failed: ${res.status}`); Defensive patterns
Strategy: try-catch
Validate before calling
const body = { note: 'string' };
const ok = typeof body.note === 'string'; Type guard
null
Try / catch
try { const r = await adminFetch(url, {...}); if (r.status >= 500) throw await r.text(); } catch (e) { /* inspect server logs, surface to user */ } Prevention
- Validate request bodies client-side against the route schema
- Apply DB migrations before deploying API consumers
When it happens
Trigger: POST with malformed JSON body that fails inside the create sub-handler; prisma.organizationApiKeys create colliding on unique(publicId); DB unavailable.
Common situations: Creating an API key on an org while another request does the same; body not matching the expected schema; self-hosted DB migrations not applied so the organizationApiKeys table is missing columns.
Understand the failure class
- HTTP status errors: handling 4xx and 5xx responses — how to handle 4xx and 5xx responses properly.
Related errors
- Internal server error
- Internal server error
- Internal server error
- Aggregation "${metric.aggregation}" is not valid for measure
- Internal server error
AI-assisted analysis of langfuse/langfuse@59d92c7cf3 (2026-08-27).
Data as JSON: /api/errors/a80bcc3f00e17980.
Report an issue: GitHub.