Getting an open model to answer from your own GPU takes an afternoon. Keeping it answering hundreds of people while you upgrade the inference engine, switch models or lose a node is a different job.

At Helmcode we learned this by running inference infrastructure for companies and for the users of NaN.builders. We have had to size GPUs for agents that handle hundreds of thousands of tokens of context, upgrade engines without interrupting the service, and fix problems that never show up in a ten-minute load test.

This guide collects those lessons. We explain what you need to serve language models in production, how to tell whether they are actually working, what it costs to keep them running and when it makes sense to do it yourself.

What self-hosting an LLM means

Self-hosting means deploying a model on infrastructure whose operation you control, instead of relying only on an external API. You can do it with open-weight models such as Qwen, Gemma, DeepSeek or GLM, as long as their licences allow your use case. It is not a property of the model: it is a way of deploying it.

There are three independent decisions: where inference runs, who operates the service and what controls exist over the data.

Four ways to deploy a model

Mode
Where it runs
Provider's infrastructure
Who operates the service
Provider
Responsibility for the data
Per contract, retention and technical controls
Four ways to deploy a model
ModeWhere it runsWho operates the serviceResponsibility for the data
Managed API Provider's infrastructure Provider Per contract, retention and technical controls
Self-hosted in the cloud Rented GPUs Your team Your team and the authorised dependencies
Your own on-premise Infrastructure on your premises Your team Per your access, network and policies
Managed dedicated deployment Dedicated infrastructure, external or local Contracted provider Per design and contract
Location, operation and access are independent decisions. Dedicated hardware can sit on your premises or the provider's. On-premise does not mean air-gapped.

On-premise does not automatically mean the environment is cut off from the internet. An air-gapped deployment adds that requirement and forces you to set specific procedures for bringing in weights, dependencies and updates. Nor does it mean the data is protected by default: a local server that logs every prompt can introduce risks that an API with strict retention policies avoids.

The inference stack can be very similar in all of these modes.

What changes is who looks after it and under which constraints.

When running your own models pays off

There are three reasons it is worth considering.

The data must stay inside a given perimeter. If a contract or a security policy forbids sending it outside your infrastructure, the economics come second. You will have to deploy inside that perimeter, although you can delegate the operation if your requirements allow it.

Your load is high and predictable enough. A rented GPU costs the same while it generates tokens as while it waits for requests. And the utilisation that matters is that of each group of GPUs assigned to each model, not the average across the fleet. A saturated model does not automatically make up for one sitting idle.

You need to control the inference environment. Maybe you have your own weights or LoRA adapters, need a model no provider offers, want to change the engine configuration or must guarantee a specific behaviour under a given load.

On the other hand, if your traffic is irregular, you change models constantly or nobody can take on the maintenance, starting with a managed API is usually a reasonable choice. It lets you learn your real load before committing to hardware.

Where to start

  • Must the data stay inside a perimeter?
    • Yes Can your team operate it?
      • YesYour own deployment inside the perimeter (or a managed one, if you prefer)
      • NoA managed deployment inside the perimeter
    • No Do you need to control or customise the environment?
      • YesEvaluate a dedicated or your own deployment
      • No Is the load high and predictable?
        • NoA managed API as the starting point
        • YesCompare TCO, SLOs and operating capacity before deciding
A starting point for the decision, not a rule: every branch depends on your requirements.

Before asking for a GPU quote, record over a representative period how many requests you get, which models you use, how much context you send, how many tokens you generate and when traffic peaks. Also define what latency you can tolerate and how much downtime your product accepts. That data is far more useful than your company's headcount.

How to size the GPUs

The usual question is "how much VRAM do I need to load this model?". It is a good place to start, but not enough for production.

A model that fits is not necessarily a model that can handle your load.

A GPU's memory has to hold the model weights, the KV cache of the active sequences and the memory the engine uses to run inference. You also need headroom for load swings and the quirks of the implementation.

Weights, precision and quantisation

A first approximation of the size of the weights is the total number of parameters times the bits used to represent them, divided by eight. A 35-billion-parameter model at 16 bits takes about 70 GB in theory (65.2 GiB), before any other part of the format.

