AI

Making LLMs fast and affordable in production

Making LLMs fast and affordable in production

A language model reads your prompt in one fast pass and writes its answer one slow token at a time. Caching, shorter answers, routing, batching, quantization and speculative decoding each attack one side of that split.

Two speeds in every request

Give a language model a two-page prompt and it reads all of it in a fraction of a second. Then it takes several more seconds to write a reply shorter than the prompt. That gap explains most of what makes LLM features slow or expensive, and almost every optimization we use in production attacks one side of it.

A request runs in two phases. In prefill, the model takes in the whole prompt at once. All the prompt tokens go through the network together, which keeps the GPU's arithmetic units busy, and the pass ends with the first token of the answer. In decode, the model writes the rest one token at a time. Each new token needs another full pass through the model, and each pass reads every weight from GPU memory to produce that single token. Prefill is limited by compute. Decode is limited by memory bandwidth.1

One request, two speeds. Prefill reads the 2,048-token prompt in a single pass and produces the first token. Decode then needs a full pass over all the weights for every further token. The 8B model is an example and the timeline widths are illustrative.

So there are two latency numbers, not one. Time to first token is how long the user waits before anything appears, and it grows with the prompt. Time per output token is how fast the answer arrives after that. Total time is roughly the first plus the second multiplied by the number of tokens written.1 When engineers at Databricks measured this, adding 512 input tokens increased latency less than generating 8 more output tokens.1 If a reply feels slow, look at the length of the answer before the length of the prompt.

Providers price the same imbalance. Across the current lineups from Anthropic, OpenAI and Google, an output token costs five to eight times as much as an input token.2,3,4

USD per million tokens · log scaleinput output
gpt-6-astraOpenAI
$10$50
5×
Claude Opus 5.5Anthropic
$4$20
5×
Gemini 3.1 Pro PreviewGoogle
$2$12
6×
Gemini 3.5 Flash-LiteGoogle
$0.30$2.50
8.3×
Claude Haiku 5.5Anthropic
$0.10$0.50
5×
gpt-6-lunaOpenAI
$0.10$0.50
5×
List prices per million tokens
ModelInputOutput
gpt-6-astra$10$50
Claude Opus 5.5$4$20
Gemini 3.1 Pro Preview$2$12
Gemini 3.5 Flash-Lite$0.30$2.50
Claude Haiku 5.5$0.10$0.50
gpt-6-luna$0.10$0.50
List prices per million tokens for a large and a small model from each provider: standard tier, short prompts, as published on 9 November 2026. Prices change often, so check the pricing pages before you plan a budget.

Two things in that chart shape the rest of this post. The dumbbells are all about the same length, so the output premium is close to an industry constant. And the rows span a range of more than a hundred, so which model you call matters more than almost any other setting.

There is one twist. Most product prompts are long: instructions, tool definitions, retrieved documents, chat history. A support assistant that sends 9,600 tokens of instructions and product docs and gets a 300-token reply sends 32 input tokens for every output token. At Claude Sonnet 5.5's list prices, input is almost nine tenths of that bill.2 So the working rule is simple: input tokens set the bill, output tokens set the wait.

Never pay twice for the same prompt

During prefill the model turns every prompt token into keys and values, the intermediate results that attention looks back at. They stay in GPU memory as the KV cache, so decode never has to redo the prompt. Prompt caching keeps that work after the request ends. If the next request starts with exactly the same tokens, the server skips prefill for that part.

The savings are large. On Anthropic's API, reading from the cache costs a tenth of the normal input price on most models and a twentieth on Claude Sonnet 5.5 and Opus 5.5. Writing an entry that lives for five minutes costs 1.25 times the normal price.2,5 When Anthropic launched the feature, a chat over a 100,000-token book went from 11.5 seconds to first token to 2.4 seconds, at 90 percent lower cost.6 OpenAI caches long prompts automatically,7 and self-hosted servers such as vLLM do the same with automatic prefix caching.8

The catch is the word "starts". The cache matches from the first token forward, and the first difference ends the match. Anthropic's documentation puts it plainly: a hit needs 100 percent identical prompt segments up to the cache breakpoint.5 One timestamp at the top of a system prompt makes every request look new.

