Filed underL03 · Cloud & DevOps
Published
Reading time17 min
Updated
Field notes · L03 Cloud & DevOps

Self-hosting open-weight LLMsVLLM, quantisation, GPU sizing and the real break-even against APIs

What self-hosting an open-weight LLM on vLLM really costs: KV cache sizing, quantisation, GPU memory maths and a break-even formula against API prices.

The short answer

A self-hosted model on vLLM costs roughly GPU $/hour ÷ (tokens per second × 3,600 × utilisation) per token, and utilisation decides almost everything. Take gpt-oss-120b on one H100 at $3.99/hour, at the throughput SemiAnalysis measured (about 9,000 tokens/s). It only beats the $0.15/$0.60 per-million-token API price once that GPU is busy about 62% of every hour, all month. And that is before you count engineering time. Most teams never get there. So self-host for control, privacy, latency or a fine-tuned model. Do not do it to save money unless you have heavy, steady traffic.

The rest of this post shows the working: how the serving stack spends GPU memory, how to size it, what quantisation actually costs you in accuracy, and a break-even worksheet you can fill in with your own numbers.


01What you are actually paying for when you self-host an LLM

A hosted API bills per token. A GPU bills per hour, whether it is busy or not. Everything else follows from that difference.

Over a month, the cost of self-hosting is:

Text
monthly_cost = (gpu_hourly_rate × gpus × 730) + fixed_ops_cost
cost_per_M_tokens = monthly_cost / (tokens_per_sec_per_gpu × gpus × 3600 × 730 × utilisation) × 1e6

There are four inputs. Three of them are mostly out of your hands:

  1. GPU hourly rate. The market sets it. On-demand H100 SXM is $3.99/GPU-hour on Lambda (8× configuration) and $5.49/GPU-hour on a Together dedicated endpoint. Community marketplaces list it lower: at the time of writing, RunPod Community Cloud lists H100 SXM at $2.69/GPU-hour.
  2. Throughput per GPU. The model, the hardware, the serving engine and your workload shape set it. You can tune it, but only within a band.
  3. Fixed ops cost. People, on-call, evals, upgrades. Easy to leave out, and you should not.
  4. Utilisation. The share of paid GPU-seconds spent doing useful work. This one is yours to control, and it moves the result more than the other three put together.

Hosted inference providers batch traffic from thousands of customers onto the same GPUs. Their utilisation is high and steady. Yours has business-hours peaks, quiet weekends and headroom for spikes. That gap, not the engine or the GPU, is usually why self-hosting loses on cost.

02How vLLM serves a model: KV cache, paged attention and continuous batching

Know what fills GPU memory and you can size hardware without guessing.

Weights, KV cache, activations

At startup vLLM loads the weights. Then it reserves a fraction of the GPU's memory, set by --gpu-memory-utilization (default 0.9). It takes out activation and CUDA-graph workspace, and everything left becomes KV cache: a pool of fixed-size blocks that holds the attention keys and values for every token of every request in flight.

Diagram
H100 80 GB (this is the whole card)
┌───────────┬────────────────┬───────────────────┬─────────────┐
│ weights   │ activations +  │ KV cache pool     │ reserve     │
│ (fixed)   │ CUDA graphs    │ (paged blocks,    │ (1 - gpu_   │
│           │ (few GB)       │ shared by all     │ mem_util)   │
│           │                │ live sequences)   │             │
└───────────┴────────────────┴───────────────────┴─────────────┘

The KV pool caps how many sequences can be in flight at once. Concurrency caps throughput. So the KV cache is what you are really buying when you buy a bigger GPU.

Paged attention and continuous batching

vLLM's PagedAttention stores each sequence's KV cache in non-contiguous blocks, much as an OS pages virtual memory. A sequence only holds the blocks it has filled, so memory is not wasted reserving room for its maximum length. Continuous batching then admits new requests and retires finished ones at every decode step. Nobody waits for the slowest request in a static batch.

Chunked prefill is on by default in the V1 engine. It splits long prompts into chunks and runs them alongside decode steps. --max-num-batched-tokens sets the trade-off: lower values (around 2048) give better inter-token latency, higher values give better time-to-first-token.