In a Mixture of Experts (MoE) model, the active parameters per token help you understand the compute work, but they do not necessarily represent the memory of all the weights you need to load. A 35B model with 3B active should not be sized like a dense 3B model.

Lowering the precision of the weights frees memory, although the speed gain depends on the hardware, the kernels, the format and the load. It can also affect quality. Evaluate the quantised model on your own tasks, especially if you need reasoning, code or tool calls.

What the KV cache is and why it matters

During generation, a transformer can keep the attention representations of earlier tokens so it does not recompute them over and over. That memory is the KV cache. Its size depends on the architecture, the cache precision and the tokens stored. Some hybrid architectures also have other state that has to be counted.

A short chat and a coding session with a 100,000-token context can use the same model, but their memory needs are very different.

Take Qwen3.6-35B-A3B on a 96 GB NVIDIA RTX PRO 6000, with the figures from our deployment experience:

GPU memory: 16-bit weights against NVFP4

Weight precision
Weights
20.4GiB
Memory freed
44.6GiB
Reported KV cache
61GiB
See the data
ItemExample estimate
16-bit weights~65 GiB
NVFP4 weights~20.4 GiB
KV cache per token at 16 bits~20 KB
KV cache per token in FP8~10 KB
KV cache in the NVFP4 configuration~61 GiB
Estimates from our deployment of Qwen3.6-35B-A3B on a 96 GB RTX PRO 6000 (96 decimal GB are 89.4 GiB). Quantized weights include overhead: not all of the model is in 4 bits. Other engine state also takes memory and is not drawn. Source: Serving agents with vLLM on your own GPU.

With that last configuration, the approximate capacity is six million cache tokens in FP8. If each request holds 100,000 tokens, that is about sixty sequences as a theoretical memory limit, before generated tokens, extra state, prefix reuse and scheduler constraints. It does not mean sixty users will get tokens at an acceptable speed.

Work out the memory you need

One device, or a memory budget already worked out for a group. Splitting a model across GPUs or replicating it does not add memory linearly. The starting values are a hypothetical example.

GiB
What is actually available, not the marketing figure: 96 GB is 89.4 GiB, and the system keeps part of it.
B
Bits per weight
GiB
B
More settings
GiB
GiB
At 0 the estimate from parameters and bits is used.
Concurrent sequences 56
Weights (estimated)
19.3GiB
Memory for KV cache
54.7GiB
Tokens that fit in cache
5,873,566

A theoretical memory limit, not an SLO: it says nothing about how fast each user will get tokens.

Formulas
weights   = measured ?? params × 10⁹ × bits ÷ 8 ÷ 2³⁰ + overhead
cache     = vram − weights − reserve
tokens    = ⌊cache × 2³⁰ ÷ bytesPerToken⌋
sequences = ⌊tokens ÷ (input + output)⌋

Size for the agents, not for the chat demo

In NaN's first month, half the requests carried more than 4,400 tokens of context and the largest 10% went over 100,000. In the analysis of Claude Code sessions we gathered in Serving agents with vLLM on your own GPU, the reference figure was about 174 requests per session and input contexts in the order of 100,000 tokens. These are observations of one specific load, not universal traits of Claude Code.

An agent resends instructions, history, tool results and files throughout a session. The cost of serving it depends on how much context is new, how much can be reused and how many sessions overlap.

This is where prefix caching comes in. If two requests share a compatible prefix and the engine keeps its state, it can reuse part of the prefill work. In the production setup described in that same article, more than 80% of input tokens were cache hits. That percentage should not be extrapolated to other models or customers: it changes with traffic, routing and memory pressure.

How prefix caching reuses an agent's context

New tokens (prefill)
4,000
Reusable tokens
23,000
Prefix reused from the cache New context (prefill) Generated answer

Illustrative example: 12,000 tokens of instructions and files in the first request, then about 4,000 tokens of tool results in each of the next ones, plus the previous 1,000-token answer.

over 80% of input tokens were cache hits in our production. It does not carry over to other models or customers. Source.

Conceptual sketch: the proportions are not data. The prefix is reused if it matches and is still in memory. Not all of the history is cacheable, and the cache is evicted when memory runs short.

