LLM inference, explained
LLM inference is running a trained large language model to turn a prompt into an answer, without changing the model. The text becomes tokens, the model reads them all at once in a step called prefill, then writes the answer one token at a time in a step called decode. Those two steps set its speed and its price.
A HIPS guide. Updated . Sources at the end.
What is LLM inference?
Inference is using a model; training is making one. During inference, a large language model's weights stay fixed: it reads your prompt and predicts the answer, token by token. Every chat reply, code suggestion and summary an LLM produces is inference.
An inference server is the software that runs it: it loads the weights onto GPUs, schedules incoming requests, and answers them through an API. vLLM and llama.cpp are two open-source examples.
How LLM inference works, step by step
1. Tokenize.The text is split into tokens, pieces of words the model knows by number. Each model has its own tokenizer, so the same text can be a different number of tokens on two models. Tokens are also what an API bills.
2. Prefill.The model reads every prompt token at once and computes, for each one, the keys and values its attention layers need. In NVIDIA's words, because "the full extent of the input is known, at a high level this is a matrix-matrix operation that’s highly parallelized. It effectively saturates GPU utilization."[1] Prefill ends with the first token of the answer.
3. Decode.The model writes the answer one token at a time. Each new token depends on every token before it, so the steps cannot run in parallel. NVIDIA: "The speed at which the data (weights, keys, values, activations) is transferred to the GPU from memory dominates the latency, not how fast the computation actually happens. In other words, this is a memory-bound operation."[1]
4. Keep the KV cache.So that decode does not recompute every earlier token at each step, the keys and values are kept in GPU memory and grow by one entry per token. NVIDIA gives the size per token as "2 * (num_layers) * (num_heads * dim_head) * precision_in_bytes", and for a 7-billion-parameter model with a 4,096-token request, "~2 GB."[1]
5. Sample and stop.At each step the model scores every possible next token, and a sampling rule (set by parameters such as temperature) picks one. Decoding stops at an end-of-answer token, a stop sequence or the maximum length you set.
6. Detokenize and stream.Tokens turn back into text. With streaming on, each piece is sent as soon as it is made, so the reader sees the answer grow.
Prefill and decode side by side
| Prefill and decode side by side | Prefill | Decode |
|---|---|---|
| What it does | Reads the whole prompt at once | Writes the answer, one token per step |
| What limits it | GPU compute | GPU memory bandwidth |
| What you notice | Time to first token | Time between tokens |
| What makes it longer | A longer prompt | A longer answer |
| How an API bills it | Input tokens | Output tokens |
NVIDIA's benchmarking guide ties the two to the metrics people measure: time to first token "generally includes request queuing time, prefill time, and network latency," and inter-token latency is "the average time between consecutive tokens."[2] The low-latency guide shows how to measure both.
Serving many requests at once
One request at a time leaves most of a GPU idle during decode. Servers fix that by batching:
- Batching decodes many requests in the same step. NVIDIA: "Since multiple requests use the same model, the memory cost of the weights is spread out."[1]
- Continuous batching (also called in-flight batching) swaps finished requests out and new ones in at every step, instead of waiting for the slowest answer in a batch. In NVIDIA's words, the runtime "immediately evicts finished sequences from the batch."[1]
- Paged KV cache. Each request's cache is stored in small blocks instead of one reserved stretch of memory, so less is wasted and more requests fit. The paper that introduced it, PagedAttention, reported "near-zero waste in KV cache memory."[3]
Batching raises total tokens per second across all users, but each user's answer can come slower as the batch grows. Every serving system picks a point on that trade-off.
What decides inference speed and cost
- Model size. Every decode step reads the weights, so more weights mean more to read. A mixture-of-experts model reads only some of them per token: gpt-oss-120b has "117B parameters with 5.1B active parameters", by its model card.[4]
- Precision. Fewer bits per weight means less memory to hold and less to read per step. NVIDIA: quantization means "you can transfer more parameters over the same amount of bandwidth, which can help to accelerate models that are bandwidth-limited."[1]
- Context length. A longer prompt means a longer prefill and a larger KV cache for every step after it.
- Answer length. Each output token is one more decode step.
- Concurrency. More requests per batch raise throughput and can slow each one.
One API request, step by step
Here is a request to an OpenAI-compatible API, with each part tied to a step above. This sample is from HIPS's Quickstart.
curl https://ai.hips.com/v1/chat/completions \
-H "Authorization: Bearer $HIPS_API_KEY" \
-H "Content-Type: application/json" \
-d "{\"model\":\"$HIPS_MODEL\",\"messages\":[{\"role\":\"user\",\"content\":\"Explain GPU inference in two sentences.\"}]}"messagesis the prompt. It is tokenized, with the model's chat template, and read in prefill.modelchooses the weights, and with them the tokenizer, the speed and the rates.- A maximum output length, if you set one, caps the number of decode steps.
stream: true, if you add it, sends tokens as decode makes them.- The answer's
usagecounts the prompt tokens (prefill) and the completion tokens (decode): the two numbers a per-token bill multiplies.
LLM inference on HIPS
HIPS runs inference for open models through one OpenAI-compatible API. One base URL, https://ai.hips.com/v1, and one API key reach DeepSeek, Kimi, Qwen, GLM, GPT-OSS and the rest of the catalog.
- Priced by the two steps. Input and output tokens are priced apart, per million tokens, per model. On HIPS's catalog of December 1, 2026, gpt-oss-120b cost $0.0294 per million input tokens and $0.147 per million output tokens in the Certified pool.
usageholds the token counts; the charge is in thex-hips-cost-microsheader, never inusage. - Streaming.
stream: truereturns server-sent events in OpenAI'schat.completion.chunkshape, thendata: [DONE]. - Prefill reused when it can be. Prompt caching is automatic, and writing to a cache costs nothing. A request's shared beginning, such as a long system prompt or a shared document, is kept in GPU memory only, reused by your workspace alone, and dropped after 30 minutes without use. No hit is promised.
- Decode that can wait. Batch jobs run as capacity becomes free, at half the on-demand rate of the same model; live requests always come first.
- Nothing kept. HIPS never trains on, retains or logs your prompt data.
LLM inference questions
What is LLM inference?
Running a trained large language model to produce an answer from a prompt. The model's weights do not change: it tokenizes the prompt, reads it in one parallel pass (prefill), then writes the answer one token at a time (decode).
What is an LLM inference server?
Software that loads a model onto GPUs, queues and batches incoming requests, runs prefill and decode, and returns answers through an API. vLLM and llama.cpp are open-source examples.
What is the KV cache?
The keys and values the model computed for every token so far, kept in GPU memory so that each new token does not recompute them. It grows with every token in every request being served, which is why long contexts need more GPU memory.
Why does the first token take longer than the rest?
Before the first token, the model must read the whole prompt (prefill), and the request may wait in a queue. After it, each token is one decode step. A long prompt therefore delays the start more than it slows the stream.
Is LLM inference done on GPUs?
Usually. Prefill needs a great deal of parallel compute and decode needs fast memory, and GPUs supply both. Small quantized models can also run on CPUs and laptops, more slowly.
Sources
- [1]
NVIDIA Technical Blog, "Mastering LLM Techniques: Inference Optimization", published November 17, 2023, updated 2025, read December 2, 2026.
developer.nvidia.com/blog/mastering-llm-techniques-inference-optimization/ - [2]
NVIDIA NIM Benchmarking documentation, "Metrics", read December 2, 2026.
docs.nvidia.com/nim/benchmarking/llm/latest/metrics.html - [3]
"Efficient Memory Management for Large Language Model Serving with PagedAttention", arXiv 2309.06180, submitted September 12, 2023, read December 2, 2026.
arxiv.org/abs/2309.06180 - [4]
Hugging Face, the openai/gpt-oss-120b model card, read December 2, 2026.
huggingface.co/openai/gpt-oss-120b HIPS: the Docs' Quickstart and Chat completions reference; the catalog of December 1, 2026.
Send your first inference request
Join early access. When your invitation comes, make a key, send one request and read its cost.