When the KV pool runs out, vLLM preempts a running request and recomputes it later. Preemption counts as wasted GPU time. Watch it.

Prefix caching

Automatic prefix caching reuses KV blocks for identical prompt prefixes: a shared system prompt, a few-shot block, a RAG preamble, an agent's growing conversation (which is why context engineering for long-running agents and serving cost are linked). SGLang's RadixAttention is built on the same idea. If your traffic shares long prefixes, this is the biggest single throughput gain you will get. Note that vLLM's gpt-oss Hopper recipe turns it off (no-enable-prefix-caching: true) because benchmark prompts are random. Do not copy that into production without checking your own traffic first.

03vLLM vs SGLang vs TGI: which serving engine in 2026

vLLM SGLang TGI
Status at the time of writing Active; v0.31.0 released 5 Oct 2026 Active; v0.5.21 Maintenance mode since Dec 2025; bug fixes only
Core memory idea PagedAttention, automatic prefix caching RadixAttention (radix-tree prefix cache) Paged attention
Strengths Widest model and hardware coverage, OpenAI-compatible server, large operator community Prefix-heavy and agentic workloads, structured outputs, prefill/decode disaggregation Simple, HF-integrated, stable
Pick it when Default choice Long shared prefixes, multi-turn agents, or you need PD disaggregation You already run it and it works. Plan a migration

Our default is vLLM. Run SGLang on a staging slice if your workload is mostly multi-turn agents or long shared context, and pick the one that does better on your traces. Do not start anything new on TGI. Hugging Face itself now recommends vLLM and SGLang as the way forward.

Both engines move quickly. vLLM shipped three minor releases between early September and early October 2026, and v0.29 made Model Runner V2 the default. Pin exact versions. Re-benchmark on every upgrade. Treat the engine like a database, not a library.

04How much GPU memory do I need? Worked sizing examples

The KV cache formula

For standard multi-head or grouped-query attention:

Text
kv_bytes_per_token = 2 (K and V) × num_layers × num_kv_heads × head_dim × bytes_per_element

Per sequence, multiply by context length (prompt + output). For the whole pool, multiply by concurrent sequences.

Example 1: Llama 3.3 70B (dense, GQA)

From the model's config.json: 80 layers, 8 KV heads, hidden size 8192 over 64 attention heads, so head_dim = 128.

Text
BF16 KV: 2 × 80 × 8 × 128 × 2 bytes = 327,680 bytes ≈ 320 KiB per token
FP8 KV:  ≈ 160 KiB per token

One 9,000-token conversation (8k in, 1k out) therefore holds about 2.9 GB of KV cache at BF16, or 1.5 GB at FP8.

Weights for 70.6B parameters:

Weight format Weight memory (approx.) Fits on
BF16 ~141 GB 2× H100 80 GB, with little room left for KV
FP8 (W8A8) ~71 GB 2× H100 comfortably; 1× H100 with almost no KV room
INT4 (W4A16) ~38–40 GB 1× H100 with ~30 GB of KV

Worked calculation, 2× H100 at TP=2, FP8 weights, FP8 KV. Usable memory at 0.9 utilisation is about 144 GB. Take off 71 GB of weights and allow roughly 8 GB for activations and graphs (an assumption that varies with max_num_batched_tokens). That leaves about 65 GB of KV, or 65e9 / 163,840 ≈ 400k tokens: around 44 concurrent 9k-token sequences. At BF16 KV the same box holds about 22. FP8 KV doubles your concurrency here, and that is why it matters as much as weight quantisation.

Example 2: gpt-oss-120b (MoE, mixed attention)

gpt-oss-120b is a mixture-of-experts model (128 experts, 4 active per token) shipped with MXFP4 expert weights. OpenAI states it fits on a single 80 GB GPU. Its config alternates sliding-window (128-token) and full-attention layers across 36 layers, with 8 KV heads of head_dim 64.

Text
Full-attention layers (18): 2 × 18 × 8 × 64 × 2 bytes = 36,864 bytes ≈ 36 KiB per token
Sliding layers (18): capped at 128 tokens → ~4.7 MB per sequence, regardless of length