Earlier requeststored in cache
This requestmatched from the first token
system3,600docs6,000newQ2
Earlier requeststored in cache
This requestmatched from the first token
time10:04system3,600docs6,000newQ2
read from cachefirst differenceprefilled again
Tokens to prefill60
Input cost, 100k requests$108
Two layouts of the same 9,660-token prompt. The cache matches from the first token and stops at the first difference. Token counts are illustrative; costs use Claude Sonnet 5.5 list prices ($2 per million input tokens, $0.10 per million read from cache). Tap a layout to compare.

So we treat prompt order as an engineering decision. Things that never change go first: instructions, tool definitions, reference documents, examples. Things that change go last: the date, the user's name, retrieved snippets, the new question. OpenAI's guide gives the same advice.7 Settings count too. On Claude, changing the thinking effort between turns of a conversation invalidates the cached messages.9 Every response reports how many input tokens came from the cache, and we watch that number the way we watch an error rate. A harmless-looking prompt edit can quietly turn a 95 percent discount into nothing.

The fastest token is the one you never write

Every output token costs a full pass through the model, so the cheapest optimization is writing fewer of them. Most products can cut a lot without anyone noticing.

  • Ask for structure, not prose. A classifier should return a label, not a paragraph explaining it. An extraction step should return the fields you need and nothing else.
  • Set a ceiling. A maximum output length caps the worst case, so one runaway answer can't hold a request open for a minute.
  • Watch the tokens you don't see. Reasoning models think before they answer, and that thinking is billed as output, even when the API only shows you a summary.9 Set the reasoning effort per feature: checking an order status doesn't need the depth of a contract review.

Some of the wait can't be removed. A long answer still takes seconds to write. Streaming doesn't make it faster, but it changes what the user lives through. Jakob Nielsen's limits from 1993 still hold: about one second keeps a person's train of thought, and about ten seconds is as long as attention lasts.10 A streamed answer starts well inside the first limit. A buffered one can easily cross the second.

time since send0.0 s
SupportDemo shop
Can I return a jacket I bought in the sale?
Yes. Sale items can be returned within 15 days if the tags are still on. Open Orders, pick the jacket and tap Return. Your refund lands 5 to 7 working days after pickup.
Message
Bufferedwaits for the whole answerfirst words at –
SupportDemo shop
Can I return a jacket I bought in the sale?
Yes. Sale items can be returned within 15 days if the tags are still on. Open Orders, pick the jacket and tap Return. Your refund lands 5 to 7 working days after pickup.
Message
Streamedshows tokens as they arrivefirst words at –
Same model, same answer, same six seconds. The buffered screen shows nothing until 6.0 s; the streamed one starts at 0.6 s. Illustrative timing and a fictional shop.

Streaming has a cost on the product side. The interface has to render partial text, cope with a stream that dies halfway, and hold back anything that must be checked before it is shown. Our usual pattern is to stream the words and validate the actions: text appears as it is written, but a refund button or a database write appears only after the complete, structured answer has passed its checks.

Send easy questions to small models

Look at the price chart again. Within one provider, the small model costs between a fifth and a hundredth of the large one. And most real traffic is not hard. Order status, opening hours and "how do I reset my password" do not need the most capable model on the market.

There are two common patterns. A router looks at each request and picks a model before answering. A cascade tries the cheap model first and escalates only when its answer fails a check. The research results are encouraging. FrugalGPT matched GPT-4's performance at up to 98 percent lower cost on its benchmarks by cascading models.11 RouteLLM trained routers on human preference data and cut costs by more than half in some settings without hurting response quality.12

The hard part is the check. A good one is cheap and boring: does the output parse, does it pass the business rules, does it cite the retrieved sources, did the user ask the same thing again a moment later. None of this works without an evaluation set built from real requests. Without one, routing is a guess, and the savings show up long before the complaints do.

Two more price levers are worth knowing. Work nobody is waiting for, such as nightly summaries, tagging a backlog or re-indexing documents, can go through the batch APIs that Anthropic, OpenAI and Google all offer at half price, in exchange for results that arrive later.2,3,4 And speed itself is now for sale: Anthropic's fast mode for Claude Opus 5.5 costs twice the normal rate for significantly faster output.2 Latency has become a line item you choose.

Share every pass through the model

Everything so far works with any API. The next ideas are what inference providers do behind those prices, and what you need if you host open models on your own GPUs.

Remember that a decode pass reads every weight to write one token. If thirty-two users are each halfway through an answer, the server can run one pass that writes one token for each of them, reading the weights once instead of thirty-two times. This is batching, and it is where most of a server's throughput comes from.1

