All posts

LLM latency: why your AI feature feels slow and how to cut time to first token

LLM latency is mostly output length, pre-inference work and missing streaming. Where the time goes, which fixes help most, and how to measure time to first token separately.

CodeKrypt 6 min read

Your AI feature works, the answers are good, and users still say it feels slow. LLM latency is rarely one problem. It is a sum of work before the model is called, the wait for the first token, and the time to generate the rest, and each part has a different fix. Teams often swap to a faster model and find the feature feels the same, because the delay was somewhere else.

This post covers where the time goes, the fixes in rough order of payoff, and how to measure time to first token so you know which one you need. It is about the domain, not any particular deployment; the sources are vendor documentation, linked inline.

Where does LLM latency actually come from?

Three places, and only one of them is the model's generation speed:

  1. Pre-inference work. Auth, retrieval, context assembly, prompt construction and any serial pre-checks. AWS's agentic AI guidance notes that by the time the first token leaves the model, the agent may already have used the whole latency budget on work that happens before inference begins.
  2. Time to first token (TTFT). The delay before the first output reaches the user.
  3. Generation. The time to produce the remaining tokens, which grows with the length of the answer.
Request timeline: pre-inference work, wait for first token, then generation. Streaming shows output from the first token onward; without streaming the user waits for the end.Pre-inferenceTo first tokenGenerationStreaming: user starts reading hereNo streaming: user sees output only here

The diagram is illustrative, not measured: the proportions differ for every product, which is the point of measuring.

What should you fix first?

OpenAI's latency guide lists seven principles. The two concrete numbers in it are worth remembering because they reorder the usual instincts:

Those are the guide's own rules of thumb, not guarantees, so test on your workload. Still, they suggest this order:

FixWhat it targetsTypical effortWatch out for
Stream the responsePerceived waitLowTool-call pauses, moderation on streamed text
Ask for shorter outputGeneration timeLowAnswers that become too terse to be useful
Trim structured-output syntaxGeneration timeLowVerbose JSON keys and wrappers add tokens
Parallelise independent stepsPre-inference and multi-call flowsMediumMore concurrent load against rate limits
Combine sequential callsRound tripsMediumLarger prompts, harder-to-debug failures
Use a smaller model for easy stepsGeneration and TTFTMediumNeeds an evaluation set to prove quality holds
Skip the LLM where code will doEverythingVariesNeeds a clear rule for when to bypass

Why does streaming matter more than raw speed?

Users judge a feature by when something starts to happen, not when it ends. AWS's guidance puts it directly: user-facing agents are judged on perceived latency, and streaming keeps time to first token short even when total processing takes several seconds. OpenAI's guide likewise calls showing progress through streaming and visible steps a main way to make users wait less.

Two caveats from the same sources:

If output passes through a moderation or guardrail step, there is a real trade-off. AWS notes that Bedrock Guardrails' synchronous mode raises accuracy but also raises TTFT, while asynchronous mode keeps TTFT low at the risk of emitting text that is later retracted. Decide this per workload by how costly a bad token is, as with human-in-the-loop approval steps.

How do you measure time to first token?

Track it as its own metric, not as a footnote to total duration. AWS recommends two:

When the two diverge, the gap is everything that is not the model: retrieval, prompt building, guardrails, network. That gap tells you whether a faster model would help at all. If pipeline TTFT is mostly pre-inference time, the better investments are narrower retrieval (see RAG hybrid search and reranking), parallel pre-checks and warm connections.

Report percentiles, not averages. A p50 that looks fine can hide a p95 that is the reason people complain, and the slow requests are often the ones with the longest prompts or the most tool calls.

What do the other levers cost you?

Latency fixes trade against other things, and some interact with work you may already have done:

Does the interaction type change the target?

Yes, and the target should be set per interaction rather than as one number:

InteractionWhat users tolerateWhere to focus
Chat or assistantA short wait, then visible streamingTTFT, streaming
Inline suggestion in an editor or formVery little; late is uselessSmall model, short output, caching
VoiceFar less than textEnd-to-end pipeline, interruption handling
Background job or batchNo user-facing TTFTThroughput and cost, not latency

AWS suggests anchoring targets to user research or published interaction norms instead of a round number, which is sound advice: ask a few real users what feels slow before engineering to a figure.

What to do next

Before you change a model or a prompt, do this in order:

  1. Add pipeline TTFT and model TTFT to your tracing, with p50 and p95.
  2. Look at the gap between them. If it is large, fix pre-inference work first.
  3. Turn on streaming for every user-facing path, and add a visible status for tool calls.
  4. Cap output length and trim any verbose structured-output syntax.
  5. Only then test a smaller model for the steps where quality allows, using an evaluation set.
  6. Re-measure after each change, under realistic load.

If you are building an AI product and want latency designed in rather than patched on after launch complaints, that is the kind of work our AI SaaS service covers.

Sources

CodeKrypt avatar

CodeKrypt

Drafted by CodeKrypt's AI writing pipeline, built and maintained by our engineers, under fixed rules on sources and claims. How we write

Frequently asked questions

What is time to first token (TTFT)?
It is the delay between a user's request and the first piece of output reaching them. For interactive AI features it is the main signal of how fast the product feels, because streaming lets the rest arrive while the user is already reading.
What reduces LLM latency the most?
Generating fewer output tokens. OpenAI's latency guide gives a heuristic that cutting 50% of output tokens may cut about 50% of latency, while cutting 50% of the prompt may only improve latency by 1-5%. For perceived speed, streaming matters most.
Will a faster model fix a slow AI feature?
Not always. A faster model improves total generation time, but if the delay is in retrieval, prompt assembly or serial pre-checks before the model is called, time to first token barely moves. Measure before swapping models.
Does prompt caching reduce latency?
It reduces the input tokens processed on repeat requests, which helps most with very large prompts. Since shortening input has a small effect on latency in typical prompts, treat caching as mainly a cost lever with some latency upside.

Related reading

Chat on WhatsApp