A 9k-token sequence needs about 0.34 GB. That is roughly a ninth of Llama 70B's figure, and it explains why this model serves so cheaply. On a single H100 the weights take most of the card: the checkpoint is about 65 GB (61 GiB). By our estimate, after activations and CUDA graphs, gpu-memory-utilization 0.95 leaves somewhere around 6–8 GB of KV, or about 20 concurrent 9k-token sequences. The vLLM recipe warns that the defaults OOM on H100 at TP=1. Raise utilisation to 0.95 or lower max-num-batched-tokens.

Rough cross-check: SemiAnalysis measured ~9,000 total tokens/s per GPU at 50 output tokens/s per user on an 8k/1k workload (InferenceX). One ninth of that is output, about 1,000 tokens/s, so ~20 users at 50 tokens/s each. That matches the memory maths, which is reassuring.

A reference vLLM config

bash
# Llama-3.3-70B-class model, FP8 weights, 2x H100, chat workload
vllm serve <your-org>/Llama-3.3-70B-Instruct-FP8 \
  --tensor-parallel-size 2 \
  --gpu-memory-utilization 0.92 \
  --kv-cache-dtype fp8 \
  --max-model-len 16384 \
  --max-num-seqs 64 \
  --max-num-batched-tokens 4096 \
  --enable-prefix-caching

Why each flag is set the way it is:

  • --max-model-len is set to what you actually need, not the model's 131k maximum. A long limit does not reserve memory per request under paging. It does let one huge request take over the pool, and it affects scheduling.
  • --kv-cache-dtype fp8 uses scales of 1.0 unless you calibrate. The vLLM docs recommend dataset calibration via llm-compressor for best accuracy. Evaluate before and after.
  • --max-num-seqs caps concurrency below the point where preemption starts. Find that point by load testing.

05Quantisation trade-offs: FP8, INT8, INT4 for serving

Quantisation does two jobs. It shrinks the weights, so they fit on fewer GPUs. It also frees memory for KV cache, which raises concurrency. The main published evidence is Neural Magic / Red Hat's "Give Me BF16 or Give Me Death"?, over 500,000 evaluations across the Llama 3.1 family:

Scheme What it is Accuracy (per the paper) Best for Hardware
FP8 W8A8 8-bit float weights and activations Effectively lossless at all scales Default on Hopper/Blackwell H100, H200, B200, L40S
INT8 W8A8 8-bit int weights and activations 1–3% degradation when well tuned Ampere (A100), which lacks FP8 A100 and newer
INT4 W4A16 4-bit weights, 16-bit activations Competitive with 8-bit Low-concurrency, latency-sensitive, or fitting onto fewer GPUs Broad
MXFP4 / NVFP4 4-bit microscaling float Model-specific; gpt-oss is trained/released in MXFP4 Blackwell-native; models shipped this way Native on Blackwell

The paper also found W4A16 the most cost-efficient for synchronous (low-batch) serving, and W8A8 the winner under asynchronous continuous batching. That fits the mechanics. Weight-only 4-bit cuts memory bandwidth per token, which is what limits small batches. At large batches you are limited by compute, and 8-bit activations use the faster tensor-core paths.

What we would do:

  • On H100 or newer, start with FP8 weights and FP8 KV. Most teams never need to go further.
  • Use INT4 to fit a model onto one GPU when you would otherwise need two at low traffic. The saving is a whole GPU, not a percentage.
  • Always run your own evals. Build LLM evals for your own use case before and after every quantisation change. Academic benchmarks average out tail behaviour. Tool-calling formats, JSON validity and long-context retrieval are where quantisation errors show up first. Test the tasks you actually ship.
  • You probably do not need to quantise a model yourself. Pre-quantised checkpoints from the model vendor or from llm-compressor users usually exist. Check how they were calibrated.

06Utilisation is the whole game

This is where most business cases fall apart.

Utilisation is not GPU utilisation from nvidia-smi. That counter says a kernel was running. What you need is achieved tokens per second ÷ the throughput you would get at your latency target under saturating load, averaged over every hour you pay for.