The simple version, static batching, groups requests and runs the group until its longest answer is done. Short answers finish early and their slots sit empty. Orca, a research system from 2022, scheduled work per iteration instead: after every pass, finished requests leave and waiting ones take their place. On GPT-3 175B its authors measured 36.9 times the throughput of NVIDIA FasterTransformer at the same latency.13 The idea is now called continuous batching, and the major open-source inference servers use it.

WaitingABCDEFGH
pass 0
Static batching· a batch holds its slots until its longest request ends
AAAAAAAABBCCCDDDDDDEEFFFFFGGHHH
done after 13 passes21 idle slots
Continuous batching· a free slot takes the next request after every pass
ABCDABCDAECDAEFDAGFDAGFDAHFAHFH
done after 9 passes5 idle slots
one token for that requestrequest finishedidle slot
Eight requests of different lengths on four GPU slots. Each column is one pass through the model, which writes one token for every request in the batch. With continuous batching the same work finishes in 9 passes instead of 13. A toy schedule: real gains depend on how much answer lengths vary.

Then memory becomes the limit. Every request in the batch keeps its KV cache on the GPU. For Mistral 7B that is 128 KB per token (keys and values, 32 layers, 8 key-value heads of 128 numbers, 2 bytes each),14 so a 4,000-token conversation holds half a gigabyte. Older servers reserved space for the longest possible answer up front, and the vLLM team found that existing systems wasted 60 to 80 percent of that memory to fragmentation and over-reservation.15 Their fix, PagedAttention, stores the cache in small fixed-size blocks, like pages in an operating system, and hands them out as tokens arrive. Waste fell under 4 percent, more requests fit in each batch, and throughput rose 2 to 4 times over the previous best systems at the same latency.15,16

At larger scale, some systems go further and run the two phases on separate GPUs, so a burst of long prompts doesn't stall everyone else's decode. DistServe, which works this way, served up to 7.4 times more requests while meeting the same latency targets.17

Lighter weights, bolder guesses

The last two ideas attack the decode pass itself. One makes each pass read fewer bytes. The other gets more than one token out of each pass.

Quantization stores the model's weights with fewer bits. Most open models ship with 16-bit weights, so a 70-billion-parameter model needs 140 GB for its weights alone, more than one 80 GB NVIDIA H100 holds.18 Stored as 8-bit integers plus a scale for each small group of weights, it fits on one GPU. At 4 bits it takes 35 GB and leaves more than half the card for KV cache, which means bigger batches. And since decode is limited by how fast weights stream out of memory, fewer bytes also means faster tokens on the same hardware.

One weighttrue value 0.04730
storedhalf-precision float=0.04730reference
70B model, weights only140 GB
GPU 1 · 80 GB
GPU 2 · 80 GB
GPUs needed2Read per token140 GBLeft for KV cache20 GB
The reference. Most open models ship in 16-bit.
Weights only, for a 70-billion-parameter model on 80 GB NVIDIA H100 GPUs. INT8 and INT4 store a small integer plus one shared scale per group of weights; the example weight and its scale are illustrative. Tap a precision to compare.

The real question is quality, because every rounding step moves a weight a little. LLM.int8() showed 8-bit inference with no measured loss on models up to 175 billion parameters.19 At 4 bits naive rounding hurts, so methods like GPTQ20 and AWQ21 use a small calibration set to decide how to round. GPTQ reported negligible accuracy loss at 3 to 4 bits and about 3.25 times faster generation on an A100. AWQ found that protecting about 1 percent of the most important weights removes much of the error. In practice the loss depends on the task, so we run our own evaluation set before switching precision, the same way we would before switching models.

Speculative decoding spends the arithmetic that decode leaves idle while it waits on memory. A small draft model guesses the next few tokens. The large model checks all the guesses in a single pass, keeps the run that matches what it would have written, and adds its own token where they part ways.22,23 Checking four guesses costs little more than writing one token, because the weights stream out of memory once either way.

Three rounds of speculative decoding with up to four guesses each. Nine tokens take three large-model passes instead of nine, and a round where every guess is wrong still yields one token. Illustrative tokens.

The output follows the same distribution the large model would produce on its own; only the time changes. The original papers measured 2 to 3 times faster decoding on T5-XXL and 2 to 2.5 times on Chinchilla 70B.22,23 EAGLE, which drafts using the large model's own internal features, reported 2.7 to 3.5 times on LLaMA2-Chat 70B.24 It helps most when traffic is light and batches are small. Under heavy load the GPU's arithmetic is already busy, which is why vLLM aims it at medium-to-low traffic, memory-bound workloads.25

