Skip to main content

Import

What it does

StreamingHelper provides static methods for consuming server-sent events (SSE), newline-delimited JSON (NDJSON) streams, and file downloads with progress tracking. The new fetchSSE method uses the Fetch API instead of EventSource, unlocking POST requests, custom headers, AbortSignal, and typed multi-event streams.

Methods

fetchSSE<T>(endpoint, options?)

Returns an AsyncGenerator<SSEEvent<T>> that you consume with for await. The connection closes automatically when the server ends the stream or when you abort via signal.
fetchSSE is the recommended approach for modern SSE consumption. It supports every HTTP method, request bodies, and cancellation — none of which are possible with the browser-native EventSource API.

streamSSE<T>(endpoint, options?)

Legacy EventSource-based SSE. Returns { subscribe, close }.

streamJsonLines<T>(endpoint, options?)

Consumes a newline-delimited JSON (NDJSON) stream. Returns a Promise<StreamResponse<T>> once the stream completes.

downloadStream(endpoint, options?)

Downloads a binary resource as a Blob with optional progress tracking.

Types

SSEEvent<T>

FetchSSEOptions

StreamOptions

StreamResponse<T>

streamSSE vs fetchSSE

Examples

AI chat streaming with abort

NDJSON log tail

File download with progress

Use fetchSSE with an AbortController for AI/LLM streaming — it gives you full control over cancellation, unlike EventSource.
streamSSE relies on the EventSource API which only supports GET requests. If your endpoint requires POST or custom headers, use fetchSSE instead.