A demo tells you a gateway works. It shows words appearing in a terminal, which is exactly the case where everything is already warm, the upstream is healthy, and nothing is queued.
Production is the other case. The measure that matters is not total latency, it is time to first token (TTFT), and it is also the measure that aggregators most often ruin without noticing.
Here is what we look at across 109 upstream models, and the failure modes that hide behind a 200.
The four shapes of "streaming"
- Real streaming. Upstream emits deltas as it generates; the gateway forwards each SSE frame as it arrives. TTFT tracks the upstream's TTFT plus routing overhead.
- Buffered streaming. The upstream streams, the gateway collects, and then replays the whole answer as a stream of chunks. Text is correct,
data: [DONE]is present, and TTFT equals full generation time. This is the one that gets shipped by accident: it passes every functional test. - Fake streaming. The endpoint returns a single
messageobject at the end regardless ofstream: true. Clients that gate their UI on the first chunk show a spinner until the answer is complete. - Stream that dies mid-flight. Early frames arrive, then the connection ends without
[DONE], or with a truncated JSON frame. If the client treats EOF as completion, the user gets half an answer and no error.
Only the first one is what your product assumes. The other three all return HTTP 200.
Measuring it honestly
TTFT has to be measured at the socket, not inside the SDK, and it has to be measured repeatedly - single samples are dominated by connection setup and upstream cold starts.
def ttft(base, key, model, n=5): samples = [] for _ in range(n): t0 = time.perf_counter() with urllib.request.urlopen(build_stream_request(base, key, model), timeout=60) as r: for line in r: if line.startswith(b"data:") and b"[DONE]" not in line: samples.append(time.perf_counter() - t0) break time.sleep(1) return round(min(samples), 3), round(sorted(samples)[len(samples)//2], 3) Report the minimum and the median. The minimum separates network noise from real behaviour; the median tells you whether users are routinely unlucky. A large gap between the two usually means queueing somewhere, not a slow model.
Why aggregators break it
Routing sits between you and the upstream, and every hop that wants to inspect a response body has to buffer it. Logging, token counting, content moderation, retry-on-error: each of these is easy to implement on a complete response and awkward to implement on a stream.
The rule we ended up with is blunt: nothing on the streaming path is allowed to hold the whole body. Token counts come from usage when the upstream sends it in the final chunk, and are estimated afterwards when it does not; logging samples frames instead of accumulating them; retries only happen before the first byte, never after.
That costs some accuracy in metrics. It buys TTFT that is actually the upstream's TTFT.
What to do with the number
Keep a per-model TTFT series, not a global one. A 109-model catalog has models that legitimately start in 300 ms and models that need 4 seconds to think before the first token; a single averaged figure hides both.
Our current per-model numbers, plus upstream incident history and the 429 scheduling behaviour that goes with them, are on the status page - it is the page we check before opening a support ticket, and the reason we stopped publishing "average latency" as a single number.
I maintain LONG AI, an OpenAI-compatible gateway over 109 upstream models. TTFT per model is measured continuously and published there.