In one of our tests, moving from FP8 to NVFP4 on the same card gave 11% more throughput and cut the peak KV cache occupancy by 12 percentage points, with 32 concurrent requests of 81,000 tokens. The memory freed by the weights was a large part of the gain. The NVFP4 KV cache configuration, however, gave us stability problems, and we kept FP8 for that cache.

The conclusion is not that NVFP4 is always better. It is that you can choose the precision of the weights and of the cache separately, and that you have to measure both decisions on the hardware and the load you are going to serve.

The architecture of an inference service

A single server with an inference engine can be enough for a low-criticality internal tool. Once several teams, models and availability requirements appear, other pieces become necessary.

Reference architecture of an inference service

Clients ApplicationsCoding agentsInternal tools Edge / ingress TLS · access Gateway auth · routing · usage PostgreSQL keys · quotas · usage Model A · replica 1 Inference engine GPU Model A · replica 2 Inference engine GPU Model B · multi-GPU group Inference engine 4 GPU Admin plane metrics · config · deploys Clients apps · agents · tools Edge / ingress TLS · access Gateway auth · routing · usage PostgreSQL keys · usage Model A · replica 1 Inference engine GPU Model A · replica 2 Inference engine GPU Model B · multi-GPU group Inference engine 4 GPU Admin plane metrics · config · deploys

The path of a request It comes in through the edge, the gateway authenticates it against PostgreSQL and sends it to a backend that serves that model.

Select a box to see what it does
A reference architecture, not Helmcode's topology. Kubernetes is an option, not a requirement.

Inference engine

vLLM and SGLang are two common options for serving models with continuous batching, efficient cache management and an OpenAI-compatible API. Ollama and llama.cpp can also serve requests and make a lot of sense elsewhere, especially when easy local execution or support for diverse hardware comes first. The choice depends on your load, not on a universal ranking of tools. We explain how to set up a server with vLLM in this article.

Pin the version of the engine, the drivers, the weights and their configurations. An upgrade can change a parser, a start-up argument or the behaviour of a chat template without touching the model weights.

Gateway

It is the entry point for clients. It has to handle authentication, per-model permissions, usage and concurrency limits, routing, usage metering and fallback policies. In a shared service it also has to stop one client from monopolising the resources.

We started with LiteLLM. One lesson from that experience is that the gateway ends up piling up business logic: budgets, limits, request transformations and routing decisions. Measure its CPU and memory use, the latency it adds, streaming performance and how it behaves when it loses its database. Do not assume it is a free proxy.

Edge and ingress

This is where you manage TLS, DNS and access to the inference endpoints. Admin, metrics and debugging endpoints should not be publicly exposed. If the service is internal, you may not need to publish the API on the internet at all.

State and admin plane

API keys, budgets and usage records need persistence. When authentication or usage control depends on the database, the database is on the critical path. Use bounded connections, pooling where it fits, backups and a recovery plan. If criticality demands it, add replication and tested failover.

In our case, moving databases next to their applications cut an operation of 10 to 12 queries from 273 ms to 7.7 ms without changing the queries.

Where a dependency lives can matter as much as optimising its code.

Separate the admin plane from inference traffic. Use a private network or equivalent restricted access to operate the engines, read metrics and deploy configurations.

Kubernetes can make it easier to deploy and recover distributed services, but it is not a requirement to get started. A well-run server can be enough if its limits and availability fit the product.

How to measure LLM performance in production

Two servers can generate the same total tokens per second and give their users completely different experiences.

Inference has two basic phases. During prefill, the model processes the input context. During decode, it generates the output tokens. Before both there can be time waiting in the queue; the client also sees network and gateway latency.

Anatomy of a request

TTFT

From sending the request to the first token received: network, gateway, queue and prefill.

  • Queue: How long the request waits before the engine starts processing it.
  • TTFT: From sending the request to the first token received: network, gateway, queue and prefill.
  • ITL: The interval between two consecutive tokens of the answer.
  • TPOT: The mean of the intervals between output tokens, as the benchmark defines it.
  • End to end: From sending to the last token: how long the full answer takes.
Sketch, not to scale. Prefill varies with each request's context.

Metric

What it tells you

TTFT (Time to First Token)