Three things hold it down:

  1. Diurnal traffic. You size for peak, but you pay around the clock. A business-hours-only workload is idle roughly two-thirds of the week, before you even get to headroom.
  2. Redundancy. One replica is not production. Two replicas for availability, each sized to take the full load, means each runs at no more than 50% of what it could do at peak.
  3. The latency target. Throughput per GPU drops steeply as you demand faster tokens per user. From the same InferenceX run on gpt-oss-120b / H100:
Per-user output speed Total tokens/s per GPU
50 tok/s 8,973
100 tok/s 5,863
150 tok/s 3,931
200 tok/s 2,558

Moving from 50 to 100 tokens/s per user costs about 35% of your capacity. Moving to 200 costs over 70%. Before you size anything, agree a latency SLO with product, and know how much of the wait streaming and the rest of the UX for AI latency can hide. "As fast as possible" is a budget decision, not an engineering one.

How to raise utilisation, roughly from most to least effect:

  • Move offline work onto the same fleet. Batch summarisation, embedding backfills and eval runs fill the troughs. Give interactive traffic priority and let batch work queue.
  • Turn on prefix caching and structure prompts so the shared prefix comes first.
  • Autoscale on queue depth (vllm:num_requests_waiting), not CPU. Model load times make scaling slow. vLLM v0.30 added a persistent weight-cache daemon for faster restarts, which helps, but scaling from zero is still not cheap.
  • Share one base model across tenants or use cases with LoRA adapters, rather than one deployment per fine-tune.

The metrics to put on a dashboard

For per-request token and cost attribution above the engine, see tracing LLM apps with the OpenTelemetry GenAI conventions. For the engine itself, from vLLM's Prometheus endpoint:

promql
# Saturation: are requests queueing?
max_over_time(vllm:num_requests_waiting[5m])

# KV pressure: near 1.0 means preemption is coming
vllm:kv_cache_usage_perc

# Wasted work
rate(vllm:num_preemptions_total[5m])

# Prefix cache hit rate
rate(vllm:prefix_cache_hits_total[1h]) / rate(vllm:prefix_cache_queries_total[1h])

# Latency SLOs
histogram_quantile(0.95, rate(vllm:time_to_first_token_seconds_bucket[5m]))
histogram_quantile(0.95, rate(vllm:inter_token_latency_seconds_bucket[5m]))

The metric that decides cost is one you build yourself: tokens served per paid GPU-hour, tracked weekly. If it is not going up, your cost per token is not going down.

07The break-even worksheet: self-hosted vLLM vs API pricing

This is the part we would want in front of us before signing a GPU commitment, and the numbers worth keeping in an architecture decision record, because a commitment is hard to undo.

Step 1: blend the API price for your input/output mix

APIs price input and output separately. Self-hosted throughput counts both. Blend them by your real ratio:

Text
blended_api_price = (in_tokens × in_price + out_tokens × out_price) / (in_tokens + out_tokens)

gpt-oss-120b on Together is $0.15 in / $0.60 out per million tokens. At an 8:1 input/output ratio, the one the benchmark used:

Text
(8 × 0.15 + 1 × 0.60) / 9 = $0.20 per million tokens

Include whatever cached-input or batch discounts your API provider gives. They narrow the gap further, and LLM API cost engineering with prompt caching, model routing and batching can lower the API side further still.

Step 2: find the throughput you need for break-even

Text
required_avg_tokens_per_sec_per_gpu = gpu_hourly_rate / (3600 × blended_api_price / 1e6)
break_even_utilisation = required_avg_tokens_per_sec_per_gpu / measured_tokens_per_sec_per_gpu

Step 3: worked example, gpt-oss-120b on H100

Assumptions: one H100 at $3.99/hour (Lambda on-demand); 8,973 tokens/s at the 50 tok/s per-user target (InferenceX); 8:1 traffic; no ops cost yet.

Text
required = 3.99 / (3600 × 0.20e-6) = 5,542 tokens/s per GPU, averaged over the month
break_even_utilisation = 5,542 / 8,973 = 62%

