LLM Inference Explained: Why AI Answers Take Time, What They Cost, and How to Make Them Faster

· 15 min read

Every time someone types a question into ChatGPT, Claude, Gemini, or an AI feature inside your own product, a lot happens in the second or two before the first word appears. A data center somewhere loads your text, breaks it into tokens, runs it through a model with billions of parameters, and then generates the answer one small piece at a time. That process is called LLM inference, and it quietly decides three things every business cares about: how fast an AI answer feels, how much it costs, and how reliable it is at scale.

For U.S. B2B SaaS teams, inference is no longer an engineering footnote. If you ship AI features, inference is a line item on your cloud bill and a factor in whether users stay or churn. If you sell to buyers who research with AI assistants, inference economics shape how much effort those assistants spend on each answer, including how many sources they read before recommending a vendor.

This guide explains inference in plain English: what happens between the prompt and the answer, why responses stream word by word, what drives latency and cost, the main techniques providers use to make models faster and cheaper, and what all of it means for your product and your AI visibility. If you are new to the basics, start with our practical guide to what an LLM is and our explainer on tokens and context windows.

Published November 26, 2026. This is an educational explainer for U.S. B2B SaaS teams. Model prices, speeds, and features change frequently, so check current provider documentation before making decisions. Numbers and company situations in examples are illustrative unless a source is named.

The Short Answer: Training Builds the Model, Inference Uses It

A large language model has two very different lives.

Training is the expensive, one-time-per-version process of building the model. Engineers feed it enormous amounts of text and adjust its internal numbers, called weights, until it gets good at predicting the next token. Our guide on how LLMs are trained covers that stage.

Inference is everything that happens afterward: every time anyone asks the finished model a question. The weights stay fixed. The model simply reads the input and produces output.

Training happens occasionally. Inference happens billions of times a day. That is why, for most companies that use AI rather than build foundation models, inference is the cost that actually shows up on the invoice.

What Happens Between Your Prompt and the Answer

Here is the journey of a single request, simplified.

  1. The application assembles the input. Your message rarely travels alone. The product adds system instructions, earlier conversation turns, perhaps saved memory, retrieved documents, or web search results. Our guide to LLM memory explains how much hidden text can be included.
  2. The text is tokenized. The input is split into tokens, small chunks of words. A typical English word is roughly one to two tokens.
  3. The prefill stage runs. The model processes all input tokens at once and builds an internal summary of them. This is computationally heavy but highly parallel, so modern chips handle it efficiently.
  4. The decode stage begins. The model generates the first output token, adds it to the sequence, then generates the next one, and the next. Each new token depends on all the tokens before it.
  5. Sampling picks each token. At every step the model produces probabilities for possible next tokens, and settings like temperature decide which one is chosen. Our explainer on temperature and sampling covers why the same prompt can produce different answers.
  6. The answer streams back. Most products send tokens to your screen as they are generated, which is why answers appear to type themselves.
  7. The request ends when the model produces a stop token or hits a maximum length.

Two stages matter most for performance: prefill, which reads your input, and decode, which writes the answer. They behave differently, and almost every speed and cost decision traces back to that difference.

Why AI Answers Appear Word by Word

The typing effect is not a design trick. It reflects how the model actually works.

Language models are autoregressive: they generate one token at a time, and each token is fed back in before the next is produced. The model cannot write the tenth word until it has written the ninth. That sequential dependency is the main reason decode is slow relative to prefill.

Streaming exists because waiting for a complete 600-word answer before showing anything would feel broken. By sending tokens as they arrive, products let users start reading within a second or two, even if the full response takes much longer.

For product teams, this distinction leads to two separate speed metrics.

The Two Latency Numbers That Matter

Time to first token (TTFT) is how long the user waits before anything appears. It is mostly driven by queueing, network time, and prefill. Long inputs, such as a big document or a lengthy conversation history, increase TTFT because the model must read everything first.

Output speed, often measured in tokens per second, is how fast the answer flows once it starts. It is mostly driven by decode efficiency, the model's size, and how busy the provider's hardware is.

A third number combines them: total response time, roughly TTFT plus the number of output tokens divided by output speed. An answer of 500 tokens at 50 tokens per second takes about 10 seconds after the first token. The same answer at 150 tokens per second takes about three.

Different features care about different numbers:

What Actually Drives Inference Cost

