Skip to content
AI engineeringBeginner8 min

The life of an LLM request

Follow one chat message from the browser, through the gateway and retrieval, into the model, and back as a stream of tokens.

Sign in to save this lesson

You will learn to

  • Name each hop an LLM request makes and what happens there.
  • Explain the difference between prefill and decode.
  • Explain why time to first token and total time are different numbers.

Before you start: You know what an HTTP request is.

Think of it like

Ordering at a busy restaurant. The host checks your booking (gateway), the waiter fetches your notes from last visit (retrieval), the chef reads the whole order before cooking anything (prefill), then sends dishes out one at a time as each is ready (decode and streaming).

Explanation depth
Diagram: The user presses sendA browser sends a prompt to an API gateway, which passes it to an application server. The server fetches context from a vector database, sends the prompt and context to an LLM, and streams the answer back through the gateway to the browser.BrowserAPI gatewayApp serverVector DBLLM↓ promptsearchprompt

Step 1 of 7

The user presses send

The browser packages the message into a request and sends it over the internet. Nothing clever has happened yet: this is a normal web request.

Try it: Where does the time go?

Change the inputs and watch where the time goes. The default values are illustrative, not measurements of any particular model or provider.

80 ms

Browser to your backend and back, plus backend to the model provider.

5 ms

Authentication, rate limiting and validation.

120 ms

Embedding the query and searching the index. Zero if the app has no retrieval.

3,000 tokens

System prompt, history, retrieved context and the question.

10,000 tokens/s

How fast the model reads the prompt. Illustrative; depends on model and hardware.

300 tokens

Tokens the model generates.

50 tokens/s

Tokens per second for this one request while it streams. Illustrative.

Prefill
300 ms
3000 tokens ÷ 10000 tokens/s = 300 ms
Time to first token
505 ms
80 + 5 + 120 + 300 = 505 ms
Decode
5,980 ms
(300 − 1) tokens × 20 ms = 5980 ms
Full answer
6,485 ms
505 + 5980 = 6485 ms
Share spent decoding
92.2 %
5980 ÷ 6485 × 100

Assumptions

  • Stages run one after another; nothing overlaps.
  • Prefill and decode speeds are constant for the whole request.
  • No queueing at the provider and no retries.
  • Speeds are illustrative inputs, not measurements of any particular model.

Key takeaways

  • An LLM request is a normal web request plus two model phases: prefill (read the prompt) and decode (write the answer).
  • Time to first token depends on everything before decode, including retrieval and prompt length.
  • Total time is usually dominated by decode, which grows with the length of the answer.
  • Streaming does not make the answer faster; it makes the wait visible and useful.

The parts

Browser:
The chat UI. It sends the user's message and renders tokens as they arrive.
API gateway:
Checks who is calling, applies rate limits and budgets, and forwards the request.
App server:
Builds the prompt: system instructions, retrieved context and the user's message.
Vector DB:
Finds document chunks whose meaning is close to the question.
LLM:
Reads the prompt, then generates the answer one token at a time.

Check your understanding

  1. 1. Your retrieval step returns twice as many chunks as before. Which number gets worse first?
  2. 2. Why are output tokens produced one after another rather than all at once?
  3. 3. What does streaming the answer improve?

Finish every step and answer the checks to complete this lesson.

Further reading

Recommended next