Glossary
Inference
The stage where a trained AI model is run on new input to produce an output, such as an LLM generating a response to a prompt.
Inference is the process of running a trained AI model on new input to produce an output: a large language model answering a prompt, an embedding model turning text into a vector, or a speech model transcribing a recording. It is distinct from training, which sets the model’s weights; at inference the weights are fixed and the model only computes. For LLMs, inference happens in two phases, reading the input and then generating output one token at a time, and its cost and speed depend mostly on how many tokens go in and come out. Because inference runs on every request, it is where most of a production AI system’s ongoing cost sits.
Training and inference
Training is a one-off, very expensive process that adjusts billions of parameters until the model predicts its training data well. Fine-tuning is a smaller round of training on top. Inference uses the finished model. Nothing in the weights changes, which is why a deployed LLM does not learn from the conversations it serves; anything it should know on a given call has to be in the input.
The economics differ as well. Training is a capital cost paid by whoever builds the model. Inference is an operating cost paid by whoever uses it, request by request, and for an application with steady traffic it quickly becomes the larger number. Teams building on hosted models pay for inference through per-token prices; teams running their own models pay for it in GPU time.
Inference applies to every kind of model, from chat models to the small models around them. An embedding model performs inference each time it turns a query into a vector, a reranker performs inference when it scores candidate passages, and a speech model performs inference when it transcribes a call. A single agent request can trigger several of these before the main model writes a word: embed the question, search, rerank, then generate. Each step adds its own latency and cost, so the inference budget for a request is the sum of all of them, and the main model’s share is usually the largest.
How LLM inference works
LLM inference has two phases with different performance profiles.
Prefill. The model reads the whole input, every token of instructions, history, retrieved material and the user’s message, in one parallel pass through its transformer layers. Prefill is compute-heavy and fast per token, because the hardware processes many tokens at once. Its length mostly determines time to first token.
Decode. The model then generates output one token at a time. Each new token requires another pass, attending to everything before it. To avoid recomputing the whole sequence each time, the server keeps a KV cache of the attention keys and values from earlier tokens. Decode is limited by memory bandwidth rather than raw compute, so output tokens are slower and usually priced higher than input tokens. The split is covered in input vs output tokens.
Sampling settings decide which token is chosen at each step. Temperature and top-p control how much randomness is allowed, and max tokens caps the length of the response. Streaming responses send tokens to the client as they are generated, which does not make generation faster but makes the wait feel shorter.
What drives inference cost and latency
Factor | Effect on cost | Effect on latency |
|---|---|---|
Input tokens | Linear: every token is billed | Longer prefill, later first token |
Output tokens | Linear, usually at a higher rate | Each token adds decode time |
Model size | Larger models cost more per token | Larger models generate more slowly |
Reasoning tokens | Billed like output, often hidden | Can add seconds before the answer starts |
Concurrency and batching | Batching lowers cost per request | Queueing can raise latency at peak load |
Input tokens are the factor most teams underestimate. In a typical agent request the user’s message is around a hundred tokens, while the system prompt, conversation history and retrieved chunks add thousands more. Every one of those tokens is processed and billed on every call. As conversations grow, input per request grows with them, so the bill tracks the size of the context rather than the number of users. LLM latency follows the same pattern.
Reasoning models add a further cost. They spend extra tokens thinking before they answer, a trade known as test-time compute: more inference spent per question in exchange for higher accuracy on hard problems. For simple lookups the extra tokens buy little.
How inference is optimised
Optimisations fall into two groups: making each token cheaper to compute, and sending fewer tokens in the first place.
Making each token cheaper
Serving engines batch requests from many users onto the same GPU, reuse cached computation, and schedule work so the hardware stays busy. Model quantization stores weights at lower precision so a model needs less memory and runs faster, with a small loss in quality. Distillation trains a smaller model to imitate a larger one. Open weight models let teams apply these techniques themselves on their own hardware.
For work that does not need an immediate answer, batch inference processes many requests together at a discount, often within a few hours. Model routing sends easy requests to a small model and hard ones to a large model, frequently behind an LLM gateway that also handles retries, fallbacks and rate limiting.
Sending fewer tokens
Prompt caching lets a provider reuse the prefill for a repeated prefix, such as a long system prompt, at a reduced price. It helps only with the static part of the input; conversation history and retrieved material change on every request. A semantic cache goes further and skips inference entirely when a new question closely matches one already answered.
The largest savings usually come from context engineering: deciding what each call needs and leaving out the rest. Context compression shortens material that must be included. Replacing full conversation history with a handful of relevant remembered facts, and replacing generic top-K chunks with the specific passage that answers the question, cuts input tokens far more than any per-token discount. Because shorter, cleaner input also gives the model less noise to reason through, answer quality tends to rise rather than fall, and with it the number of retries needed.
A worked example
Consider a support agent running on a hosted model. Each request carries a system prompt of about 500 tokens, a conversation history that grows from a few hundred to 12,000 tokens over a long session, five retrieved chunks of about 500 tokens each, and a 100-token user message. A late-session request totals roughly 15,000 input tokens to produce a 300-token answer. Most of the bill is input, and most of that input does not help answer the latest question.
Caching the system prompt saves a few hundred tokens per call. Switching to a smaller model halves the price per token but struggles with the noisy context and needs more retries. Replacing the history with the few facts that matter and the five chunks with the one passage that contains the answer brings the request to under 3,000 tokens. The model, prompt and agent logic stay the same; only the context changes. That is the pattern behind most large inference savings.
Measuring inference in production
LLM observability tools record tokens in and out, latency per phase, cost per request and error rates. The most useful single metric is average input tokens per request over time: if it climbs steadily while traffic is flat, context is growing unchecked. Track time to first token and total response time separately, since they respond to different fixes. Watch for HTTP 429 errors as well, which signal that a provider’s rate limits are being hit and requests are being retried or dropped.
Embedding inference deserves its own line in the budget. Embedding models are small and cheap per call, but re-embedding a large corpus after a model change, or embedding every incoming document, can add up to a noticeable cost.
Where Exabase fits
Exabase does not run inference for your agent’s model, and it works with any model or framework. It reduces how many tokens each inference call needs by changing what goes into the context. Exabase Memory extracts durable facts from conversations, so an 8,000-token conversation can become about 50 tokens of structured facts, and retrieves only the memories relevant to the current query, at about 200ms for simple retrieval. Deep Search returns the sub-document passage that answers a question, with a precision setting per query, instead of a pile of loosely related chunks.
In an illustrative request, those two changes cut input from about 15,100 tokens to about 2,800, roughly 81 per cent fewer input tokens, and shorter, cleaner context also tends to shorten the output. The reduce token costs solution sets out the method, the token cost calculator estimates savings for your own traffic, and the retrieving memories guide shows the API calls. On the BEAM benchmark, Exabase’s M-1 engine uses about 20 per cent fewer tokens per query than the next-best memory system.
For more on the cost side, read how to cut token costs, your LLM bill is a retrieval problem and model routing is not a cost strategy on its own. Voice agents, where latency budgets are tight, show why small context matters, and the best AI agent infrastructure roundup places these tools alongside compute platforms such as those compared in Exabase vs Modal.
Frequently asked questions
What is the difference between training and inference?
Training sets a model’s weights by learning from data; inference uses those fixed weights to produce outputs for new inputs. Training happens once or occasionally, while inference happens on every request.
Why are output tokens more expensive than input tokens?
Because they are generated one at a time. Input tokens are processed together in a single parallel pass, while each output token needs its own pass through the model, which uses the hardware less efficiently.
What is inference latency?
It is the time between sending a request and receiving the response. For LLMs it is usually split into time to first token, driven mainly by input length, and the time to generate the rest, driven by output length and model speed.
Does prompt caching reduce inference cost?
Yes, for repeated prefixes such as a long system prompt. It does not help with conversation history or retrieved material that change on every call, which is often most of the input.
Is inference cheaper on a smaller model?
Per token, yes. Smaller models can handle noisy or long context less well, though, which can mean more retries or worse answers. Reducing the context often saves more than switching models.
How does Exabase reduce inference cost?
By shrinking the input. Exabase Memory and Deep Search replace full history and generic chunks with a few hundred relevant tokens, so each call to your model processes less. Your model, prompts and agent logic stay unchanged.
Related pages: LLM, token, KV cache, time to first token, batch inference, prompt caching, model routing, reduce token costs, token cost calculator, model quantization, Modal pricing