Why LiteLLM latency is hard to diagnose and where the time goes
When users report slow AI responses through a self-hosted LiteLLM gateway, the first decision is which layer to examine: the model provider, the gateway's own request handling, or the time a request waits before the gateway starts handling it. Time can accumulate in all three. The provider spends time generating the answer. The gateway handler spends time on authentication, routing, budget checks, payload parsing and logging. Before that handler runs, the request may wait in the Uvicorn event loop behind other work, and nothing in the gateway's normal logs records that wait. LiteLLM measures latency from the moment its handler starts, so its own logs only see the middle layer. That is why a gateway can report healthy timings while callers still wait.
The gateway gives you two early signals. Every response carries an x-litellm-overhead-duration-ms header with the latency the gateway added, which separates gateway time from provider time for requests you can inspect. For the queueing layer, /health/backlog and the litellm_in_flight_requests gauge show how many requests each pod is holding at a given moment. Confirm both are reachable from your monitoring before go-live, because a queue problem that appears only during an incident is hard to reconstruct afterward. Check whether your load balancer or ingress also reports request time, since a gap between its numbers and the gateway's numbers points to waiting upstream of the pod.
Work through this diagnosis before you add replicas, before a go-live load test and during any latency incident. Adding pods to a queue-bound gateway spreads the problem without removing it, and adding pods to a provider-bound gateway adds cost without speeding responses. Agree in advance which signals each team reads, who owns the provider account and who owns the gateway, and what evidence you collect before escalating to the provider or to LiteLLM support. Ask your team to confirm the exact header name, gauge name and endpoint against the version you run, because these depend on the release in your environment.
Provider, gateway or queue: the three places latency hides
A slow response can be spent in four or more places: the provider, the gateway's own handler, the pod's event loop before the handler starts, or the network path in front of the pod. Each leaves different evidence, so the cards below pair every component with what points to it and what it will not show you.
Provider inference and network
Time the model spends generating tokens, plus the round trip from the gateway to the provider endpoint. Long prompts, large outputs and provider-side rate limiting all land here. The gateway header reports only the latency the gateway added, so a slow response with a small header value usually points upstream. It does not separate queueing at the provider from generation time, so compare against a fake OpenAI endpoint in a test before blaming the provider.
Gateway handler work
Auth checks, virtual key lookups, budget and rate limit checks, routing, request translation and spend logging all run inside the handler. The x-litellm-overhead-duration-ms header on each response reports this added time, so compare it across models and keys to see which routes cost more. It does not show time spent before the handler starts, and a low value does not prove the gateway is fast under load.
DEBUG logging and large payloads
DEBUG logging writes request and response bodies, which becomes expensive as prompts grow. LiteLLM names it as the top cause of latency with large payloads. Check the log level in the deployment config and environment variables first. If overhead rises with prompt size and falls when the level is raised, logging is the likely cause. Confirm the current logging settings against the version you run, since they change between releases.
Base64 attachment size
Images and files sent as base64 inflate the request body by about a third and must be parsed, validated and sometimes forwarded again. Overhead that tracks attachment size rather than token count points here. Test with the same prompt text, once with a URL or file reference and once with inline base64, to isolate the cost. Be aware that the header covers gateway work only, so a large body can also slow the provider and the network leg.
Queueing in Uvicorn before the handler
Requests can wait in the Uvicorn event loop before LiteLLM's handler starts its timer, so logs and the overhead header miss this time entirely. Check /health/backlog and the litellm_in_flight_requests gauge per pod. Rising in-flight counts with flat handler timings mean the pod is saturated, not that the gateway logic is slow. Compare in-flight requests per pod against the worker count before adding replicas.
Load balancer and ingress time
Time spent at the ingress controller, load balancer, TLS termination or connection reuse sits outside the gateway's own timers. Uneven spread across pods, idle connection resets and slow TLS handshakes all show up here. Compare client-side timings with gateway logs for the same request IDs. Load balancer metrics show queue depth and backend response times, which the gateway cannot report, so collect them from the platform team's tooling rather than assuming the gateway sees them.
How to isolate the slow layer step by step
This sequence narrows a slow response to the provider, the gateway, or the queue in front of the gateway, so the team fixes the layer that actually adds the time.
Confirm the symptom by caller and model
Start by pinning down which callers, keys, models and routes report slow responses, and whether the slowness is constant or tied to certain times. Pull client-side timings for a few representative requests from each affected caller, and record the model and route name for each. The step is done when you can say whether the problem is limited to one model, one team or one route, or spans the whole gateway. If every model is slow for every caller, suspect shared infrastructure such as the database, Redis or the load balancer before looking at the provider.
Compare the overhead header with client-observed time
Every LiteLLM response carries an x-litellm-overhead-duration-ms header that reports the latency the gateway itself added. Capture this header alongside the total time the client measured for the same requests. If the client time is high but the header is small, the extra time sits outside the gateway's handler, either in provider response time, in network hops, or in queueing before the request reached LiteLLM. If the header is large and grows with the client time, the gateway is adding the latency, and the next steps focus on it.
Check in-flight requests and backlog per pod
LiteLLM measures latency from the moment its handler starts, so time spent waiting in Uvicorn's event loop does not appear in its own logs. Check the litellm_in_flight_requests gauge for each pod and query /health/backlog on each pod to see requests waiting to be handled. Work through the pods one by one, since a single overloaded pod can hide behind a healthy average. If a pod shows a growing backlog while its in-flight count is high, the delay is queueing before the gateway handler, and you should review replica count, worker settings and traffic distribution. If backlog is empty and the header is small, the gateway is not the bottleneck.
Check DEBUG logging and payload size
Confirm that the gateway is not running at DEBUG log level in production, because LiteLLM identifies DEBUG logging as the top cause of latency with large payloads. Review recent request sizes for the slow routes, particularly long prompts, large tool outputs and base64 attachments embedded in the request body. Compare latency for small and large payloads on the same model. If the slow requests are the large ones and logging is verbose, reduce the log level and re-run the same comparison. The step is closed when the log level is confirmed and payload size either explains the slowdown or has been ruled out.
Review load balancer metrics
Last, check the load balancer or ingress in front of the gateway. Compare request count, active connections, response time and error rate at the balancer with the same figures reported by the gateway pods for the same window. A large gap between balancer response time and gateway-reported overhead points to time spent in the balancer, in TLS termination, or in connection handling. Confirm with your platform team what the balancer's timing metrics actually measure, since definitions differ between products. The step is complete when each layer has either been shown to contribute time or has been ruled out with a matching measurement.
Record the layer and the evidence
Write down which layer accounts for the slow responses, with the header values, gauge readings, backlog counts, log level and balancer figures that support the conclusion. Include the caller, model and time window for the reproduction. If the cause is the provider, the next step is a provider-side conversation supported by the timings, and the gateway is working as intended. If the cause is the gateway or queueing, the evidence sets the baseline for the scaling and configuration changes that follow. Keep the record with the incident notes so the same sequence can be rerun after a change.
Where each timing signal is measured in the request path
The request starts at the client and passes through the load balancer or ingress, then waits in the Uvicorn event loop before LiteLLM's handler starts. LiteLLM's handler-start timer begins only at that point, so queueing before it never appears in the gateway's own logs. The x-litellm-overhead-duration-ms header covers the time the gateway adds inside its handler, while the litellm_in_flight_requests gauge and /health/backlog show requests still waiting in the pod. Compare load balancer timings with these signals to find where the delay sits.
Timing signals observe different segments of one request path.
Which signal to read for each symptom
Slowness that appears only with large prompts, long conversations or base64 attachments usually points at the gateway's handling of the payload rather than at the provider's model. Payload size changes how much work the gateway does before and after the upstream call, so a gap that grows with request size is the pattern to look for.
- Check the overhead header first: Compare the
x-litellm-overhead-duration-msvalue on small and large requests to the same model. A large difference confirms the gateway is adding time. - Look at debug logging: Confirm that DEBUG logging is off in production. LiteLLM names it as the top cause of latency with large payloads.
- Separate attachments from text: Test a text-only prompt of similar token count against a base64 attachment. If only the attachment is slow, the cost is in encoding and transfer through the gateway.
- Check request body limits and timeouts: Look for proxy or load balancer limits that truncate or stall large bodies before they reach the gateway.
- Confirm the likely layer: Gateway processing or network transfer, not the provider, when the header stays low while end-to-end time rises.
After these checks, compare the same payloads through a direct provider call to separate gateway cost from upstream cost. Interpretation depends on your own traffic mix and payload distribution.
When every model slows down during busy periods, the cause is more often concurrency on the gateway pods than a single provider. Requests wait in the server's event loop before LiteLLM's handler starts, and that wait is not visible in the gateway's own timing logs.
- Read in-flight requests per pod: Use the
litellm_in_flight_requestsgauge to see how many requests each pod holds at once. Uneven or rising values across pods point at queueing. - Check the backlog endpoint: Query
/health/backlogon each pod to see whether requests are waiting before the gateway starts timing them. - Compare header values with client timing: A low
x-litellm-overhead-duration-msalongside high client-side latency suggests time spent queued before the handler ran. - Review pod count and resource limits: Check whether pods are CPU-bound or memory-bound at peak, and whether autoscaling responded.
- Confirm the likely layer: Queueing in front of the gateway when in-flight counts climb while the header stays low.
These readings depend on your pod sizing, worker count and traffic shape, so record baseline values in a quiet period before comparing peaks.
When one model or route is slow while others are fine, the first question is whether the gateway or the provider behind that route is responsible. A route can add cost through retries, cooldowns or fallback ordering, and the provider endpoint can be slow on its own terms.
- Compare the overhead header by model: Check
x-litellm-overhead-duration-msfor requests to the slow route and to a healthy route. If the header is similar, the gateway is not the main source of delay. - Look for retries and fallbacks: Routing retries, cooldowns and priority failover can add time that appears as one slow model. Review router settings for that model group.
- Check provider-specific settings: Confirm timeouts, region and endpoint configuration for that provider route.
- Test the provider directly: Send the same request to the provider outside the gateway to see its own response time.
- Confirm the likely layer: Provider or routing configuration when the header is normal but end-to-end time is high on only that route.
Route behavior varies by provider and by your configuration, so confirm the current routing settings in your own deployment before drawing conclusions.
Timeouts and errors that rise with load often come from requests that never reach the gateway's handler in time, or from connection and database pressure that builds as traffic grows. The first step is to tell apart requests that failed inside the gateway from those that failed while waiting.
- Check in-flight counts before error counts: A rising
litellm_in_flight_requestsvalue with timeouts at the client suggests requests are queued rather than failing inside LiteLLM. - Match client timeouts to gateway timeouts: Compare client, load balancer and gateway timeout settings. A client timeout shorter than the queue wait produces errors the gateway logs as successes.
- Review database and Redis connections: Check connection counts and errors from the gateway pods, since exhausted connections surface as request failures under load.
- Read load balancer metrics: Compare upstream response times and 5xx counts at the load balancer with the gateway's own logs to locate where requests were dropped.
- Confirm the likely layer: Queueing or connection exhaustion in front of or behind the gateway when errors track in-flight counts.
Whether these signals point to a bottleneck depends on your timeout design and load pattern, so confirm each setting in your own environment before changing it.
Diagnostic signals and settings compared
This table compares the signals and settings you can use to locate LiteLLM latency, and what each one cannot see. Read it by first matching the symptom to a signal that measures the right layer, then checking the blind spot before trusting the number. The main takeaway is that the gateway's own timing excludes time spent queued before the handler starts, so queue-side signals are needed alongside it.
| Signal or setting | What it measures | What it cannot see | When to use it | Risk of leaving it on |
|---|---|---|---|---|
| x-litellm-overhead-duration-ms header | Latency the gateway added to a response, reported per response | Time queued in Uvicorn's event loop before the handler starts, and provider time | Per-request checks comparing gateway overhead with total client latency | Minimal; it is a response header, but confirm your ingress does not strip or log it inconsistently |
| litellm_in_flight_requests gauge | Requests currently in flight on each pod | Why requests are slow, and the provider's own queueing | Spotting pods that hold many concurrent requests while others sit idle | Low; scrape cost only, but watch label cardinality in your metrics store |
| /health/backlog endpoint | Backlog of requests waiting inside a pod | Individual request timing and provider latency | Confirming queueing before the gateway when latency rises without gateway overhead | Low; restrict access, since it reveals operational state about the gateway |
| DEBUG logging | Detailed per-request internals, including request and response bodies | Nothing extra; it adds work to every request | Short, controlled investigations on a single pod with small test payloads | High: LiteLLM names DEBUG logging as the top cause of latency with large payloads, and bodies may contain personal data |
| Base64 attachment handling | Cost and time of decoding and forwarding inline file content | Whether the provider or the network is the slow step | Requests with images, PDFs or other files sent inline | High: large inline payloads inflate parsing, memory use and log size, and may be stored in logs |
| Load balancer and ingress metrics | Request time seen at the edge, status codes and upstream response time | Which gateway internals or queueing caused the delay | Comparing edge latency with gateway-reported timing to find where time goes | Low; confirm retention and whether access logs capture request bodies or headers |
How DEBUG logging and large payloads inflate gateway time
Check the logging settings before you tune workers or pods. LiteLLM names DEBUG logging as the top cause of latency when payloads are large, so a gateway that is slow on long prompts may be spending its time writing logs rather than waiting on anything else. Confirm the log level the proxy runs at in the deployment manifest or configuration, and confirm whether any debug flags are set in the environment. If DEBUG is on in production, that single setting can make every extra worker or replica look like it is not helping, because each one carries the same serialization and logging cost. Scaling out first only spreads that overhead across more pods and makes the bill for logs larger.
Prompt size is the second variable to isolate. Base64-encoded attachments such as images, PDFs and audio are large strings that travel inside the request body, so they add cost at parsing, logging and any step that copies the payload. Build a staging copy of the gateway with the same configuration, route the same model, and send two sets of requests: one with plain text prompts of typical length and one with the attachment mix you expect in production. Run each set with the production log level and again at a lower level, and compare the x-litellm-overhead-duration-ms header across both runs. If the overhead rises with payload size only when DEBUG is enabled, you have found the cause. Record the test inputs, the log level and the gateway version so the result can be repeated after a change.
Logs created at DEBUG level are a data question as well as a performance one. Full request bodies in logs can contain personal data, confidential business text and attachments, and log volume also drives storage cost and retention. Before you enable verbose logging on any shared environment, confirm with the team that owns logs and the privacy function where those records would go, how long they would be kept and who could search them. Ask whether staging logs can contain real prompts at all, or whether synthetic payloads should be used for the comparison. Settle these points first, then choose the logging level that the team that owns logs has approved for production.
Setting up measurement before you change anything
This sequence gives you a version-confirmed, comparable baseline of gateway overhead, queueing and provider time for each model and pod, so later tuning changes can be judged against numbers rather than impressions.
Confirm the deployed LiteLLM version
The platform team records the exact image tag or package version running in every environment, then checks it against the release list on the LiteLLM GitHub releases page. Note whether the deployment is open source or Enterprise, because the support window and upgrade path depend on it. Done means one written version per environment, with the release date of that version noted, and any gap from the newest listed release flagged for a decision before testing starts.
Enable scraping of the in-flight gauge
The operator configures the metrics collector to scrape each LiteLLM pod, including the litellm_in_flight_requests gauge, which shows how many requests each pod is handling at once. Confirm that the series appears per pod label in the time-series store and that the value changes under a small test request. Done means the gauge is visible per pod for at least one full test window, so queue build-up on a single pod can be spotted later.
Check backlog endpoint availability
The operator calls the /health/backlog endpoint on each pod directly, bypassing the load balancer, and records the response alongside the gauge. This shows requests that have arrived at the process but not yet reached LiteLLM's handler, which the handler-based logs cannot show. Confirm the endpoint is reachable from the monitoring network and that a pod under light load reports a near-zero backlog. Done means each pod returns a backlog reading you can compare during load.
Record the overhead header in logs
Every LiteLLM response carries an x-litellm-overhead-duration-ms header with the latency the gateway added. The team confirms which client or gateway log fields capture this header, such as access logs or the calling application's HTTP client, and adds it to the request log format. Send a few test requests to each model and confirm the header value is present and parseable in the stored log. Done means each logged request carries the header value next to its total response time.
Set the production log level
Set the gateway log level to a non-DEBUG value that matches production, and confirm in the running container configuration that DEBUG logging is off. DEBUG logging is named as the top cause of latency with large payloads, so leaving it on would distort the baseline. Check the effective setting from the running process or its environment, not only the configuration file. Done means the effective log level is recorded with the baseline, and any earlier comparison run made under DEBUG is marked as not comparable.
Capture a baseline per model and pod
Run a fixed set of representative requests against each model route and collect, per pod, the total response time, the overhead header, the in-flight gauge and the backlog reading. Group results by model and pod so a slow route or an overloaded pod is not hidden in an average. Store the raw values with the LiteLLM version and log level. Done means a dated baseline table exists that a later change can be compared against, with the same request mix and payload sizes recorded.
Security and privacy risks of detailed latency logging
Detailed logs are the fastest way to see where latency starts, and they are also the easiest way to copy prompts, attachments and credentials into places nobody meant to store them. The cards below cover what a diagnostic capture contains, who can read it, how long it survives and how the master key stays out of the troubleshooting path.
Prompts and attachments in DEBUG logs
At DEBUG level, LiteLLM can write request bodies, which means full prompts, system instructions, retrieved documents and base64 attachments can land in the log stream. Large payloads make this worse, because the same capture that slows the gateway also holds the most sensitive content. Before enabling DEBUG, check which fields your logging configuration emits and whether a sample request with a dummy attachment appears in the output.
Latency troubleshooting guideKeys and tokens in log output
Authorization headers, virtual key values and provider credentials can appear in request dumps or error traces when verbose output is on. A leaked virtual key grants the same model access and budget as its owner until it is rotated. Search captured logs for key prefixes and bearer tokens before anyone shares them, and confirm that redaction covers headers as well as bodies.
Who can read gateway logs
Gateway logs often reach more people than the prompts they contain. Engineers who run the platform, observability vendors, log shippers and support staff may all have read access by default. Map every destination that receives DEBUG output, confirm which roles can query it, and limit the diagnostic window to the engineers actively working the incident.
Retention of diagnostic captures
A capture taken for one slow-response investigation can outlive the investigation by months if it lands in a default retention bucket. Agree in advance where captures are stored, who deletes them and when, and record that deletion as part of closing the incident. Ask your log platform team for the retention setting on each index or bucket that receives gateway output.
Master key handling during troubleshooting
Troubleshooting often pulls engineers into the proxy's admin configuration, where LITELLM_MASTER_KEY grants full administrative control. LiteLLM recommends keeping this key, which must start with sk-, in a secret manager rather than in manifests or shell history. Read it through the secret manager during the session, avoid echoing it into terminals or tickets, and rotate it if it appears in any captured output.
Turning debug logging back off
DEBUG logging is easy to enable on one pod and forget, especially when the change is made by editing an environment variable on a running deployment. Record the exact setting you changed, set a reminder to revert it, and check that the change did not persist into the Helm values or manifests that the next rollout uses. Confirm the revert by checking that the log level in new pods is back to the normal setting.
Questions teams ask before diagnosing LiteLLM latency
What does a LiteLLM latency diagnosis engagement actually include?
A diagnosis separates the time spent at the provider, inside the gateway and waiting in queues before the gateway starts working on a request. In practice it covers reviewing how the gateway is deployed (pods, Uvicorn workers, database and Redis connections), reading the x-litellm-overhead-duration-ms header on sampled responses, checking in-flight request counts per pod through /health/backlog and the litellm_in_flight_requests gauge, and comparing load balancer metrics with gateway metrics. The main effort drivers are how many deployments and models are in scope, whether you have metrics and logs already, how much traffic you can replay, and whether the problem reproduces in a test environment. The scope is agreed in writing before work starts.
Can our own engineers diagnose LiteLLM latency without a partner?
Yes, if you have people who can read Kubernetes metrics, load balancer logs and the LiteLLM proxy configuration. The core method is the same whoever runs it: measure where time is spent before the handler starts, inside the handler and at the provider, then change one variable at a time. The points most teams miss are that LiteLLM's own timers start only when its handler begins, so time queued in the Uvicorn event loop does not appear in gateway logs, and that DEBUG logging on large payloads is a common hidden cost. An outside team usually saves time when the first pass needs repeated load tests in an environment you already run, or when your internal team needs to build a repeatable runbook afterward.
What do we need to provide for a diagnosis?
Plan to provide access and samples in four groups: deployment details, telemetry, traffic and configuration. Deployment details include the container image version, the number of pods, the Uvicorn worker count per pod, and how PostgreSQL and Redis are connected. Telemetry includes gateway and load balancer metrics for the slow period, plus access to response headers from sampled requests. Traffic samples should show the prompt sizes, streaming share and model mix, with attachments noted, because base64 attachments inflate payloads in ways synthetic tests miss. Configuration means the proxy config file with secrets removed and the routing settings. Ask your security team early about how logs with prompt content will be handled, since prompts may contain personal data.
How long does a latency diagnosis take?
Duration depends on scope and environment, and no fixed figure applies to every gateway. The main drivers are how many models, providers and environments are involved, whether production-like load can be reproduced in a test environment, how quickly access to metrics and logs is granted, and whether the cause is a single setting or several interacting limits. A narrow scope on one cluster with existing dashboards takes less time than a multi-region gateway with unclear telemetry. Ask for a written timeline that separates the investigation, the fix and the verification retest, and ask what each phase depends on from your side.
What usually changes after a latency fix?
Typical changes are worker layout, database connection limits, Redis configuration and autoscaling thresholds. Running one Uvicorn worker per pod and scaling horizontally is the approach LiteLLM recommends for Kubernetes, so a fix often means adjusting replica counts or resource requests rather than adding workers. Redis 7.0 or newer becomes necessary once more than one proxy instance shares rate limits, router state and cache, so a diagnosis that finds shared-state problems may recommend it. Expect some changes to recur, such as capacity planning as traffic grows and reviewing the batched spend write settings at higher throughput. Ask for a retest against the same traffic sample so you can confirm the improvement with numbers from your own environment.
Does a diagnosis cost less than a full performance engagement?
It can, because a diagnosis has a narrower purpose: find where the added time comes from and recommend fixes. A full performance engagement adds implementation of the changes, capacity testing and ongoing tuning. Cost is driven by the scope agreed in writing, the number of environments, the volume of telemetry to review, and whether load testing is included. DeployOpen does not publish prices, so ask for a written quote that lists each phase, the deliverables and what you must provide, and confirm whether a retest is included.
Will the diagnosis tell us if LiteLLM or the provider is at fault?
The goal is to separate the three sources of delay: the provider, the gateway and queueing before the gateway. The x-litellm-overhead-duration-ms header reports the latency the gateway added to each response, so slow responses with a small overhead value point toward the provider or the network path. A large overhead value points toward the gateway, such as DEBUG logging on large payloads. Slow responses with little header overhead but high in-flight counts per pod point toward queueing before the gateway handler starts. Confirm these readings with your load balancer metrics, because a diagnosis that relies only on gateway logs will miss queue time.
How DeployOpen scopes and delivers latency diagnosis
DeployOpen works on LiteLLM latency overhead inside your own infrastructure, starting from where slow responses are actually spent: the provider, the gateway or time queued before the gateway. The written scope sets which pods, logs, headers and load balancer metrics are examined, and what evidence the findings must rest on.
How we scope
- Agree in writing which deployment, namespaces, pods and provider routes are in the diagnosis.
- Confirm access to gateway logs, the x-litellm-overhead-duration-ms header, and load balancer metrics before work starts.
- Engagements are fixed-scope, with deliverables and timelines agreed in writing before any work begins.
How we build
- Measure in-flight requests per pod with /health/backlog and the litellm_in_flight_requests gauge during real traffic.
- Compare gateway-added overhead against end-to-end timing to separate provider delay from gateway and queueing delay.
- Test debug logging settings and large or base64 payloads in a controlled run, recording each change and its effect.
How we hand over
- Deliver a written report that identifies the source of added latency with the measurements that support it.
- Document the configuration changes, logging settings and dashboards your team needs to repeat the measurements.
- Walk your platform and operations engineers through the findings and the runbook for future latency investigations.
How we support
- Ongoing support, upgrades and continuous testing are available as a retainer after the diagnosis is complete.
- Retest the gateway after fixes are applied to confirm that the overhead has changed as the report predicted.
- Ask for the retainer terms, retest scope and response commitments in the written quote before signing.