Same model, other assumptions:

GPU price Per-user target Throughput/GPU Break-even utilisation
$3.99/h 50 tok/s 8,973 62%
$2.69/h 50 tok/s 8,973 42%
$3.99/h 100 tok/s 5,863 95%
$2.69/h 100 tok/s 5,863 64%

Now make it realistic. Two replicas for availability, 40% average utilisation each (a reasonable result for a single-product workload with daytime peaks; an assumption, not a measurement), $3.99/hour:

Text
cost per M = (3.99 × 2 × 730) / (8,973 × 2 × 3600 × 730 × 0.40) × 1e6 ≈ $0.31 per million tokens

That is about 1.5× the API price, before any engineering time. Add an illustrative $5,000/month for the share of a platform engineer's time spent on upgrades, evals and on-call (substitute your own figure). The two GPUs cost $5,825/month, so the ops share adds another ~86% on top.

Conclusion for this model: a cheap MoE that providers already serve at scale is very hard to beat on price. SemiAnalysis's own figure for hyperscaler-volume ownership cost is $0.036 per million total tokens at this operating point. That is the cost base your API provider competes on, and you will not match it.

Step 4: worked example, a 70B dense model

Older dense models are often priced well above their running cost. Llama 3.3 70B is $1.04/M input and output on Together. On 2× H100 at $3.99/hour:

Text
required_avg_tokens_per_sec (for the pair) = (2 × 3.99) / (3600 × 1.04e-6) ≈ 2,131 tokens/s

We have not found a current primary-source benchmark for Llama 3.3 70B FP8 on 2× H100 at a defined latency target. So run the test yourself. If your load test sustains, say, 5,000 total tokens/s at your SLO (an illustrative figure, not a measurement), break-even falls at 43% utilisation. That is achievable for a busy internal platform, and it is the shape of workload where self-hosting can pay.

The calculator

python
"""Self-hosted LLM vs API break-even. All prices USD; tokens counted input+output."""
from dataclasses import dataclass

HOURS_PER_MONTH = 730

@dataclass
class Scenario:
    gpu_hourly: float          # $/GPU-hour you actually pay
    gpus: int                  # total GPUs incl. redundancy
    tok_s_per_gpu: float       # measured at YOUR latency SLO, YOUR prompt mix
    utilisation: float         # avg useful load / capacity, over all paid hours
    fixed_monthly: float = 0.0 # people, on-call, evals, storage, egress

    def monthly_cost(self) -> float:
        return self.gpu_hourly * self.gpus * HOURS_PER_MONTH + self.fixed_monthly

    def monthly_tokens(self) -> float:
        return self.tok_s_per_gpu * self.gpus * 3600 * HOURS_PER_MONTH * self.utilisation

    def cost_per_m(self) -> float:
        return self.monthly_cost() / self.monthly_tokens() * 1e6

def blended_api_price(in_tok: float, out_tok: float, p_in: float, p_out: float) -> float:
    return (in_tok * p_in + out_tok * p_out) / (in_tok + out_tok)

def break_even_utilisation(s: Scenario, api_price_per_m: float) -> float:
    cost = s.gpu_hourly * s.gpus * HOURS_PER_MONTH + s.fixed_monthly
    capacity = s.tok_s_per_gpu * s.gpus * 3600 * HOURS_PER_MONTH
    return cost / (capacity * api_price_per_m / 1e6)

if __name__ == "__main__":
    api = blended_api_price(8, 1, 0.15, 0.60)               # gpt-oss-120b, 8:1 mix
    s = Scenario(gpu_hourly=3.99, gpus=2, tok_s_per_gpu=8973,
                 utilisation=0.40, fixed_monthly=5000)       # illustrative
    print(f"API blended:      ${api:.3f}/M")
    print(f"Self-host:        ${s.cost_per_m():.3f}/M")
    print(f"Break-even util:  {break_even_utilisation(s, api):.0%}")

With these inputs the break-even utilisation comes out above 100%. That is the honest answer for this model: no amount of tuning makes the numbers work.