How long the user waits for the first token

TPOT (Time per Output Token)

Average time between output tokens, as the benchmark defines it

ITL (Inter-Token Latency)

Interval between consecutive tokens

Output TPS per request

Generation speed one request experiences

Aggregate throughput

Tokens processed or generated per unit of time; say which

Goodput

Useful requests or tokens per unit of time that meet the defined SLO

Queue time

How long requests wait before being processed

Prefix cache hit rate

Share of input tokens reused, as the engine defines it

KV cache utilization

Occupancy of the memory reserved for the cache

Error rate

Share of failed requests, with an explicit criterion

Aggregate throughput usually grows as batching increases, but past a certain point it can do so at the expense of per-request speed or latency. So the goal should not be the highest TPS a card can reach, but the most work served that meets your product's targets.

Define SLOs (service level objectives) for TTFT, generation, errors and availability. An interactive chat, a coding agent and a batch process can have different targets. Measure percentiles, not just averages: an acceptable average TTFT can hide requests that take tens of seconds.

How to run a useful capacity test

Build a representative load with the real distribution of input and output sizes. Test short and long contexts separately, with a cold and a warm cache. Raise concurrency step by step and record TTFT p50/p95, TPOT, input and output throughput, goodput, errors, queue and cache occupancy. Add a test with arrivals at a controlled rate to find where the queue starts growing without recovering.

Record the model and its revision, quantisation, hardware, engine and driver versions, batching configuration, seeds where they apply and the length of each run. Without those conditions, comparing two TPS figures is of little use.

Do not confuse the engine's latency with the client's. An agent's harness can add tools, retries, response processing or successive calls. Measure the server directly and also the full path from the client.

Your LLM can be down while every health check is green

An HTTP service can accept connections, return metrics and answer /v1/models while the inference engine is unable to generate a single token. The checks that work for a conventional web application are necessary here, but not enough.

Health checks green, engine down

Detection interval HTTP 200 on /health Tokens generated The engine wedges
2of 4
checks green
Process The process exists and answers a basic check Pass
API The HTTP endpoint returns a valid response Pass
Engine There is real inference progress when there is work Fail
End to end A complete authenticated request returns the expected result Fail

There is pending work and no progress: the engine and end-to-end checks fail. Process and API stay green.

Conceptual example, not real telemetry. The goal is to catch silent failures; /health does not always return 200 when the engine fails.

Use four levels of checks:

Level

What it checks

What it can miss

Process

The process exists and answers a basic check

Stuck engine

API

The HTTP endpoint returns a valid response

Stalled generation

Engine

There is real inference progress when there is work

External routing or authentication failures

End to end

A complete authenticated request returns the expected result

Load-specific degradation the probe does not cover

To check the engine, watch the prefill and generation counters together with the active requests. If there is pending work and no progress for an interval that is abnormal for your load, find out whether it is saturated or stuck. If the engine is idle, use a small synthetic request to check that it can generate.

Probes have to tell an instance still loading weights from one that has stopped responding. In Kubernetes, a startup probe can protect start-up; the readiness probe controls whether traffic is admitted; the liveness probe can recover a stuck process. Avoid restarting healthy instances because of a long queue: tune timeouts, require consecutive failures and limit automatic restarts.

Also run synthetic checks through the same API your users call, with least-privilege test credentials. Verify that there is a useful response and that it comes from the expected backend or model, using reliable routing metadata. An HTTP 200 obtained through a silent fallback does not prove the original model works.

Symptom

Possible causes

First action

HTTP 200 with no generation

Stuck engine or slow prefill

Cross-check progress, queue and errors

Growing queue

Demand above capacity

Limit admission or add capacity

High TTFT p95

Routing, prefill, queue or network

Split times by phase and backend

Recurring CUDA errors

Driver, GPU or kernel

Take the backend out and diagnose

Invalid tool calls

Incompatible template or parser

Reproduce with a compatibility test

Alert as well when metric series disappear or expected counters stop increasing. And give every critical alert an owner.

Sending a notification to a chat channel is not an on-call system.

High availability: redundancy is per model

Having ten GPUs does not mean having ten replicas. If a model needs four GPUs to run and you only have one group of four serving it, losing that group means losing the model, even if the rest of the fleet keeps working.

