Server-Sent Events (SSE)
Server-Sent Events (SSE) is a web standard that lets a server push a continuous stream of text events to a client over a single long-lived HTTP connection. Browsers consume SSE with the EventSource API, and it is widely used to stream AI model tokens and live updates.
Technical Architecture & Deep-Dive
Unlike WebSockets, SSE is one-directional and runs over plain HTTP, so it works through proxies and CDNs with minimal configuration. Each event is formatted as `data:` lines separated by blank lines, with optional event names and IDs for reconnection.
OpenAI and Anthropic stream chat completions as SSE. An edge LLM gateway can relay these streams to browsers and mobile apps while hiding API keys and stripping verbose metadata from each event.
Key Architectural Benefits
Implement Server-Sent Events (SSE) at the Edge
Deploy lightweight API aggregation, edge caching, and secret injection in minutes without Docker containers or complex servers.
Frequently Asked Questions
Q:Should I use SSE or WebSockets?
Use SSE when the server pushes updates and the client rarely sends data. Use WebSockets when both sides need to send frequent messages.
Related Architecture Concepts
An LLM gateway, also called an AI gateway, is a proxy layer between applications and large language model providers such as OpenAI and Anthropic. It injects API keys server-side, enforces rate limits and budgets, caches responses, logs usage, and can fail over between models.
NDJSON, or newline-delimited JSON, is a format where each line contains one complete JSON object. It allows APIs to stream large result sets incrementally, so clients can parse and display records as they arrive instead of waiting for one large JSON array to finish downloading.
Edge Secret Injection is a security pattern where sensitive upstream API credentials (e.g. Stripe Secret Keys, OpenAI Tokens) are stored in an encrypted vault and injected into HTTP request headers exclusively at the edge runtime, ensuring client browsers and mobile apps never see or store the keys.
Ready-to-Use Edge Recipes
You should not store Anthropic credentials in Next.js / React client code. Next.js client chat UI calls edge stream; Anthropic never touches browser. RealComposer Secret Vault injects headers on Cloudflare Workers so only your edge URL is public.
Anthropic payloads are heavy for Frontend / Web. Edge strips rate limit headers and debug from streamed JSON chunks. RealComposer output mapping returns only the fields your UI needs at the edge.