Articles

LLM Latency: Time to First Token vs Tokens per Second

LLM latency has two parts: time to first token (TTFT) and output speed in tokens per second. What drives each, how to measure them, and how to cut them.

Chisato Chisato · · 5 min read
A black stopwatch on a dark background

LLM latency is best understood as two separate numbers. Time to first token (TTFT) is how long you wait before the model produces anything. Output speed, usually given in tokens per second, is how fast the rest of the response streams once it starts. They are driven by different parts of inference, so optimizing one often does little for the other. Knowing which one your users actually feel is the first step to making an AI feature seem fast.

The two phases of inference

A transformer generates a response in two distinct phases.

Prefill processes the entire input prompt: system instructions, conversation history, retrieved documents, and the user’s message. All input tokens are handled in parallel, which keeps the GPU’s compute units busy. Prefill ends when the model produces the first output token. Its cost grows with prompt length.

Decode generates the output one token at a time. Each new token depends on all the previous ones, so this phase is sequential. For each step, the model reads its weights and the KV cache from memory to produce one token. Decode is usually limited by memory bandwidth rather than raw compute, which is why the relationship between memory bandwidth and latency matters so much for inference hardware.

TTFT is dominated by prefill plus any time spent waiting in a queue. Output speed is a property of decode.

TTFT vs tokens per second

Time to first tokenTokens per second
What it measuresWait before any output appearsSpeed of streaming after output starts
Inference phasePrefill, plus queueing and networkDecode
Main bottleneckCompute and prompt lengthMemory bandwidth and model size
Grows withInput lengthOutput length (for total time)
Users feel it as”Is it doing anything?""How fast is it typing?”
Key leversShorter prompts, prompt caching, less queueingSmaller or faster models, speculative decoding

A related metric is inter-token latency, the average gap between consecutive tokens. It is essentially the inverse of tokens per second for a single request. End-to-end latency is the total time for the full response: roughly TTFT plus output tokens divided by output speed.

Which one matters for your use case

It depends on how the output is consumed.

  • Chat interfaces with streaming. TTFT matters most. Once text starts appearing, people read along, and a decode speed faster than reading speed adds little perceived benefit. Streaming over server-sent events is what makes this work.
  • Agents and tool calls. End-to-end latency matters most, because the next step cannot start until the model finishes its output. A multi-step agent multiplies every second of decode time.
  • Structured output parsed by code. End-to-end latency again. Nothing useful happens until the full JSON arrives.
  • Background and batch jobs. Throughput across many requests matters more than any single request’s latency. Our comparison of batch vs real-time inference covers that trade-off.

What drives time to first token

Prompt length. Prefill work grows with the number of input tokens, and attention cost grows faster than linearly with length. Long retrieved documents and sprawling conversation histories push TTFT up.

Queueing. On a busy server, your request may wait for capacity before prefill even starts. This is often the largest and least predictable component, and it shows up in the tail latency more than the median.

Network and overhead. TLS setup, request routing, and safety checks add fixed time on every call.

Reasoning before answering. Models that produce internal reasoning tokens before the visible answer effectively delay the first useful token, even if the first raw token arrives quickly.

How to reduce TTFT

  • Trim the prompt. Remove redundant instructions, summarize old conversation turns, and retrieve fewer, better chunks.
  • Use prompt caching. If many requests share a long, stable prefix such as a system prompt or a reference document, a provider’s cache can skip recomputing it. Put stable content first and variable content last so the shared prefix is as long as possible. See prompt caching and LLM costs.
  • Keep connections warm. Reuse HTTP connections rather than paying for a new handshake on every request.
  • Stream everything. Even when total time is unchanged, showing the first tokens immediately changes how fast the product feels.

What drives output speed

During decode, the hardware must move a large amount of data, the model’s active weights and the growing KV cache, for every token. That makes output speed depend on:

  • Model size. Larger models read more weights per token and generate more slowly on the same hardware.
  • Hardware memory bandwidth. Faster memory directly raises the ceiling on tokens per second.
  • Batching. Servers process many requests together to use hardware efficiently. Continuous batching raises total throughput, but heavier batches can lower the speed any single request sees.
  • Context length. A longer context means a bigger KV cache to read on every step.

How to increase tokens per second

  • Pick a smaller model for tasks that do not need the largest one. This is often the single biggest lever.
  • Generate fewer tokens. Ask for concise output, set a sensible maximum, and avoid formats that are verbose by nature. Fewer output tokens cut end-to-end latency and cost together; the LLM token cost calculator helps estimate the cost side.
  • Speculative decoding. A small draft model proposes several tokens and the large model verifies them in one pass, which can produce several tokens per expensive step. See speculative decoding.

How to measure latency properly

Record timestamps on the client: when the request was sent, when the first token arrived, and when the last token arrived. From those you get TTFT, end-to-end latency, and output speed as output tokens divided by the time between first and last token. Always look at percentiles, not just averages. A median TTFT that looks fine can hide a 95th percentile several times worse, and those slow requests are the ones users remember.

Measure with realistic prompts. A benchmark with a ten-token prompt says little about a production request carrying thousands of tokens of retrieved context.

The takeaway

LLM latency splits into time to first token, set by prefill and queueing, and tokens per second, set by memory-bound decode. Streaming chat lives or dies by TTFT, while agents and structured output care about end-to-end time. Shorten and cache prompts to cut TTFT, and choose smaller models, shorter outputs, or speculative decoding to raise output speed.

Chisato Chisato · · 5 min read

Prefill vs Decode: The Two Phases of LLM Inference

LLM inference runs in two phases: prefill processes the prompt in parallel, decode generates tokens one at a time. Why they behave so differently.

#AI #LLMs #Machine Learning
Chisato Chisato · · 4 min read

Continuous Batching in LLM Inference Explained

Continuous batching lets an LLM server add and remove requests from a batch mid-generation, instead of waiting for a fixed group to finish together.

#AI #LLMs #Performance
Chisato Chisato · · 4 min read

What Is Semantic Caching for LLM Applications?

Semantic caching reuses an LLM's past response for a new prompt that means the same thing, by comparing embeddings instead of exact text.

#AI #LLMs #Performance