How LLM serving worksLesson 1 of 9
How an Answer Is Built One Token at a Time
An LLM does not write its answer all at once. It turns the question into tokens (the text pieces a model reads), picks one next token, appends it, and computes again, repeating until the answer is done. That is why chat answers appear as if someone were typing.
Input tokens—
Generated tokens0
Answer received—
RequestResponse / reportAppears in a later step
What you will learn
- The model reads token IDs, not characters
- The model outputs a probability table for the next token
- Generation is a loop: pick a token, append it, compute again
- Why longer answers cost more time and money
- When generation stops
Running it on Kubernetes
- Inference servers such as vLLM and KServe usually expose this process through an OpenAI-compatible API (
/v1/chat/completionsand similar). Withstream: true, tokens arrive over SSE as they are generated. - If streamed tokens arrive in bursts or the stream breaks midway, check the Ingress or gateway in front first. Response buffering, or a read timeout shorter than a long answer, causes exactly this.
- vLLM exposes cumulative input tokens (
vllm:prompt_tokens_total) and output tokens (vllm:generation_tokens_total) on/metrics. Comparing their rates shows whether load comes from long prompts or long answers. - When users report answers cut off mid-sentence, check the client’s
max_tokensand the server’s maximum context length first.
Try it yourself
curl -s http://<engine>:8000/v1/models # Served model name, e.g. vLLM
curl -sN http://<engine>:8000/v1/completions -H 'Content-Type: application/json' -d '{"model":"<model>","prompt":"What is Kubernetes?","max_tokens":50,"stream":true}' # One token per SSE event (step 6)
curl -sN http://<engine>:8000/v1/completions -H 'Content-Type: application/json' -d '{"model":"<model>","prompt":"What is Kubernetes?","max_tokens":5}' | grep -o '"finish_reason":"[a-z]*"' # "length": cut by max_tokens (step 8)
curl -s http://<engine>:8000/metrics | grep -E 'vllm:(prompt|generation)_tokens_total' # Input vs output tokens so far
Check yourself
Further reading: vLLM documentation · KServe documentation