Latency (AI)

Latency in AI is the delay between sending a request to a model and getting a usable response, usually broken into time to first token and the rate at which the rest of the output arrives.

Also known as: Response time, time to first token (TTFT)

Related terms in this glossary

How it works

For language models, one latency number hides several parts:

  • Time to first token (TTFT): network time, queueing, and processing the full prompt. Long prompts raise it.
  • Inter-token latency, or output tokens per second: how fast the reply streams once it starts. Larger models are usually slower.
  • End-to-end time: the whole request, including retrieval, tool calls, guardrail checks and any reasoning tokens generated before the answer.

An agent that makes five sequential model calls and three tool calls adds all of them up, which is why agents often feel slower than chat. Measure percentiles such as p50 and p95, not averages, since slow outliers are what users remember.

Why it matters

Latency tolerance depends on the use case. A nightly document batch can take minutes. A chat reply should start streaming within a second or two. Voice agents are the strictest: conversation research by Stivers and colleagues (PNAS, 2009) found typical gaps between speaker turns of around 200 milliseconds across languages, so pipelines chaining speech recognition, a model and speech synthesis must be tightly tuned to feel natural. Ways to cut latency include:

  • Stream output so users see progress.
  • Use smaller or faster models for simple steps.
  • Shorten prompts and use prompt caching.
  • Run independent tool calls in parallel.
  • Host models in a region close to users.

Each has a cost or quality trade-off, so test with evals. See AI cost optimization and voice AI agents.

Latency (AI) in depth

Building a latency budget

Treat latency like money: decide the total you can spend, then allocate it across the steps. For an interactive feature, write down the target, such as the first visible output within a set time at p95, and break the request into stages. Measure each stage separately with tracing, so you know where the time goes before you optimize anything.

Example: a voice agent pipeline

Example: a hypothetical clinic's phone agent books appointments in Hindi and English. One caller turn passes through:

  1. Voice activity detection decides the caller has stopped speaking.
  2. Speech-to-text produces a transcript, ideally streaming partial results.
  3. The language model decides the reply, possibly calling the calendar tool.
  4. Text-to-speech starts speaking the first sentence while the rest is still generating.

Tracing shows that the calendar lookup, done sequentially after the model's first call, dominates. The fix is to prefetch the next available slots when the caller's intent becomes clear, and to have the agent say a short acknowledgment while the lookup runs. Each change is checked against the evaluation set so faster does not mean wronger.

Levers and their trade-offs

LeverEffectTrade-off
StreamingLower perceived waitHarder to apply output guardrails to partial text
Smaller model or routingFaster decode, lower costPossible quality loss on hard cases
Prompt cachingLower time to first token on long, stable promptsOnly helps when prefixes repeat
Shorter prompts and contextFaster prefillRisk of dropping needed context
Parallel tool callsShorter agent runsMore complex error handling
Lower reasoning effortFewer hidden tokens before answeringWeaker multi-step reasoning
Regional hostingLess network timeModel availability varies by region

Measuring latency properly

  • Record time to first token, output tokens per second and end-to-end duration on every request.
  • Report p50, p95 and p99, sliced by model, route and prompt size.
  • Measure from the user's side as well as the server's: mobile networks in tier-2 and tier-3 cities add real delay.
  • Load-test at production-like concurrency; hosted APIs and self-hosted servers both slow down under load.

For self-hosted models, latency is tied to inference settings such as batch size and quantization, which trade throughput against per-request speed.

Set different targets for different routes. A background summarization job, an internal search box and a customer-facing voice line deserve different budgets, and treating them alike either wastes money on speed nobody notices or leaves the strict routes too slow. Write the targets into the service's SLOs so regressions are caught.

Common mistakes

  • Optimizing the model call when retrieval or a slow internal API is the real bottleneck.
  • Reporting averages that hide a long tail of very slow requests.
  • Turning on long reasoning by default for tasks that do not need it.
  • Testing from an office connection only.

Latency, cost and quality are linked, so tune them together. Our model comparison tool helps shortlist options. We work on this in AI cost optimization and voice AI agents.

Questions about Latency (AI)

Something else? Send us your question and an engineer replies with next steps.

Why does the same AI request sometimes take much longer than usual?

Several causes are common. Hosted model providers queue requests during busy periods, so time to first token varies by time of day. The model may generate more output or more hidden reasoning tokens for some inputs. Retrieval or tool calls inside the request can hit slow databases or rate limits, and retries add time. Long prompts take longer to process. Tracing each stage of the request shows which one varies, and percentile reporting reveals how often the slow cases happen.

Is self-hosting a model faster than calling a hosted API?

Not automatically. Self-hosting removes some network distance and provider queueing, and gives you control over hardware and batching, so it can be faster for steady, predictable traffic. But a small model on a modest GPU may be slower than a large provider's optimized fleet, and under load your own server will queue requests too. Speed depends on model size, GPU type, serving engine and concurrency. Benchmark both options on your real prompts and traffic pattern before deciding.

Jump to

↑↓ to move↵ to open