Most commercial APIs price by tokens, usually quoting separate rates for input and output, per million tokens. Output tokens typically cost several times more than input tokens, which matches the physics: input is processed in parallel during prefill, while output is generated slowly, one token at a time.

The main cost drivers are:

Here is an illustrative example. Suppose a support feature sends 6,000 input tokens (instructions plus retrieved help articles) and receives 400 output tokens per question. At 100,000 questions a month, that is 600 million input tokens and 40 million output tokens. Even modest per-token prices add up, and the input side dominates. Cutting the retrieved context in half could save more than switching to a slightly cheaper model. The specific prices depend on your provider, but the arithmetic pattern is common.

Why Long Prompts Slow Things Down

Long inputs affect inference in two ways.

First, prefill takes longer, which raises time to first token. Attention, the mechanism that lets each token consider every other token, becomes more expensive as inputs grow. Research such as FlashAttention by Dao and colleagues made attention far more efficient on GPUs, which is one reason long context windows became practical, but long inputs still cost more than short ones.

Second, the model must keep information about every previous token in memory while generating. That memory is called the KV cache (key-value cache). It lets the model avoid recomputing the whole input for each new token, which is essential for speed, but it consumes GPU memory in proportion to the length of the conversation. Long contexts mean bigger caches, which means fewer users can share the same hardware at once.

Quality matters too. More context is not automatically better. Models can overlook details buried in long inputs, and irrelevant material can distract them. Sending only the most relevant passages is usually faster, cheaper, and more accurate.

How Providers Make Inference Faster and Cheaper

AI providers and open-source projects have developed several techniques that shape the speed and price you see. You do not need to implement them, but knowing they exist helps you read pricing pages and make sensible choices.

Batching

GPUs are most efficient when they process many requests together. Providers group requests from many users into batches. Continuous batching lets new requests join and finished ones leave mid-flight rather than waiting for a whole batch to complete. This is a major reason shared APIs are affordable, and also why response speed can vary at busy times.

Smarter Memory Management

Managing the KV cache well lets more requests fit on each GPU. The vLLM project introduced PagedAttention (Kwon and colleagues), which stores the cache in small blocks, similar to how operating systems manage memory, reducing waste and increasing throughput.

Prompt Caching

Many requests start with the same text: identical system instructions, the same product documentation, the same long policy. Prompt caching lets providers reuse the processing of a repeated prefix instead of recomputing it. OpenAI documents automatic prompt caching for eligible requests, and Anthropic offers prompt caching that developers mark explicitly. Cached input is typically cheaper and faster. The practical rule: put stable content first and variable content, like the user's question, last.

Quantization

Quantization stores model weights with fewer bits, for example 8-bit or 4-bit numbers instead of 16-bit. The model takes less memory and often runs faster, with a usually small and sometimes noticeable loss in quality. It is common when running open-weight models on your own hardware.

Speculative Decoding

Because decode is sequential, providers look for ways to produce several tokens per step. In speculative decoding (Leviathan, Kalman, and Matias), a small, fast model drafts several tokens ahead and the large model checks them in one pass, accepting the ones it agrees with. When drafts are good, output speeds up without changing the large model's results.

Distillation and Smaller Models

Providers also train smaller models to imitate larger ones. These distilled models power many fast, inexpensive tiers. For narrow tasks such as classification, extraction, or routing, they often perform close to frontier models at a fraction of the cost.

Batch APIs

For work that does not need an immediate answer, some providers offer asynchronous batch processing at a discount. OpenAI's Batch API, for example, processes requests within a completion window at reduced cost. Nightly enrichment, bulk summarization, and evaluation runs are good candidates.

Hosted APIs vs. Running Models Yourself

B2B SaaS teams usually choose between three options.

Hosted proprietary APIs from OpenAI, Anthropic, Google, and others are the fastest way to start. You pay per token, the provider handles hardware, and you get the newest models. The tradeoff is less control over latency, data location, and pricing changes.

Hosted open-weight models through cloud platforms or inference providers offer more choice and sometimes lower prices, with similar convenience.

Self-hosting on your own GPUs, using serving software such as vLLM, gives maximum control over data and customization. It also makes you responsible for capacity planning, utilization, upgrades, and on-call. GPUs that sit idle still cost money, so self-hosting tends to pay off only at steady, high volume or when data requirements demand it. Our guide to running an LLM locally is a useful starting point for experiments.

