Autoscaling LiteLLM on requests and tokens per second: when CPU is not enough
A CPU target alone can leave a shared LiteLLM gateway under-provisioned, because the gateway's load follows request volume and token throughput, not only how hard the processes work. The high-throughput guide's example combines Horizontal Pod Autoscaler metrics for requests per second (RPS), tokens per second (TPS), CPU and memory in one HPA. The example targets 83 requests and 6.25 million tokens per second per pod alongside its CPU and memory targets, and the HPA uses whichever metric asks for the most replicas. That means any single signal can add capacity, but none of them removes capacity while another still asks for it. Teams should consider this setup when many applications, developer tools or batch jobs share one gateway and their traffic arrives in bursts that CPU lags behind, or when long prompts make token volume a better predictor of load than request count.
The HPA only sees RPS and TPS if the cluster exposes them, which takes more than the HPA manifest itself. The high-throughput guide requires the microservices Helm chart 1.104.2 or later, external PostgreSQL and Redis, Kubernetes 1.30 or newer, Metrics Server, Prometheus Operator and Prometheus Adapter with RPS and TPS rules. Confirm each of these in your own cluster before editing the HPA, and confirm that the Prometheus Adapter rule names match the metric names your HPA references, since a mismatch typically shows up as an HPA that never scales. Confirm the exact versions and rule definitions against the LiteLLM high throughput guide rather than copying values from older examples.
Plan the target values as a measured decision, not a copied number. The 83 RPS and 6.25 million TPS figures come from the guide's example and describe its own test setup, so your gateway's per-pod capacity may be very different once your providers, prompt sizes and streaming mix are in play. Load test the gateway first, then set targets below the point where latency starts to climb, and review them after each LiteLLM upgrade. Remember that the guide's per-pod values assume four workers per pod, so changing worker count changes what a single pod can sustain.
How request and token metrics reach the HPA
The path starts with the LiteLLM pods, which expose request and token metrics on their metrics endpoint. Prometheus scrapes those pods through service discovery, and the Prometheus Adapter turns the RPS and TPS series into custom metrics served through the Kubernetes metrics API. The HorizontalPodAutoscaler then reads CPU, memory and custom metrics together and applies whichever one asks for the most replicas. Check that each hop returns the metric names your adapter rules expect, because a missing series usually shows up as an HPA that quietly stops scaling.
Metric path from LiteLLM pods to the HPA's replica decision.
Scaling signals and HPA settings and when each fits
This table compares CPU, memory, requests per second and tokens per second as HPA signals for the LiteLLM gateway, along with scale behaviour settings. Read the per-pod values from the high-throughput example as a starting reference that you recalibrate against your own load tests, workers and resource requests.
| Signal or setting | What it measures or controls | When it fits and what to watch |
|---|---|---|
| CPU utilization | Average CPU use across pods relative to requested CPU | Reasonable baseline for proxy overhead, but it can lag behind request bursts and may not reflect token-heavy or streaming traffic. Confirm the CPU request you set matches measured use. |
| Memory utilization | Average memory use across pods relative to requested memory | Useful as a guard against memory growth from large payloads or worker buildup. Memory often rises and falls slowly, so it rarely triggers scaling fast enough on its own. |
| Requests per second per pod | Gateway request rate divided by ready pods, exposed through a Prometheus Adapter rule | Fits traffic made of many short calls. Requires a correct adapter rule and a per-pod target from your own load test, since the example value of 83 is a reference only. |
| Tokens per second per pod | Token throughput per pod, exposed through a Prometheus Adapter rule | Fits workloads where a few long completions dominate capacity. The example target of 6.25 million tokens per second per pod depends on the example hardware and model mix, so validate it before use. |
| Workers per pod | Uvicorn worker processes inside each container, multiplying per-pod concurrency | Changes how much traffic one pod absorbs, so per-pod targets must be measured with the same worker count. The high-throughput values use four workers per pod, and the production guide recommends one worker per pod on Kubernetes. |
| Resource requests | CPU and memory reserved per pod, which HPA utilization percentages are calculated against | Lower requests make utilization percentages rise sooner and scale earlier. The high-throughput values request 4 vCPU and 16 GiB per pod with a 16 vCPU limit, so changing them shifts every CPU and memory target. |
| Scale up behaviour | How fast replicas are added when a metric exceeds its target | Set a short stabilization window and a generous per-period increase so bursts are absorbed. Test against ramp-up in your load profile, because new pods need time to become ready. |
| Scale down behaviour | How slowly replicas are removed after load falls | Use a longer stabilization window so streaming and bursty traffic do not cause flapping. Pods removed mid-stream can break in-flight requests, so confirm graceful termination settings. |
Configure the HPA and Prometheus Adapter rules in order
This sequence takes a cluster from the prerequisites for LiteLLM's high-throughput setup to an HPA that scales the gateway on requests per second, tokens per second, CPU and memory. Each step ends with a check so you know the layer below it works before you build on it.
Confirm chart and Kubernetes prerequisites
Confirm that you will deploy the LiteLLM microservices Helm chart at version 1.104.2 or later, that the cluster runs Kubernetes 1.30 or newer, and that PostgreSQL and Redis are external to the gateway pods. Check the Kubernetes version against the supported minor releases on the Kubernetes releases page before you pick a cluster version. Done means you have written down the chart version, the cluster version and the external database and Redis endpoints, and each one meets the minimum in the high-throughput guide.
Install Metrics Server and Prometheus Operator
A platform engineer installs Metrics Server, which provides the CPU and memory metrics the HPA reads, and the Prometheus Operator, which runs Prometheus and scrapes the LiteLLM pods through a ServiceMonitor or PodMonitor. Confirm that Metrics Server answers resource queries and that Prometheus shows the LiteLLM targets as up before you go further. Done means
kubectl top podsreturns CPU and memory for gateway pods and the LiteLLM scrape target appears healthy in Prometheus.Install Prometheus Adapter
Install Prometheus Adapter so Kubernetes can serve custom and external metrics from Prometheus. Point it at the Prometheus service the Operator created. The adapter is the component that exposes derived series to the HPA, so this step is complete only when the custom metrics API responds. Done means
kubectl get --rawagainst the custom.metrics.k8s.io API returns a discovery list without errors.Write RPS and TPS adapter rules
Write Prometheus Adapter rules that turn the gateway's request and token counters into per-pod rate series, one for requests per second and one for tokens per second. Take the exact metric names from the LiteLLM metrics endpoint in your running version, because rules that reference a name the gateway does not emit will return no data without an obvious error. Use the example rules in the high-throughput guide as the starting point and rename the series to match your naming. Done means a PromQL query for each derived series returns a value per pod while you send test traffic.
Set resource requests from the high-throughput values
Set each gateway pod to run four workers, with 4 vCPU and 16 GiB requested and a 16 vCPU limit, which are the values the high-throughput setup uses. Keep one Uvicorn worker per pod only if you follow the production guide's single-worker layout instead, and do not mix the two models. Resource requests drive HPA utilization percentages, so an incorrect request makes the CPU and memory targets meaningless. Done means
kubectl describe podshows the requests and limits you set, and the worker count matches the chart values.Configure the HPA with CPU, memory and custom metrics
Create the HorizontalPodAutoscaler with CPU, memory, and the custom RPS and TPS metrics as separate targets. Kubernetes computes a replica count for each metric and uses the highest result, so one metric that saturates first sets the pace. Start with the per-pod targets from the example HPA and treat them as a starting point to confirm in your own load test, not production values. Done means
kubectl get hpalists all four metrics with current values and no unknown readings.Tune scale up and scale down behaviour
Set the HPA behavior block so scale up responds quickly to traffic bursts while scale down waits longer, which avoids flapping when load falls between requests. Choose stabilization windows and policies for both directions, and record the values with the reason for each. Confirm that the minimum and maximum replica counts fit the database connection budget and the Redis capacity you planned. Done means the HPA spec contains explicit behavior settings and a test run shows the expected pattern.
Verify scaling under a load test
Run a load test against a fake model endpoint so provider limits do not cap throughput, then watch
kubectl get hpa -wand the custom metrics API while the ramp runs. Confirm that replica counts rise when RPS or TPS crosses its target, that the metric which drove the change matches your expectation, and that replicas fall after load drops and the stabilization window passes. Done means you have a recorded sequence of replica changes tied to the metric that caused each one, and any metric that never moved is fixed before go-live.
How workers per pod change the replica math
The high-throughput values run four workers per pod, with 4 vCPU and 16 GiB requested and a 16 vCPU limit, which is a different unit of capacity from the single Uvicorn worker per pod that the production guide recommends on Kubernetes. Each pod now serves roughly four times the traffic of a one-worker pod, so an HPA target such as the example's 83 requests per second per pod only means something for the same worker count and resource profile. If you raise workers, lower the per-pod request, or change the CPU request, the HPA will compute a different replica count for the same load. Confirm the worker count and resources in your rendered Helm values before you copy any per-pod number from the guide.
Worker count also multiplies shared dependencies. Every worker opens its own database connections, so a pod with four workers holds roughly four times the PostgreSQL connections of a single-worker pod, and replica count multiplies that again. Rate limit and router state live in Redis once more than one instance runs, so each additional worker adds Redis traffic too. Ask your team to compute total connections as pods times workers times pool size, and check that the result fits the PostgreSQL max_connections budget and the connection pooler in front of it before the HPA is allowed to scale out. Fewer, larger pods reduce the number of connection pools and Redis clients, but they also make each pod failure remove more capacity and make scale-out steps coarser. More, smaller pods give finer scaling and smaller failure domains, at the cost of more connections and more scheduling overhead.
Treat every per-pod target as a measured value, not a constant. When the worker count, CPU or memory request, or the LiteLLM release changes, repeat a load test on one pod and record the requests and tokens per second at which latency and error rates still meet your objective. Then set the Prometheus Adapter thresholds from that measurement. Confirm the exact worker setting, such as the one your chart exposes, against the LiteLLM high throughput guide for your chart version, and record which values produced each target so a later upgrade does not silently shift the replica math.
Security and operational risks of metric-driven scaling
Scaling on requests and tokens per second adds a metrics pipeline, cluster permissions and shared state to the gateway. Each of these components holds something sensitive or affects availability, so the risks below should be checked before the HPA goes into production.
Keep the master key in a secret manager
The LITELLM_MASTER_KEY must start with sk- and grants administrative access to the gateway. Autoscaled pods start and stop often, so the key must never be baked into an image or written into a values file in plain text. Confirm that the key is injected from an external secret manager into each new pod, that rotation does not require a redeploy of every replica, and that access to the key is logged.
Production guideRestrict RBAC for the metrics adapter and HPA
The Prometheus Adapter and the HPA controller read custom metrics through the Kubernetes API. Grant each of them only the get and list rights on the metric resources they need, bound to a dedicated service account in the namespace of the gateway. Review any cluster-wide ClusterRole that the adapter chart creates, because broad read access to pods and secrets in other namespaces would widen the blast radius of a compromised adapter.
Encrypt Secrets at rest in etcd
Kubernetes stores Secrets unencrypted in etcd by default. The gateway's database credentials, Redis password and master key all live in these objects, so anyone with access to etcd snapshots or backups can read them. Configure encryption at rest on the API server, restrict list and watch on Secrets with least-privilege RBAC, and consider an external store through the Secrets Store CSI Driver. Confirm that etcd backups are encrypted too.
Secrets good practicesPlan Prometheus as single-node storage
The metrics that drive the HPA come from a Prometheus server that stores data on local disk. Local storage is not clustered or replicated, so a failed Prometheus instance means the adapter has no fresh RPS or TPS values. Decide whether the Prometheus setup needs a replica, and confirm what the HPA does when metrics are missing. Remote write to external long-term storage is an option for retention, not for failover by itself.
- Default retention
- 15 days
Do not bill from Prometheus metrics
Prometheus values reliability over precision and is not a good choice where 100% accuracy is required, such as per-request billing. Scaling decisions tolerate sampled and approximate token rates, but spend and chargeback must come from the gateway's own spend records. Keep budget enforcement on virtual keys in the gateway database and treat the scrape-based rate as a capacity signal only.
Require Redis 7.0 for shared state
With one replica, the gateway can hold rate limits and router state in memory. Once more than one instance runs, shared rate limits, router state and cache need Redis 7.0 or newer. An HPA that adds replicas without a shared Redis gives each pod its own view of TPM and RPM limits, so limits drift as traffic moves. Confirm the Redis version, its high availability setup and its memory sizing before setting the maximum replica count.
Production guideQuestions teams ask before scaling LiteLLM on requests and tokens
What does it cost to set up autoscaling for LiteLLM, and what drives the effort?
The cost is mostly the engineering time to build the autoscaling path, plus the platform components it depends on. The main drivers are how mature your Kubernetes cluster already is, whether you already run a Prometheus stack with a metrics adapter, and how wide the load test scope must be. The high-throughput setup expects Kubernetes 1.30 or newer, external PostgreSQL and Redis, Metrics Server, Prometheus Operator and Prometheus Adapter with RPS and TPS rules, so each missing component adds work. Ask any partner for a written scope that lists which components are already present, which must be built, and which load profiles will be tested. Those three lists explain most of a quote.
Can our own platform team set up HPA scaling on requests and tokens without a partner?
Yes, if the team already operates Kubernetes, Prometheus and a metrics adapter. The work is well defined: write Prometheus Adapter rules that expose requests and tokens per second as custom metrics, set HPA targets alongside CPU and memory, tune scale-up and scale-down behaviour, and set workers per pod and resource requests. The harder parts are validating the targets with a realistic load test and proving that scale-down does not disrupt traffic. Teams new to Prometheus Adapter often spend their time on metric naming and label mapping rather than on the HPA itself. A partner is most useful when the team lacks load testing experience or needs the result documented for an internal review.
What do we need to provide before the work starts?
You need access to the cluster and the namespace where LiteLLM runs, with rights to install or inspect Prometheus Adapter rules and HPA objects. You also need the metric names that the gateway emits, because the adapter rules must map them to request and token rates per pod. Provide the current Helm values, the database and Redis setup, and the expected load profile: request rates, prompt and completion sizes, and the share of streaming traffic. Without a realistic load profile, the per-pod targets cannot be justified. Confirm these items in the scope document so the first week is not spent gathering access.
How long does this take, and what makes it longer?
No fixed duration can be given here without the cluster and load profile in front of us. Duration depends mainly on whether the prerequisites are already in place, how many metrics need adapter rules, how many load test rounds are needed to settle the per-pod targets, and how many environments must be covered. Teams that already run the full Prometheus and adapter stack typically move faster than teams building it from scratch. Ask for a schedule in the written scope with milestones for prerequisites, adapter rules, load testing and sign-off, and check that each milestone has a named owner on both sides.
Can HPA scale-down drop in-flight streaming responses?
It can, if scale-down removes a pod while it still serves long streaming responses. Kubernetes terminates pods gracefully, but a streaming completion can run for a long time, so the termination window and the scale-down behaviour must be set with that in mind. Limit how fast replicas are removed in the HPA behaviour section, allow enough termination grace time for long streams, and test scale-down under a streaming-heavy load profile before go-live. Also confirm that clients retry safely when a connection closes early. Results depend on your provider latency and prompt sizes, so measure them rather than assuming a default.
Which HPA metrics should we use, and how do we choose the targets?
Use requests per second and tokens per second alongside CPU and memory, because the HPA scales on whichever metric asks for the most replicas. The reference HPA in the LiteLLM high-throughput guide uses 83 requests and 6.25 million tokens per second per pod, along with CPU and memory targets. Treat those figures as a starting point for that reference setup, not as targets for your cluster. Your per-pod targets depend on workers per pod, the resources you request, the provider mix and the payload profile. Derive your own targets from a load test on the same resources you plan to run.
When does a retainer make sense for ongoing autoscaling tuning?
A retainer makes sense when traffic changes often enough that targets, workers per pod or resource requests need regular review, or when your team cannot staff continuous load testing. LiteLLM publishes a supported release line, and upgrades can change metrics, so the adapter rules and HPA targets may need checking after each upgrade. DeployOpen offers ongoing support, upgrades and continuous testing as retainers, with scope agreed in writing. Compare the retainer scope with the one-time build scope so you pay for recurring testing and upgrade review, not for work your team already does well.
How to prove the autoscaling rules work under load
Treat the HPA settings as a hypothesis until a load test shows they hold. The two traffic shapes must be tested separately: one run that raises request count with small prompts, and one that keeps request count modest but raises tokens per second with large prompts and long completions. If you only push one dimension, you will not know whether the requests per second rule or the tokens per second rule is the one that adds replicas, and a target that looks correct for one profile may be far too loose or too tight for the other. Use a fake provider endpoint so that upstream rate limits do not decide the result, and keep the gateway's own worker count and resource requests fixed for each run so that changes in replica count are attributable to the metric you are testing.
During each run, watch four things together: the replica count the HPA reports over time, the per-pod value of the custom requests and tokens metrics compared with the targets in the HPA, gateway latency at the percentiles your service levels use, and PostgreSQL connection counts. Scaling out adds pods, and each pod opens its own database connections, so a rule that scales correctly can still exhaust the database. Confirm how many connections your PostgreSQL setup allows before you raise maximum replicas, and check whether the stabilization window on scale down is long enough to avoid replica churn when load drops. Record the pod count at which latency starts to rise, since that point, not the target value, is the real capacity limit.
Adjust targets only after you have a clear reading from both runs, and change one value at a time. For load-test design, see the sibling topic on Locust-based load testing for LiteLLM and the sibling topic on diagnosing LiteLLM latency overhead, which explains whether added latency sits in the gateway, in queueing or in the provider. Confirm the exact metric names and HPA fields your Prometheus Adapter rules expose before you start, because a metric that is missing or reports zero will make the HPA fall back to CPU and memory without any visible error.
How DeployOpen scopes and delivers LiteLLM autoscaling
DeployOpen plans, builds and hands over the autoscaling setup for a self-hosted LiteLLM gateway inside your own cluster, starting from a written scope. The work covers the HPA, the metrics pipeline that feeds requests and tokens per second, and the load evidence that shows the settings hold under your traffic.
How we scope
- We confirm the cluster versions, Metrics Server, Prometheus Operator and Prometheus Adapter state before any values change.
- We agree which metrics drive scaling, the replica bounds, and the per-pod targets for requests and tokens per second.
- Engagements are fixed-scope, with deliverables and timelines written down before work starts, and ongoing support available as a retainer.
How we build
- We write the Prometheus Adapter rules that expose RPS and TPS as custom metrics the HPA can read.
- We set scale up and scale down behaviour, workers per pod and resource requests against your measured load profile.
- We run load tests that ramp traffic, confirm which metric drives replicas, and check that scale events do not drop requests.
How we hand over
- We deliver the Helm values, HPA and adapter manifests as code, with a record of the tests that justified each setting.
- We document the metric names, alert thresholds and the steps to change a target without breaking the autoscaler.
- We walk your platform and SRE teams through the runbook so they can tune targets after go-live.
How we support
- Retainers cover LiteLLM and chart upgrades, metric rule changes and periodic retesting as traffic and model mix change.
- We review scaling events and Prometheus data with your team when replica counts behave unexpectedly.
- Confirm with us the support hours, response expectations and change process that fit your environment before signing.