Put together, the playbook is short. Keep the stable part of every prompt identical and at the front. Write less, and stream what you write. Send easy work to small models and patient work to batch queues. If you run your own GPUs, batch continuously, quantize carefully and let a draft model guess ahead. None of it is exotic. The skill is knowing which side of the request a problem lives on.

A model reads in one pass and writes one token at a time. Make the reading cheap, keep the writing short, and save the big model for the questions that need it.

References
1Agarwal, M., Qureshi, A., Sardana, N., et al. (2023). LLM Inference Performance Engineering: Best Practices. Databricks. Prefill vs decode, time to first token, and the input vs output token latency measurement.
2Anthropic (2026). Pricing. Claude API documentation. Model, cache, batch and fast mode prices, read on 9 November 2026.
3OpenAI (2026). Pricing. OpenAI API documentation. Standard and batch prices, read on 9 November 2026.
4Google (2026). Gemini Developer API pricing. Google AI Studio documentation. Standard and batch prices, read on 9 November 2026.
5Anthropic (2026). Prompt caching. Claude API documentation.
6Anthropic (2024). Prompt caching with Claude. Claude blog.
7OpenAI (2026). Prompt caching. OpenAI API documentation.
8vLLM project (2026). Automatic Prefix Caching. vLLM documentation.
9Anthropic (2026). Steering thinking. Claude API documentation. Thinking tokens are billed as output; changing effort invalidates the prompt cache.
10Nielsen, J. (1993). Response Times: The 3 Important Limits. Nielsen Norman Group, from Usability Engineering.
11Chen, L., Zaharia, M., Zou, J. (2023). FrugalGPT: How to Use Large Language Models While Reducing Cost and Improving Performance. arXiv:2305.05176.
12Ong, I., Almahairi, A., Wu, V., et al. (2024). RouteLLM: Learning to Route LLMs with Preference Data. arXiv:2406.18665.
13Yu, G.-I., Jeong, J. S., Kim, G.-W., Kim, S., Chun, B.-G. (2022). Orca: A Distributed Serving System for Transformer-Based Generative Models. USENIX OSDI 2022.
14Mistral AI (2023). Mistral-7B-v0.1 model configuration. Hugging Face. Layer count, key-value heads and head size used for the KV cache arithmetic.
15Kwon, W., Li, Z., Zhuang, S., et al. (2023). vLLM: Easy, Fast, and Cheap LLM Serving with PagedAttention. vLLM blog.
16Kwon, W., Li, Z., Zhuang, S., et al. (2023). Efficient Memory Management for Large Language Model Serving with PagedAttention. ACM SOSP 2023.
17Zhong, Y., Liu, S., Chen, J., et al. (2024). DistServe: Disaggregating Prefill and Decoding for Goodput-optimized Large Language Model Serving. USENIX OSDI 2024.
18NVIDIA (2026). NVIDIA H100 Tensor Core GPU. Product specifications. H100 SXM: 80 GB of memory at 3.35 TB/s.
19Dettmers, T., Lewis, M., Belkada, Y., Zettlemoyer, L. (2022). LLM.int8(): 8-bit Matrix Multiplication for Transformers at Scale. NeurIPS 2022.
20Frantar, E., Ashkboos, S., Hoefler, T., Alistarh, D. (2023). GPTQ: Accurate Post-Training Quantization for Generative Pre-trained Transformers. ICLR 2023.
21Lin, J., Tang, J., Tang, H., et al. (2024). AWQ: Activation-aware Weight Quantization for LLM Compression and Acceleration. MLSys 2024.
22Leviathan, Y., Kalman, M., Matias, Y. (2023). Fast Inference from Transformers via Speculative Decoding. ICML 2023.
23Chen, C., Borgeaud, S., Irving, G., et al. (2023). Accelerating Large Language Model Decoding with Speculative Sampling. arXiv:2302.01318.
24Li, Y., Wei, F., Zhang, C., Zhang, H. (2024). EAGLE: Speculative Sampling Requires Rethinking Feature Uncertainty. arXiv:2401.15077.
25vLLM project (2026). Speculative Decoding. vLLM documentation.

I want to a.

Tell us where it is today, what you’re trying to achieve and what’s getting in the way.