n8n-io/n8n · error · Error
SSE connection failed (${res.status}): ${text}
Error message
SSE connection failed (${res.status}): ${text} What it means
The SSE client opens a streaming connection to /rest/instance-ai/events/<thread> with cookie auth. If the response is not 2xx, it reads the body and throws with status+text so the caller knows why the stream never opened (typically auth, thread-not-found, or server error).
Source
Thrown at packages/@n8n/instance-ai/evaluations/clients/sse-client.ts:40
* the response is not a valid SSE stream.
*/
export async function consumeSseStream(
url: string,
cookie: string,
handler: (event: SseEvent) => void,
signal: AbortSignal,
): Promise<void> {
const res = await fetch(url, {
headers: {
cookie,
Accept: 'text/event-stream',
},
signal,
});
if (!res.ok) {
const text = await res.text();
throw new Error(`SSE connection failed (${res.status}): ${text}`);
}
if (!res.body) {
throw new Error('SSE response has no body');
}
const reader = res.body.pipeThrough(new TextDecoderStream()).getReader();
// Accumulator for partial lines (SSE data can be split across chunks)
let buffer = '';
// Current event being assembled
let eventId: string | undefined;
let eventType: string | undefined;
let dataLines: string[] = [];
try {
while (true) {View on GitHub (pinned to 5ac6606e81)
Solutions
- Ensure client.login() ran and the cookie is valid before opening the SSE stream.
- Confirm the threadId exists (await ensureThread) before subscribing to its events.
- Retry on 5xx with backoff; do not retry on 4xx without fixing the precondition.
Defensive patterns
Strategy: validation
Validate before calling
if (!client.sessionCookie) await client.login(); await client.ensureThread(threadId); // ensure thread exists before SSE
Try / catch
try { await openSse(url, cookie, signal, onEvent); }
catch (e) {
if (e instanceof Error && e.message.startsWith('SSE connection failed')) { /* classify status, retry only on 5xx */ }
else throw e;
} Prevention
- Ensure login + ensureThread before opening the SSE stream.
- Retry only transient (5xx/network) failures, not 4xx.
- Surface the status from the message to drive branching.
When it happens
Trigger: Cookie missing/expired (401/403); threadId that doesn't exist (404); instance-ai events endpoint disabled (404); server error (5xx).
Common situations: Reading the cookie before login; race where the thread is created async and SSE starts before it commits; instance-ai feature flag off.
Related errors
- Failed to authenticate with n8n — no session cookie received
- Not authenticated — call login() first
- MCP api-key rotate endpoint returned no apiKey
- MCP api-key rotate endpoint returned a redacted key — cannot
- Invitation accepted but no session cookie received
AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12).
Data as JSON: /api/errors/dcc0684613061b24.
Report an issue: GitHub.