A model is a big file of numbers. Something has to load it, take requests from many people at once, manage memory and produce answers one token at a time, as fast and cheaply as the hardware allows. That something is an inference engine. Here's what the four best-known ones optimize for, how to pick one, and what the same ideas mean for your Claude bill.

What an inference engine does

Training builds the model. Inference is everything after: every time you send a prompt, the model runs and generates its answer one token at a time, and each new token depends on all the tokens before it.

General-purpose tools like PyTorch can run a model, but they weren't built for that token-by-token pattern at scale. Inference engines specialize in it. They decide which requests run together, where memory goes, how compressed the model is and which GPU code runs. Most of the well-known engines appeared in 2023, once large language models made those decisions worth optimizing.

The two things that fill memory

Almost every trick below is about memory. Two things compete for it:

Model weightsKV cache
What it isThe trained numbers that make up the modelSaved intermediate results for every token so far, so the model doesn't recompute them
SizeFixed for a given model and precisionGrows with every token, in every conversation, for every user
Rough example7 billion parameters at 16 bits each is about 14 GB; at 4 bits, about 3.5 GBSmall for one short chat, huge for long chats with many users

The weights decide whether a model fits at all. The KV cache decides how many people you can serve at once.

llama.cpp: run big models on the hardware you have

The problem it solves: big models assume a big GPU, and most people don't have one.

  • Quantization. It supports 1.5-bit up to 8-bit integer versions of models, which shrink the weights and speed things up at some cost to quality.
  • CPU and GPU together. If a model is bigger than your GPU memory, it can run part of it on the GPU and the rest on the CPU.
  • Memory mapping. By default it maps the model file into memory and lets the operating system load pieces as they're needed, instead of copying the whole model up front.
  • Runs almost anywhere. It's designed for minimal setup, and Apple silicon is a first-class target.

Best for: running a model on your own laptop or desktop, offline or for privacy.

vLLM: serve many users without wasting memory

The problem it solves: older serving systems reserved KV cache memory for each request's maximum possible length. Most of that space sat empty. The vLLM paper found only 20.4% to 38.2% of KV cache memory actually held tokens.

  • PagedAttention. It splits the KV cache into small fixed-size blocks and hands them out as a conversation grows, the way an operating system pages memory. Waste drops to near zero, so more requests fit at once.
  • Continuous batching. New requests join the batch as soon as others finish, instead of waiting for the whole group.

The paper reported 2 to 4 times the throughput of earlier systems at the same latency, with bigger gains for longer conversations and larger models.

Best for: serving an open model to many users on your own GPUs.

SGLang: stop recomputing the same start of every prompt

The problem it solves: many prompts start the same way, with the same system prompt, examples or chat history. Recomputing that shared start for every request wastes work.

  • RadixAttention. It keeps the KV cache for prompt beginnings in a tree, so any request that starts the same way reuses the stored work. When memory fills up, it evicts the least recently used branches first.
  • Faster structured output. It also speeds up responses that must follow a format, like JSON.

The SGLang paper reported up to 6.4 times the throughput of other systems, on workloads like agents, multi-turn chat and retrieval. "Up to" matters here: the gain depends on how much your prompts share.

Best for: agents and chat apps where many requests share a long prompt beginning.

TensorRT-LLM: get the most out of Nvidia GPUs

The problem it solves: squeezing maximum performance from specific hardware.

Nvidia's library combines specialized GPU code for common operations with an efficient runtime and a Python framework you can extend. Because Nvidia makes the chips too, it can tune for them closely.

Best for: teams already on Nvidia GPUs who want peak performance and can handle more setup.

They overlap more now. These engines started with different priorities, but the serving engines borrow each other's best ideas. vLLM now lists prefix caching alongside PagedAttention and continuous batching, for example. Choose on your hardware and workload, not on one headline feature.

Pick one

Your situationStart withWhy
Running a model on your laptop or Macllama.cppSmall quantized models, runs on CPU and Apple silicon
Serving an open model to many usersvLLMMemory efficiency and throughput
Agents or chats with long shared promptsSGLangReuses the shared start of prompts
Production on Nvidia GPUs, maximum speedTensorRT-LLMTuned for Nvidia hardware
You use Claude or another hosted APINoneThe provider runs the engine. You can still use its ideas, below

What this means when you use Claude

You never choose Claude's inference engine. Anthropic runs it. But three API features expose the same ideas, and they change what you pay:

Engine ideaClaude featureWhat to do
Reuse the shared start of promptsPrompt caching. Cache reads cost 0.1x the normal input price: 0.05x on Opus 5.5 and Sonnet 5.5, 0.025x on Fable 5.2Put what stays the same first: tools, then the system prompt, then messages
Let the provider schedule the workMessage Batches API. 50% off, and most batches finish in under an hourSend anything that isn't urgent as a batch
Pay more for speedFast mode on Fable 5.2: up to 2.5x faster at twice the priceUse it only when someone is waiting

Cache entries last 5 minutes by default and refresh each time they're used. A cached prompt only helps if the next request starts the same way, so a timestamp at the top of your system prompt quietly breaks it.

Start here

  • Try one locally. Install llama.cpp from its official site, then run llama cli -hf ggml-org/Qwen3.5-0.8B-GGUF to download and chat with a small model
  • If you use the Claude API: move tools and the system prompt to the front, turn on prompt caching, and check that cache reads show up in your usage
  • For the clearest explanation of the KV cache problem, read the introduction of the vLLM paper

Go deeper: Claude prompt caching · SGLang paper · TensorRT-LLM · Fable 5.2 vs Gemini 4 Carbon