All posts
Internet Fundamentals

Streaming AI Responses: SSE vs WebSockets, and the Timeouts That Cut Them Off

By

October 26, 2026

6 min read

Token-by-token output makes AI features feel fast, and every proxy, load balancer and gateway between the model and the browser has a timeout that can cut it off. When to use Server-Sent Events, WebSockets or a background job, with current AWS limits: API Gateway REST streaming up to 15 minutes, WebSocket connections up to 2 hours, Lambda streaming up to 200 MB.

Internet Fundamentals
Streaming
Server-Sent Events
WebSockets
Amazon API Gateway

An answer that takes 20 seconds feels slow behind a spinner and fast when words appear after half a second. Streaming changes perceived speed, not total time, and it means holding a response open for as long as generation takes.

Three ways to deliver it

Server-Sent Events

WebSockets

Background job

Direction

Server to client

Both ways

Client polls or gets a webhook

Protocol

An ordinary HTTP response with Content-Type text/event-stream

An upgraded connection (RFC 6455)

Ordinary requests

Reconnects

Built into the browser's EventSource, with Last-Event-ID

You write them

Not needed

Through CDNs and proxies

Usually, with buffering off

Needs explicit support

Yes

Fits

Chat answers and progress updates

Collaboration, live cursors, voice

Anything longer than a few minutes, or that must survive a closed tab

For a typical chat feature, SSE is the simplest fit: one request, one streamed response. Many teams read a streamed fetch body rather than using EventSource, which cannot send a POST body or custom headers.

Want a second opinion on this for your system?

Book a free 30-minute call. You'll leave knowing what we'd do first and roughly what it costs, whether or not you hire us.

Current AWS limits

Service

Limit

API Gateway REST API, response streaming

Up to 15 minutes; idle timeout 5 minutes (Regional, private) or 30 seconds (edge-optimized); first 10 MB unthrottled, then 2 MB/s; proxy integrations only

API Gateway REST API, buffered

29 seconds by default; 10 MB payload

API Gateway HTTP API

30 seconds maximum; response streaming is REST-only

API Gateway WebSocket API

2-hour connections, 10-minute idle timeout, 128 KB messages in 32 KB frames

Lambda response streaming

200 MB responses by default; first 6 MB uncapped, then 2 MB/s

Lambda

15 minutes per invocation

Timeouts along the path

  • The CDN's origin response timeout: CloudFront waits 30 seconds by default, including between bytes.

  • The load balancer's idle timeout: 60 seconds by default on an Application Load Balancer.

  • Your server or function timeout.

  • Proxy buffering, which holds the whole response before sending it and turns streaming back into waiting. Turn it off on streaming routes.

During long pauses, such as while the model is calling tools, send a heartbeat (an SSE comment line works) every 15 to 30 seconds so idle timeouts never fire.

When to stop streaming and use a job

If a task can run for minutes (research agents, long documents, batch generation) or must finish when the user closes the tab, run it as a background job, save progress as it goes, and stream updates from the saved state. A dropped connection then loses nothing.

hoolco Monthly Review

Once a month: what changed in tech that month and what it means for you, from cloud and AI to security and the tools you build with. Every item links to its source. No sales pitch, unsubscribe in one click.

As of October 26, 2026. Provided as is, for general information, and accurate to the best of our knowledge on the date shown. Not legal, compliance, tax, financial or other professional advice. Prices, limits and vendor services change; check current vendor documentation before relying on anything here. Terms of use.