Costs people leave out

  • Redundancy and headroom. Already covered above, and the most common omission.
  • Evals. Every model, quantisation or engine upgrade needs a regression run. That is GPU time and engineer time.
  • Cold capacity. Reserved or committed GPUs are cheaper per hour but turn scaling up into a procurement problem.
  • Egress and storage. Weights are tens to hundreds of GB per model version, per region.
  • Opportunity cost. The engineer tuning max-num-batched-tokens is not working on your product.

08Decision matrix: when self-hosting an LLM makes sense

Signal Lean API Lean self-host
Sustained average throughput Below the break-even from the worksheet Well above it, on most hours of the week
Traffic shape Bursty, daytime, single product Steady, or with offline work to fill troughs
Model Popular open model already served cheaply (MoE, gpt-oss class) Your own fine-tune, or a model priced well above its running cost
Data constraints Provider's DPA and region options are enough Contractual or regulatory need for data to stay in your VPC or on-prem
Latency Provider p95 meets your SLO You need guaranteed TTFT, co-location with other services, or no shared-tenancy jitter
Team No one owns GPU infra today You already run Kubernetes GPU nodes and on-call
Customisation Prompting and RAG are enough Custom adapters, constrained decoding, logit access, speculative decoding tuned to your traffic

If the right-hand column wins on cost alone, double-check the utilisation figure. If it wins on data control or latency, self-host and budget for it honestly. There is a sensible middle path too: a dedicated endpoint from an inference provider (e.g. Together at $5.49/H100-hour). You get isolation and a fixed model version, while someone else runs the engine.

09Where this touches the rest of the stack

Inference cost is rarely just a Cloud & DevOps question. Data residency, and whether prompts may be logged, is a Security decision, and it often settles the API-or-self-host question before cost comes into it. Prefix-cache hit rates depend on how the Software and AI & Automation layers build their prompts. Offline batch jobs from the Data layer are what fill the GPU troughs. And whether you run GPU nodes on Kubernetes at all is the same question as do I need Kubernetes, with a much bigger bill attached. Planning the fleet as one shared platform, rather than one cluster per team, is usually what moves utilisation from 20% to 50%.

10FAQ

Is it cheaper to self-host an LLM than to use an API?

Usually not, for popular open models. With gpt-oss-120b on H100 at $3.99/hour, break-even against $0.15/$0.60 API pricing needs about 62% sustained utilisation, and more once you add redundancy and staff time. Self-hosting pays when traffic is heavy and steady, when the model is your own fine-tune, or when the API price is far above running cost.

How many GPUs do I need to serve a 70B model with vLLM?

At FP8, two 80 GB GPUs (H100/H200) with tensor parallelism. That leaves about 65 GB for KV cache, roughly 40+ concurrent 9k-token sequences with FP8 KV. At INT4 one 80 GB GPU works, with less concurrency. BF16 needs two GPUs and leaves little KV room, so we would not run it in production.

Should I use vLLM or SGLang?

Start with vLLM: widest model and hardware support, largest community. Benchmark SGLang if your traffic has long shared prefixes or multi-turn agent sessions, where RadixAttention and its PD-disaggregation support can win. Do not start new deployments on TGI. It has been in maintenance mode since December 2025.

Does quantisation hurt output quality?

FP8 weights and activations are effectively lossless in the largest published study. Well-tuned INT8 loses 1–3%, and INT4 weight-only is competitive with 8-bit. Your own task evals matter more than averages. Check structured output, tool calls and long-context retrieval specifically.

What GPU utilisation should I plan for?

Measure it, do not assume it. Define it as achieved tokens/s divided by measured capacity at your latency SLO, averaged over every paid hour. A single interactive product with two replicas often lands well under 50%. Shared platforms that soak up batch work can go higher.

What about Blackwell (B200) instead of H100?

B200 costs more per hour ($6.69/GPU-hour on Lambda) but has native FP4 and much higher throughput per GPU. Rerun the worksheet with measured tokens/s, using SemiAnalysis's InferenceX comparisons as a starting point. The formula stays the same. Only the inputs change.


If this is the layer that hurts, we should talk.

Tell us which layer hurts →