A sensible default for most SaaS teams is to start with hosted APIs, measure real usage for a few months, and revisit the decision with actual numbers rather than projections.

Practical Ways to Cut Latency and Cost in Your Product

These steps help almost any AI feature, regardless of provider.

Common Misconceptions About Inference

"A bigger model is always slower." Usually, but not always. A well-optimized large model on strong hardware can outrun a poorly served small one. Measure the actual endpoint.

"Temperature zero means identical answers." Not reliably. Batching, hardware differences, and provider updates can still change outputs.

"Inference cost only depends on the price per token." The number of tokens usually matters more. Bloated prompts and long answers often cost more than a slightly more expensive model.

"Faster means lower quality." Techniques like speculative decoding and caching are designed to preserve output. Quantization and smaller models can affect quality, so test them.

"Prompt length doesn't matter now that context windows are huge." Long contexts are allowed, not free. They add cost and latency, and can reduce accuracy.

What Inference Economics Mean for AI Search and Brand Visibility

Inference is not only a product engineering concern. It shapes how AI engines research and recommend vendors.

When an AI assistant answers a buyer's question with web search, every source it reads becomes input tokens it must pay to process. Providers therefore design retrieval to be selective. Assistants typically read a limited number of pages, often only parts of them, and favor content that answers the question quickly and clearly. That has three practical implications for B2B SaaS brands.

Clear, direct pages are cheaper to use. A page that states who the product serves, what it costs, which integrations it supports, and what security standards it meets, in plain sentences near the top, is easier for retrieval systems to extract and quote. Our guide on structuring a website for LLM crawlers covers this in detail.

Not every answer involves fresh research. To manage cost and speed, many answers rely partly on training knowledge rather than live search. That knowledge has a cutoff, so outdated facts about your product can persist. See our explainer on knowledge cutoffs.

Different modes give different answers. A quick chat answer, a search-grounded answer, and a deep research report spend very different amounts of inference. The vendor list a buyer sees can differ by mode. When you measure AI visibility, record the engine, the mode, the date, the exact prompt, and the verbatim answer so comparisons are fair. Our guide on how to track LLM recommendations explains a repeatable method.

The takeaway is not to write for machines instead of people. It is to make accurate, specific information easy to find, because AI systems working under cost and time limits will use the clearest sources they can reach.

A 30/60-Day Plan for SaaS Teams

Days 1 to 30: measure.

Days 31 to 60: optimize and verify.

Teams that follow a plan like this often find meaningful savings from input trimming and model routing alone, though results depend on your workload, so measure before and after rather than assuming.

The Bottom Line

LLM inference is the moment a trained model actually does work, and it turns technical details into business outcomes: the wait your users feel, the bill your finance team sees, and the depth of research an AI assistant performs before naming vendors. Understand the two stages, prefill and decode, watch input and output tokens, choose the smallest model that does the job well, and make your public information easy for cost-conscious AI systems to use.

If you want to know how AI engines currently describe your SaaS brand and which sources they rely on, book a strategy call with LLM Recommend. For related reading, see our guides on prompt engineering, LLM hallucinations, and LLM security and privacy.

Frequently Asked Questions

What is LLM inference?

Inference is the process of using a trained language model to produce an answer. The model's weights stay fixed; it reads the input tokens and generates output tokens one at a time. Training builds the model, inference runs it every time someone asks a question.

Why do AI chatbots show answers word by word?

Language models generate one token at a time, and each new token depends on the ones before it. Products stream tokens as they are produced so users can start reading quickly instead of waiting for the full answer.

What is time to first token?

Time to first token is how long a user waits before the first part of the answer appears. It is driven mainly by queueing, network time, and the prefill stage, so long inputs usually increase it.

Why do output tokens cost more than input tokens?

Input tokens are processed in parallel during prefill, while output tokens are generated sequentially, one step at a time. Generation uses more hardware time per token, so providers usually price output higher.

How can a SaaS company reduce LLM inference costs?

Route simple tasks to smaller models, trim retrieved context and conversation history, place stable content first so prompt caching can apply, cap output and reasoning length, use batch processing for offline work, and set explicit retry and tool-call limits.

Does inference cost affect which brands AI assistants recommend?

Indirectly. Search-grounded assistants read a limited number of sources to control cost and speed, and many answers rely partly on training knowledge. Clear, specific, current public pages are easier for these systems to find and use.