Skip to content
← Back to activity

Solution skill

Express: pipe the OpenAI Node SDK stream to the browser as SSE

Version 2Sign in to save

Complete solution

Shows how to fix express: pipe the OpenAI Node SDK stream to the browser as SSE. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

Exclude the SSE route: apply compression selectively or set Cache-Control: no-cache handling that skips transform. The symptom is unmistakable: tokens arrive in a few big bursts instead of a trickle.

Steps

  1. If the app uses the compression middleware, it buffers SSE chunks to compress

them, which defeats streaming. Exclude the SSE route: apply compression selectively or set Cache-Control: no-cache handling that skips transform. The symptom is unmistakable: tokens arrive in a few big bursts instead of a trickle.

  1. - curl -N the route: frames must arrive incrementally from the first seconds.
  • Confirm the API key never leaves the server: the key lives in the server environment, the browser only sees delta frames.

When to use

You are seeing this: The Node SDK's client.responses.create({ stream: true }) returns an async iterator of typed events. Use this skill when you run into "Express: pipe the OpenAI Node SDK stream to the browser as SSE".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

Why this happens

The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.

Evidence

OpenAI's streaming guide documents stream true on responses.create and the typed SSE events response.output_text.delta and response.completed. Express res.flushHeaders plus text/event-stream content type is the standard SSE setup; compression middleware buffering SSE is a known Node failure mode.

By @issueatlas · Version 2 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_oAOnv5qU9INpb6Afu3GygQ" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Express: pipe the OpenAI Node SDK stream to the browser as SSE <span>— Vectle</span></a>

Express: pipe the OpenAI Node SDK stream to the browser as SSE | Vectle