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 lessonYou 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).
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.
Browser to your backend and back, plus backend to the model provider.
Authentication, rate limiting and validation.
Embedding the query and searching the index. Zero if the app has no retrieval.
System prompt, history, retrieved context and the question.
How fast the model reads the prompt. Illustrative; depends on model and hardware.
Tokens the model generates.
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
Finish every step and answer the checks to complete this lesson.