Training & Inference

Time to First Token: Separating Network Delay, Queue Wait and Prompt Processing

Time to first token (TTFT) adds up three spans you can measure separately:

  1. Network trip: the request travels from the client to the server.
  2. Queue wait: the request waits for a free GPU.
  3. Prefill: the model reads the prompt before it writes the first token.

Timestamp the boundaries between them, and your own monitoring points to the span that needs work. Each section below gives a check, the pattern each cause leaves in your latency numbers, and a fix.

TL;DR: Log four timestamps per request, and the gaps between them show the span behind the delay. A spike in the slowest requests with a steady median often points to queue contention, and TTFT that climbs with prompt length points to prefill.

What Time to First Token Measures

TTFT runs from the moment a client submits a request to the moment the first output token arrives. IBM's explainer splits it into queueing delay, prefill time, first-token generation and network overhead.

The NVIDIA NIM benchmarking docs list request queuing time, prefill time and network latency. NVIDIA's benchmark also counts tokenization and de-tokenization of the first token inside TTFT.

TTFT stops at the first token. The gaps between later tokens make up inter-token latency, also called time per output token (TPOT), which has its own causes.

Queue Wait: Time Spent Waiting for a GPU

Suspect queue wait when TTFT swings from one request to the next. Anyscale's serving metrics docs note that a busy server may queue incoming requests, and that this delay adds to TTFT.

The check: compare the time the request entered the queue with the moment a GPU starts processing the request. That gap is the queue wait.

The signature: p50 is the median TTFT, and p99 is the TTFT that the slowest 1% of requests exceed. Redis's TTFT guide reads a p99 that spikes while p50 stays flat as a common sign of queue contention during traffic bursts.

A mix of short and long prompts also widens the gap between p50 and p99. Confirm with the queue timestamps before acting.

The fix: autoscale on queue depth, add admission control to turn away or delay excess requests, or route traffic to less busy copies of the model (replicas). If the fleet is short of GPUs, rerouting moves the wait to another replica, so add GPUs.

Track goodput, which Anyscale defines as the percentage of requests that meet your latency targets. Under heavy load, a server can raise its throughput and still miss more of those targets.

Prefill: When the Prompt Slows the First Token

For longer prompts, prefill is often the largest contributor to TTFT, according to IBM.

During prefill, the model reads the prompt and builds its KV cache, the stored attention data it reuses for each later token. Each extra prompt token adds prefill work ahead of the first output token.

The check: plot TTFT against prompt token count across your traffic. If TTFT climbs with prompt length, prefill takes the largest share of the delay.

Nscale's worked example shows the arithmetic: raising prefill throughput from 1,000 to 2,500 tokens per second cuts a 100,000-token prompt from about 100 seconds to 35–40 seconds. That's one vendor's illustration, so measure your own prefill throughput before planning on a similar gain.

The signature: the cost of reading the prompt grows with its length, so the gap between p50 and p99 follows your mix of prompt lengths. Uniformly long prompts raise each percentile, and a mix of short and long prompts widens the gap.

The fix, in order of effort: shorten prompts by trimming retrieved context and system preamble, or turn on prefix caching. Redis describes prefix caching as computing the KV cache once for a shared prefix, such as a system prompt, and reusing it across requests.

After a change, measure how much useful work the GPUs do during prompt processing with model FLOPs utilization and model bandwidth utilization.

Network Latency: Timing the Trip From Client to Server

Rule out network delay first when you already log timestamps on both the client and the server, because it's the cheapest check.

The check: compare the client's send timestamp with the server's receive timestamp. That gap covers the network trip plus a proxy, load balancer or TLS handshake in the path.

The two timestamps come from different machines, so sync their clocks before trusting the gap. Depending on where your stack runs the tokenizer, this gap can also include some tokenization time.

The signature: a slower network path adds roughly the same delay to each request, so p50 and p99 rise by about the same amount. A regional routing change or a new proxy in the path can cause that kind of shift.

Redis reads that same pattern as a sign of an undersized model or undersized hardware. The client-to-server gap separates the two cases.

The fix: route clients to a regional endpoint and keep connections open between requests. Stream the response, so the server sends the first token without waiting for the rest of the reply.

Four Timestamps to Log for Time to First Token

The checks above need four timestamps per request, stored on a span, one timed step in a trace.

Record each model call as a span with OpenTelemetry's Gen AI semantic conventions, which give AI calls shared attribute names such as gen_ai.operation.name and gen_ai.usage.input_tokens. Add these four timestamps to that span:

  1. `t0`: the client sends the request.
  2. `t1`: the server receives the request.
  3. `t2`: a GPU takes the request off the queue and starts prefill.
  4. `t3`: the server emits the first token back toward the client.

The gaps follow from those timestamps: t1 − t0 is network, t2 − t1 is queue wait, and t3 − t2 is mostly prefill. Tokenization lands in the gap where your stack runs the tokenizer.

Log the prompt token count next to the timestamps, and each check above becomes a query against your logs.

SpanGap to computePattern in your numbersFirst fix to try
Network and transportt1 − t0p50 and p99 rise by the same amountRegional endpoint
Queue waitt2 − t1p99 spikes during burstsAutoscale on queue depth
Prefillt3 − t2 (mostly)TTFT climbs with prompt token countShorter prompts

Worked Example: Reading One Time to First Token Spike

Suppose your dashboard shows p50 TTFT flat at 800 ms for hours, then p99 climbing past 4 seconds during traffic bursts. Redis reads that pattern as a common sign of queue contention.

Confirm with timestamps before acting. Pull the queue gap (t2 − t1) for requests inside the burst window, and if it accounts for the 3-plus seconds of excess, the queue is the cause.

Scale on queue depth or reroute traffic, then compare the new percentiles with the old ones. If p99 falls back toward p50, that confirms the diagnosis.

If the excess remains, run the prefill check next by plotting TTFT against prompt length.

Time to First Token in RAG and Multi-Call Agents

The three-span split assumes one request makes one model call. Retrieval-augmented generation (RAG), which fetches documents before the model reads the prompt, adds a retrieval step to TTFT before prefill starts.

Redis cites one RAG benchmark in which retrieval took 41% of end-to-end latency and 45–47% of TTFT. Redis notes that the share varies by architecture, so add a timestamp around retrieval before reading the other gaps.

Agents that chain several model calls pay a network trip and a queue wait at each hop. A per-call TTFT reading won't show the slow hop, so tie the calls together in one trace at the agent level.

A saturated fleet needs fixes beyond a single request, in how the cluster schedules work and recovers from hardware failures.

Zettabyte's zWARE schedules AI workloads across a cluster, tracks GPU and network card health, and runs automated recovery. The diagnostic steps above don't depend on zWARE.

Time to First Token FAQ

Does a high time to first token mean the model is slow?

A high TTFT can come from the network or the queue while the model runs at its normal speed. Under heavy load, queue wait can grow without a change in the prefill time per request.

Can two requests have the same time to first token for different reasons?

Yes, two 2-second requests can have different causes: one spends 1,900 ms in a queue and the other 1,900 ms in prefill. The span timestamps show the cause of each delay.