# Latency

> The Latency of an AI model is the time it takes to receive a response, often measured as time to first token.

## How do I reduce LLM response latency?

The response time of a model, usually split into time to first token and generation speed in tokens per second. Affected by model size, prompt length and reasoning effort, and improved with streaming, caching and smaller models.

- Topic: Quality & Operations
- Type: concept

## Example

Wrong:

```js
const res = await fetch(url, { method: 'POST', body });
const { text } = await res.json();
render(text);
```

Right:

```js
const res = await fetch(url, { method: 'POST', body: streamBody });
const reader = res.body.pipeThrough(new TextDecoderStream()).getReader();
while (true) {
  const { value, done } = await reader.read();
  if (done) break;
  appendChunk(value);
}
```

Streaming shows text as soon as the first tokens arrive, so users do not wait for the whole answer to finish.

## Common mistakes

- Using a large reasoning model for simple tasks where a smaller, faster model is enough.

## Key points

- Responses are streamed, so users see the first tokens instead of waiting for the full answer.
- Independent model calls run in parallel, not one after another.
- Time to first token and total time are measured separately.

## Interview questions

### What is time to first token?

It is the time from sending a request until the first token of the response arrives. It is what users feel most in chat interfaces.

### Does a longer prompt increase latency?

Yes, longer prompts take more time to process before the first token. Prompt caching can reduce this for repeated prefixes.

### Does streaming make the model faster?

No, total generation time stays about the same. Streaming improves perceived speed because users can start reading right away.

## Related cards

- [Streaming](https://wonderium.dev/ai/streaming.md)
- [Prompt Caching](https://wonderium.dev/ai/prompt-caching.md)
- [Model Routing](https://wonderium.dev/ai/model-routing.md)
- [Small Language Model](https://wonderium.dev/ai/small-language-model.md)
- [TTFB](https://wonderium.dev/web/ttfb.md)

---

- Level: [Artificial Intelligence](https://wonderium.dev/ai.md)
- HTML version: https://wonderium.dev/ai/latency
- Last updated: 2026-11-25