Redundancy is per model

Model A: two independent backends

50 %
model capacity
Backend 1 Down
Backend 2 OK

Available Keeps serving, if it has the capacity

Model B: one backend across four GPUs

0 %
model capacity
Backend Down

Unavailable One GPU fails and the whole backend stops

Splitting a model across GPUs (tensor parallelism) is not replicating it. Availability depends on capacity and failure domains.

For each model, decide what happens when a backend fails: is there an independent replica with enough capacity? Is a temporary error acceptable? Can you use another model? Falling back to a different model can change quality, capabilities, licence or the data-processing perimeter. Do not turn it on without an explicit policy.

Session affinity deserves special attention. Sending all of a user's requests to the same backend can improve prefix reuse, but agents with long contexts can pile the work onto a few nodes while others sit idle. Routing has to balance cache locality, pending tokens, capacity and latency. Counting requests is not enough when one carries 2,000 tokens and another 225,000.

High availability also covers the gateway, the ingress, storage and the control plane. If you use Kubernetes with an etcd-based control plane, design the quorum and failure domains so you can lose a member without interrupting it. Keep a single source of truth for the configuration and test restoring it.

Several replicas protect you from losing a process; they do not protect you from a faulty configuration rolled out to all of them at once. Roll out changes gradually and check that routes and models are still available after each change.

Security and privacy

Before you feed in customer information, private code or internal documentation, draw the full path of a request. The GPU is not the only place data is processed: it also passes through the gateway, the observability components and possibly external systems.

  • Access: API keys with least privilege, rotation, per-team limits and separation between administration and inference.
  • Isolation: network segmentation, tenant separation according to risk and review of possible exposure channels between users, including cache reuse.
  • Retention: an explicit policy for prompts, responses, traces, errors, caches and backups. Avoid logging sensitive content by default.
  • Supply chain: pin weight revisions, verify integrity and provenance, review licences and avoid running code from untrusted repositories.
  • Operations: secrets management, security updates, access auditing and incident response procedures.

For an air-gapped environment, also document how weights and container images get in, how you verify their artefacts, how you distribute patches and how you investigate a failure without sending information outside. If an application uses tools, RAG or external services, review those flows separately: hosting the model locally does not automatically isolate the whole application.

Security depends on the complete architecture and on the obligations that apply to your organisation, not on the server being physically close.

How to upgrade engines and models without interrupting the service

Our procedure for changing an engine, model or driver is to work on one backend at a time. If the rest of the infrastructure cannot absorb the load, you need extra capacity or an agreed maintenance window.

Update one backend at a time

The model’s fleet

Backend 1 v1
Out of routing
Backend 2 v1
Serving traffic
Backend 3 v1
Serving traffic
2of 3
backends get traffic

SLOs and tests OK?

Without enough capacity in the other backends there is no update without downtime: you need more capacity or a maintenance window.

With this procedure we moved the fleet from FP8 to NVFP4 node by node, without losing requests. The procedure, however, does not prevent every failure.

A ten-minute test that missed a once-an-hour failure

During that migration, a configuration passed a ten-minute load test. Once in production, the engine crashed roughly once an hour. The cause was a cuDNN bug, identified through a GPU core dump.

The test was not wrong for being short. What was wrong was using it as proof of stability over much longer periods. The length of a test should match the kind of failure you are looking for and the level of risk you can take. A canary and sustained observation are still needed even when the benchmark went well.

OpenAI compatibility is more than the endpoint

Two engines can expose /v1/chat/completions and behave differently with the same request. Chat templates and reasoning or tool-call parsers can change between versions, and even vary between models served by the same engine.

After upgrading, test streaming, cancellations, reasoning parameters, system messages, structured JSON and tool calls where they apply. A normalisation layer in the gateway can help, as long as it does not silently change the meaning of the request. Keep regression tests per model and client.

Manage configuration and deployments as code. Validate the applied result, not just the file you sent. Review versions and configurations periodically, along with capacity per model.

Keeping hardware idle indefinitely is not an availability policy: it is a cost that has to be justified.

What it costs to self-host an LLM

