From request to first token
From the briefNumbers here are given in the practice brief.
A load balancer sends the request to any stateless gateway instance. Response buffering is disabled so chunks are not collected before the app sees them: the WHATWG HTML Standard defines server-sent events as a text/event-stream format for server-to-page messages, and it fits this one-way stream (WHATWG HTML Standard (opens in a new tab)).
If a proxy is in front, configure it for streaming. nginx, for example, says that when proxy buffering is disabled, the response is passed to the client immediately as it is received (nginx docs (opens in a new tab)).
The gateway checks the key, loads the policy from a local cache, reserves quota, optionally checks cache and guardrails, chooses a healthy allowed provider route and opens the provider stream. Each provider chunk is flushed through. If the caller disconnects or sends stop, the gateway sends cancellation to the provider, records what is known and lets billing or credits finish from the usage path.
- The app calls the common streaming API with an API key and request id.
- The gateway authenticates the key and reads the policy from local cache; a stale policy has a short versioned window.
- Admission reserves tokens and spend, and optional checks run only if the company enabled them.
- The router selects a healthy route from the company’s allowed list and region.
- Provider chunks are written through to the caller; a slow reader gets a bounded buffer, not unbounded memory.
- Disconnect or stop sends cancellation upstream, then finalises the request record with any provider work already produced.
Read:Learn: High-level architectureLearn: Real-time delivery architectureLearn: Latency budgeting
Keep reading+1 min
Timeouts for long streams
Use separate timeouts for connecting to a provider, waiting for the first token, idle gaps between chunks and total stream age. The first protects the gateway’s latency promise; the idle timeout catches a stuck stream; the total age lets deploys and clients avoid holding forgotten connections forever.
Backpressure from a slow reader
Each stream gets a bounded buffer. If the app reads too slowly and falls past that buffer, the gateway closes the client stream and sends cancellation to the provider. That contains memory per tenant and turns an overloaded client into that client’s failure, not a platform failure.