n8n-io/n8n · error
500
500
Error message
e.message
What it means
Returned as HTTP 500 `{ code: 500, message: e.message }` from the AI Assistant `/chat` (or stream-style) endpoint when an error occurs BEFORE streaming begins (headers not yet sent). The catch asserts `e instanceof Error` then sends the native message. If headers were already sent, it just ends the response to avoid a double-write.
Source
Thrown at packages/cli/src/controllers/ai.controller.ts:136
role: 'assistant',
type: 'error',
content: streamError.message,
},
],
};
res.write(JSON.stringify(errorChunk) + STREAM_SEPARATOR);
} finally {
// Clean up event listener
res.off('close', handleClose);
}
res.end();
} catch (e) {
// This catch block handles errors that occur before streaming starts
// Since headers haven't been sent yet, we can still send a proper error response
assert(e instanceof Error);
if (!res.headersSent) {
res.status(500).json({
code: 500,
message: e.message,
});
} else {
// If headers were already sent dont't send a second error response
res.end();
}
}
}
@Post('/chat', { ipRateLimit: { limit: 100 } })
async chat(req: AuthenticatedRequest, res: FlushableResponse, @Body payload: AiChatRequestDto) {
try {
const abortController = new AbortController();
const { signal } = abortController;
const handleClose = () => abortController.abort();
res.on('close', handleClose);View on GitHub (pinned to 5ac6606e81)
Solutions
- Check the server logs for the full stack trace of the underlying `e`.
- Verify AI provider credentials and connectivity from the n8n host.
- Update `@n8n/ai-assistant-*` packages to a version compatible with the SDK.
- Retry — transient provider 5xxs are common.
Defensive patterns
Strategy: try-catch
Try / catch
try { await api.post('/ai/...', payload); } catch (e) { if (e.response?.status === 500) { logAiConfigDiagnostics(); await retryWithBackoff(); } else throw e; } Prevention
- Validate AI credentials and provider connectivity in a startup health check.
- Keep AI assistant package versions aligned with the backend SDK.
When it happens
Trigger: The upstream AI SDK fails during request setup (auth, payload validation, network DNS, model unavailable) before any chunk is streamed; an unexpected throw inside `aiService` prior to the first `res.write`.
Common situations: AI provider outage; misconfigured AI credentials (`N8N_AI_*`); SDK version mismatch; request payload triggers an internal assertion.
Related errors
- output.error.errors[0]
- Plan lacks license for this feature
- 401
- User is missing a scope required to perform this action
- error.message
AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12).
Data as JSON: /api/errors/71149b599fd75f74.
Report an issue: GitHub.