There is no universal price per million tokens. There is the cost of running a specific configuration and the useful volume you manage to serve with it.

Take the example from our analysis of GLM-5.2 in FP8 on a rented node of eight H200s:

Item

Assumption

Monthly cost

Hardware

8 rented H200s

€21,500

Staff

0.5 full-time equivalent, at €90,000/year fully loaded

€3,750

Subtotal

Hardware and operating effort

€25,250

Half a full-time equivalent does not mean you have round-the-clock on-call cover. Nor is it a complete infrastructure budget: depending on the case, storage, network, redundant capacity, setup, support and other expenses are missing.

In the benchmark cited, that node reached 17,993 tokens per second with SGLang, using 64 concurrent requests, 8,192 input tokens and 1,024 output tokens. Extrapolating that figure to 30 days of continuous operation gives about 46,638 million tokens. We round it to 47,000 million for the economic exercise.

These are aggregate tokens, input and output, at that fixed 8,192-to-1,024 ratio. Since input and output are priced differently and your traffic will not have the same mix, the figure cannot be compared as is with an API's price per token.

Partial cost per million tokens by volume served

Monthly volume
20,000M tokens
Partial cost per million
€1.26
Of the theoretical maximum
43%
See the data
Monthly volume (millions of tokens)Partial cost per million
5,000 €5.05
10,000 €2.53
20,000 €1.26
30,000 €0.84
47,000 (theoretical, rounded) €0.54
Calculated, not measured: €25,250 a month (8 rented H200s and 0.5 people) divided by the volume. The maximum extrapolates a benchmark to 30 days without a break. Source: the cost analysis of self-hosting open models.

The last scenario is not a realistic forecast of sustainable capacity: it leaves no room for maintenance, peaks or latency misses.

In production what matters is the capacity that meets your SLOs, not the extrapolation of the best benchmark.

To compare with an API, work out the spend with your real distribution of uncached input, cached input and output tokens. Use the same model, quality and service requirements in both options. Include the cost of every replica you need, and do not confuse GPU occupancy with the share of theoretical throughput you can actually use.

Compare your cost with an API

The monthly cost of running your configuration against an API with the same quality, the same SLOs and the same caching policy. Enter your own figures: no API prices are preloaded.

Self-hosting (€/month)

€
€
Other costs and setup
€
€
€
€

Monthly volume (millions of tokens)

M
M
M
More settings
M
At 0 capacity is not checked.

API prices (€ per million)

€/M
Enter the prices of the API you compare against: none are preloaded here.
€/M
€/M
Self-hosting per month €25,250
API per month Not calculable
Difference (self-hosting − API)
Not calculable
Effective self-hosting cost per million
Not calculable
Weighted API price
Not calculable
Break-even volume for this mix
Not calculable

Hardware and people come from the article's example (8 rented H200s and 0.5 people); the rest starts empty. Whatever you leave out does not count: support, on-call, licences, power if you own the hardware. What you type never leaves your browser.

A mid-sized model that fits on a single card can change the hardware cost a lot. It does not cut the monitoring, security and maintenance work in the same proportion. That is why a company that already runs GPUs has a different break-even point from one starting from scratch.

We go through this calculation in more detail in the cost analysis of self-hosting open models. If your priority is to cut spend without building your own infrastructure, see also the AI cost optimization guide.

Checklist before going to production

Use this list as a launch review. Each point should have an owner and, where it applies, evidence.

Checklist before going to production

Capacity and performance
Architecture and availability
Observability and operations
Security and economics

Build it yourself or delegate the operation

If you have an experienced team, a load that justifies it and requirements that call for controlling the deployment, running your own models can be a good decision. You can build much of the stack with open tools: vLLM or SGLang, a gateway, Prometheus or VictoriaMetrics, Grafana and, when it makes sense, Kubernetes and CloudNativePG.

If you do not know your load yet, start by measuring. You do not need to commit to a fleet to find out which models your teams use or how much context they need.

At Helmcode we work with open models and offer access through an OpenAI-compatible API on European infrastructure. If you are evaluating a private or dedicated architecture, we can work through the capacity, security and operating requirements with you; these are our deployment options.

Explore open models and their capabilities or talk to our team about your use case.