How to reduce LLM latency in production
To reduce LLM latency in production, stream responses so users see text immediately, cut the number of output tokens, keep prompts short and use prompt caching for repeated context, route simple requests to smaller, faster models, run independent calls in parallel, and cache repeated answers. Measure time to first token and total response time separately.
LLM features that feel slow get abandoned, however good the answers are. The good news is that most latency problems come from a handful of causes, and each has a well-understood fix. These are the techniques we apply when an AI feature needs to feel fast.
Where does LLM latency come from?
Total latency is roughly network time, plus queueing at the provider, plus time to process the input tokens, plus time to generate each output token. Output generation usually dominates, because tokens are produced one at a time, so the length of the response is often the biggest lever.
| Component | Driven by | Main fix |
|---|---|---|
| Time to first token | Prompt length, model size, provider load | Shorter prompts, prompt caching, smaller models |
| Generation time | Number of output tokens, model speed | Shorter outputs, faster models |
| Round trips | Sequential calls in chains and agents | Parallel calls, fewer steps |
| Retrieval | Vector search and reranking | Indexes, smaller top-k, caching |
| Network | Distance and new connections | Same-region hosting, connection reuse |
10 techniques that reduce LLM latency
1. Stream the response
Streaming does not make the model finish sooner, but it changes how fast the product feels: users start reading within a second instead of waiting for the full answer. For chat and writing features it is the single biggest perceived improvement, and every major provider supports it.
2. Generate fewer output tokens
Because output is generated token by token, halving the response roughly halves generation time. Ask for concise answers, set a sensible maximum token limit, and request compact structured output, such as a short JSON object, instead of explanations your code will throw away.
3. Shorten prompts and use prompt caching
Long prompts increase time to first token. Remove instructions the model doesn't need, retrieve only the most relevant documents, and put stable content, such as the system prompt, tool definitions and reference material, at the start of the prompt. Providers including Anthropic and OpenAI offer prompt caching, which reuses that repeated prefix and reduces both latency and cost.
4. Use the smallest model that meets the quality bar
Smaller models are faster and cheaper. Build an evaluation set from real requests, then test whether a smaller model handles them acceptably. Many tasks, such as classification, extraction and routing, don't need the largest model.
5. Route requests by difficulty
Send simple requests to a fast model and only complex ones to a larger model. A cheap classifier, or simple rules, can decide the route. Most traffic ends up on the fast path without lowering quality on hard requests.
6. Run independent calls in parallel
If a feature needs several model calls that don't depend on each other, such as summarising several documents or checking several criteria, run them concurrently. Total time becomes the slowest call rather than the sum of all of them.
7. Cache answers to repeated questions
Many products receive the same questions repeatedly. An exact-match cache on normalised inputs is safe and simple. Semantic caching, which reuses answers for similar questions, saves more but needs a careful similarity threshold so users never get an answer to a different question.
8. Reduce steps in agents and chains
Every model call in a chain adds a full round trip. Combine steps where one well-instructed call can do the work of several, let the model request multiple tool calls at once where the provider supports it, and cap the number of agent iterations.
9. Move non-urgent work out of the request
If the user doesn't need the result immediately, such as when generating reports, tagging documents or enriching records, do it in a background job and notify them when it's ready. Batch processing APIs are slower but cost less, which suits this kind of work.
10. Fix the plumbing
Host your backend in the same region as your model provider, reuse HTTP connections rather than opening a new one per request, set timeouts with a fallback model, and make sure retrieval queries hit proper vector indexes.
Which metrics should you track?
- Time to first token (TTFT) at the median and 95th percentile
- Total response time at the median and 95th percentile
- Input and output tokens per request
- Cache hit rate
- Error and timeout rate per model
Track the 95th percentile, not just the average. Users remember the slow requests, and long-tail latency often reveals oversized prompts or runaway agent loops.
A quick latency checklist
- 1Is the response streamed to the user?
- 2Is the output as short as it can be?
- 3Is repeated prompt content at the start and cached?
- 4Is this the smallest model that passes your evaluations?
- 5Are independent calls running in parallel?
- 6Are repeated questions served from cache?
- 7Could any of this run in the background instead?
Frequently asked questions
What is time to first token (TTFT)?
Time to first token is how long it takes from sending a request until the model returns its first piece of output. It is driven mainly by prompt length, model size and provider load, and it determines how responsive a streamed feature feels.
Does streaming make an LLM faster?
Streaming does not shorten the total generation time, but it lets users start reading immediately, which makes the feature feel much faster. For chat and writing features it is usually the most noticeable improvement.
What is prompt caching?
Prompt caching lets a model provider reuse the processing of a repeated prompt prefix, such as a long system prompt or reference document, across requests. It reduces time to first token and input costs for prompts that share the same beginning.
Is a smaller model always faster?
Generally, yes: smaller models generate tokens faster and start responding sooner. The trade-off is quality, so test smaller models against real examples before switching, and route only the requests they handle well.
Have a project in mind?
AHK Studios designs and builds custom software, AI and mobile products for modern businesses. Let's talk about yours.
Book a Free Consultation