LiteLLM routing, fallbacks and load balancing

How to pick a LiteLLM routing strategy, set retries, cooldowns and fallback order, and spread traffic across provider accounts and private models, with the checks to run before go-live.

On this page

Why LiteLLM routing, fallbacks and load balancing need design before go-live

Routing choices in LiteLLM decide three things at once: what each request costs, how fast it responds, and whether model access survives a provider failure. When several teams call one gateway, and that gateway fronts hosted providers, provider accounts with rate limits, and self-hosted models, the default configuration rarely reflects those trade-offs. The router settings, fallback order and retry behavior need to be chosen deliberately and tested before applications depend on them.

The default setup hides three interactions. First, a fallback that moves traffic from one provider to another can quietly change cost and data residency, because the second provider may price differently, log differently or run in a different region than the first. Second, retries, cooldowns and fallbacks interact with per-key budgets, TPM and RPM limits. A retry loop can spend a team's budget faster than expected, and a cooldown can push all traffic onto the one deployment that remains healthy, which then hits its own rate limit. Third, load balancing across several accounts of the same provider can make usage look fine in aggregate while one team's key is throttled.

Routing state is shared across proxy instances only when Redis is in place. If you run more than one proxy instance without Redis, each instance keeps its own view of cooldowns and usage, so the behavior you tested on one pod will not match what callers see across the fleet. Confirm the Redis configuration and version against the LiteLLM production guide before you rely on routing behavior in a multi-instance deployment.

Which LiteLLM router settings and deployment parts control traffic

Traffic in a LiteLLM gateway is shaped by a small set of parts: model groups, the routing strategy, retry and cooldown behavior, failover order and session affinity. Shared state for multiple proxy instances lives in Redis, while PostgreSQL holds the virtual key and spend records that decide who may send traffic and how much. Review each part together, because a routing choice that looks correct in isolation can behave differently once keys, budgets and several instances are involved.

Model groups with multiple deployments

A model group is one public model name backed by several deployments, such as the same model served from two provider accounts or a provider and a self-hosted endpoint. Applications call the group name, and the router picks a deployment for each request. Check that every deployment in a group accepts the same request shape and produces comparable output, since callers will not know which one answered. Confirm the exact configuration keys in the routing docs before you write the model list.

Routing docs

Routing strategy selection

The routing strategy decides how the router chooses among healthy deployments in a group. Simple-shuffle is the documented recommended default, while usage-based, latency-based, least-busy and cost-based strategies weigh other signals. Pick one strategy per group based on what you need to control, such as spend, response time or load, and test it under realistic concurrency before rollout. Confirm which strategy names and options your version supports.

Documented strategies
5

Retries and cooldown behavior

Retries let the router try another attempt when a request fails, and cooldowns temporarily remove a deployment from rotation after repeated failures. Together they decide how quickly a failing provider account stops receiving traffic and how often callers see errors. Set retry counts with care, because retries against a provider that is rate limiting you can increase load and cost. Confirm the cooldown trigger and duration settings in the routing docs for your release.

Priority ordering for failover

Priority ordering defines the sequence in which deployments or fallback models are tried when the preferred one is unavailable. Put the approved primary first, then the account or model you accept as a second choice, and keep any fallback within the data handling and cost limits your policy allows. A fallback that a team has never tested may fail on different context lengths or features. Write the order down and confirm the exact fallback configuration keys in the docs.

Session affinity

Session affinity keeps related requests from one session routed to the same deployment, which can matter for conversational state or provider-side caching. It conflicts with pure load spreading, so decide whether consistency or even distribution matters more for each application. Test how affinity behaves when the pinned deployment enters cooldown, because the session must move cleanly to another deployment. Confirm how affinity is enabled and scoped in the routing docs.

Redis and PostgreSQL state

Routing state and rate limits are shared across proxy instances through Redis, which the production guide requires at version 7.0 or newer once more than one instance runs. PostgreSQL holds virtual keys, budgets and spend records, and is needed before virtual keys can be used. If Redis is missing, instances may disagree on cooldowns and limits, so traffic patterns can differ by pod. Plan both services for availability before you tune routing.

Production guide

Which routing strategy fits which traffic pattern

This table compares the LiteLLM routing strategies and failover options by the traffic pattern each one fits and the operational cost it adds. Read each row against your own provider limits, traffic shape and monitoring capacity, and treat simple-shuffle as the starting point unless a specific pattern calls for more state.

StrategyWhen it fitsOperational cost
Simple-shuffle (recommended)Most workloads where deployments of the same model are roughly equivalent and you want the documented default with minimal tuningLow. Spreads requests across deployments randomly or by weight, so confirm weights reflect each account's real limits
Usage-basedDeployments with different token or request limits where you want traffic to follow remaining capacityNeeds shared router state (Redis once more than one proxy instance runs) and reliable limit settings per deployment
Latency-basedInteractive applications where response time differs noticeably between providers or regionsRequires latency measurements to stay current, and can shift traffic toward a fast deployment until it saturates
Least-busyWorkloads with long or uneven requests where in-flight load per deployment varies widelyTracks concurrent requests, so it needs shared state across instances and monitoring of queue depth per deployment
Cost-basedRouting cheaper models or accounts first when quality is equivalent and the price per token is configured accuratelyDepends on pricing data staying correct for every model; stale prices send traffic to the wrong deployment
Priority-ordered failoverPrimary-and-backup setups where a specific provider or self-hosted model should serve first and only fail over on errorsSimple to reason about, but you must test that the fallback chain is complete and that backups have the needed capacity
Session affinityMulti-turn conversations or workflows where a session should keep hitting the same deploymentCan pin load onto one deployment, so watch for uneven distribution and plan cooldown behavior for pinned sessions

How to configure routing, fallbacks and load balancing in sequence

This sequence turns a set of model deployments into a gateway that picks the right route, retries sensibly, fails over only to approved models and keeps working when a proxy instance or provider account goes down. Each step closes with a check you can run before the configuration reaches production.

  1. Inventory deployments and provider accounts

    Your platform or gateway owner lists every model deployment the proxy will call, grouped by the model name applications request, along with the provider account, region, API key owner and rate limits behind each one. Include self-hosted models and note which deployments hold approved data classifications. The inventory is done when every deployment has a named owner, a provider account and an approval status, and the group membership is agreed with the application teams that will consume it.

  2. Choose the base routing strategy

    Select one base strategy for each model group: simple-shuffle, usage-based, latency-based, least-busy or cost-based. LiteLLM documents simple-shuffle as its recommended default, and the other options trade off spreading load, favoring faster deployments, avoiding queues or controlling spend. Record the choice and the reason for each group so later tuning has a baseline. The check is a written decision per group, reviewed by the platform owner and the team that pays for usage.

  3. Define model groups and aliases

    In the proxy configuration, map each deployment into a model group under a stable alias that applications call, so provider model names stay hidden from client code. Confirm that every alias resolves only to deployments on the approved list, and that no group quietly includes a provider endpoint that has not passed review. The check is a config review in which each alias lists its deployments, and a test request to each alias returns a response from the expected deployment.

  4. Set retries, timeouts and cooldowns

    Set the number of retries per request, the request timeout and the cooldown behavior that takes a deployment out of rotation after repeated failures. Keep retries modest so that a failing provider does not multiply load or spend, and make sure cooldown settings match the rate limits you recorded in step one. The check is a controlled failure: point one deployment at an invalid key or a blocked endpoint in a test environment, send a burst of requests, and confirm that the deployment enters cooldown and stops receiving traffic.

  5. Define fallback order to approved models only

    Write the priority order for failover within each group, listing the next deployment to try and, where needed, a cross-group fallback. Every entry must be an approved model, including the data handling terms agreed for that provider. Do not let a fallback send regulated data to a provider or region the group was never approved for. The check is a fallback table signed off by security and the data owner, followed by a test that takes the primary out of service and confirms the next deployment in order serves the call.

  6. Add session affinity where conversations need it

    Identify workloads where follow-up requests must reach the same deployment, such as multi-turn assistants that rely on provider-side context or caching. Enable session affinity only for those groups, since pinning sessions can reduce the benefit of load spreading. The check is a two-turn conversation test in which both requests reach the same deployment, followed by a confirmation that stateless groups still distribute calls across their deployments.

  7. Enable Redis for multiple proxy instances

    When more than one proxy instance runs, connect all instances to a shared Redis 7.0 or newer deployment so that rate limits, router state and cache are consistent across them. Confirm that PostgreSQL is also shared, since the production guide names it as the primary supported database. The check is a load test across two instances in which a cooldown triggered on one instance is respected by the other, and request counts reported by both instances add up to the total sent.

  8. Test routing, fallbacks and failover end to end

    Run a scripted test set that covers normal load spreading, forced cooldown, fallback order, session affinity and a full instance restart. Record which deployment served each request, the latency, and the cost reported in logs, then compare results against the decisions from earlier steps. Ask the platform owner to confirm that test evidence is retained, and repeat the suite after each configuration change or LiteLLM upgrade. The sequence is complete when every scripted case passes and the results are filed with the configuration.

How routing differs across single node, HA and Kubernetes deployments

On a single proxy instance, the router keeps its state in memory on that one process. Retries, cooldowns and failover decisions are made locally, and nothing needs to be shared with another instance. Failover in this model covers provider errors: when a deployment returns repeated failures, the router can cool it down and send requests to the next deployment in the priority order you define. It does not protect against the proxy itself going down, because there is no second instance to take traffic.

  • Local router state: cooldown and usage counters live in the single process and reset when it restarts.
  • Provider-error failover: timeouts, rate-limit responses and server errors from one provider account can trigger retries and fallbacks.
  • No instance failover: a crash or failed deployment of the proxy stops all model access until it recovers.
  • Shared limits are local: RPM and TPM limits apply within this one process only.
  • Simple testing: routing behavior is easiest to reproduce and verify in this model.

Before relying on this model, confirm with your own test traffic how long cooldowns last and how the router behaves after a restart in your LiteLLM version.

How to spread traffic across provider accounts and self-hosted models

In LiteLLM, spreading traffic starts with the model group. Each provider account or self-hosted model server is added as a deployment under the same model_name, and the router treats those deployments as interchangeable targets for that alias. Weights and priorities then shape the split: the router can distribute requests across deployments with the strategy you chose, and priority ordering decides which deployments are tried first during failover. Budgets do not sit in the router at all. They are enforced on virtual keys, so a request that is routed to a cheap account still counts against the calling key's spend. Before you add a second account, confirm in the routing docs how your chosen strategy weights deployments and how it treats a deployment that is cooling down.

A single provider account is often the real bottleneck. If one account holds most of the traffic, its tokens-per-minute and requests-per-minute ceilings become the ceiling for the whole alias, and cooldowns triggered by rate-limit errors push load onto the remaining deployments at the moment they are already busiest. Spread traffic only as far as the account limits allow. Pull each deployment's limits from the provider console and compare them with the peak per-minute load you expect. Then check the same numbers against the TPM and RPM limits and budgets on the virtual keys that call the alias, since a split that looks safe at the router can still exhaust one key's allowance.

Fallback order matters most when data is regulated. If a request for a sensitive workload fails over to a public provider endpoint, the data leaves the environment you approved, even though the request succeeded. For those workloads, put approved private models, such as a self-hosted model server inside your network, first in the fallback chain and restrict the key to that alias so no public deployment can be reached. Keep public providers for workloads your data classification allows. Test this with a deliberate failure of the private deployment and confirm in the logs which endpoint served the request. Your compliance and security teams should review the fallback map as part of the gateway's design, not after go-live.

Access and data controls that routing must respect

Routing decisions can quietly move traffic to providers, models and log destinations that your access policy never approved. The four controls below cover where fallbacks may send regulated prompts, how virtual keys stay limited to their models, where provider credentials live, and what the router records.

Keep fallbacks inside the approved provider list

A fallback is a second route the router uses when the first one fails, and it can point at any deployment in the model list. Define fallback chains only from providers and regions your data classification allows, and check every fallback target against that list before go-live. Test a forced failure on the primary route and confirm in the logs which provider actually served the request. A fallback that leaves the approved list is a data transfer, even during an outage.

Routing docs

Respect key model restrictions during failover

Virtual keys can be restricted to specific models, and that restriction must hold when the router reroutes a request. Confirm that a key limited to an approved alias cannot reach a fallback deployment that sits under a different model name or group. Run one test per key class: send a request that would trigger failover and verify that the request is rejected or served only by an allowed deployment. Document which model group each key maps to so the restriction and the routing config are reviewed together.

Virtual keys docs

Move provider credentials into a secret manager

Provider API keys written into the proxy config file are readable by anyone with repository or server access and persist in backups and copies. Reference credentials through environment variables or a secret store, and keep the master key, which must start with sk-, out of version control as well. Secret manager integrations, including AWS, Azure, Google, HashiCorp Vault and CyberArk, are a LiteLLM Enterprise feature, so confirm licensing before you design around them. Plan rotation for every provider account used in a load-balanced group, since one leaked key exposes that whole group.

Enterprise docs

Limit what routing logs capture

Routing and request logs can store full prompts and responses, which may then sit in a database or log pipeline that is broader than the data policy allows. Decide which fields the router logs, such as model, deployment, latency and error class, and which content it omits. Team-level logging and guardrails are an Enterprise capability, so check whether your open-source setup can meet the logging rule or whether you need a license. Review log retention and access rights as part of the same change, because a routing fix that adds a logging callback can expand exposure overnight.

How to test that routing fails over safely

Test each failure mode on purpose before any production traffic depends on the router. Force provider errors (for example, by pointing one deployment at an invalid credential or a rate-limited account in staging) and simulate timeouts with a deployment that accepts connections but responds slowly. For each case, confirm that the router retries as configured, that the failing deployment enters cooldown after repeated failures, and that the request lands on the next deployment in the priority order you set. Then drain one deployment by removing it from the model list or disabling it, and confirm that the simple-shuffle or usage-based distribution rebalances across the survivors without errors reaching the caller. Finally, stop one proxy instance behind the load balancer and confirm that in-flight and new requests succeed on the remaining instances, with Redis holding shared rate limit and router state as expected.

Failover is only safe if access controls hold while traffic moves. Run requests with a virtual key restricted to an approved model group and check that a fallback never routes that key to a model outside its allow list. Set up a fallback path that would reach a non-approved provider if the configuration were wrong, then confirm the proxy blocks it. Review the request logs for every test request and check the provider and deployment recorded for each call. Next, confirm spend is booked to the virtual key that made the request, not to a shared or default key, after a request has failed over to a different deployment. Compare the spend records for the key against the calls you made, and confirm that a fallback does not double-count cost. Ask your provider and pricing configuration owner to confirm how cost is calculated for each deployment in the fallback chain.

Run this full test matrix in a staging environment that matches production as closely as possible: the same LiteLLM version, the same config.yaml routing settings, the same PostgreSQL and Redis topology, and the same number of proxy instances. Use separate staging provider accounts or sandbox keys so that test failures do not consume production quota or spend. Record the expected deployment for each scenario before you run it, so the result is a pass or fail rather than an interpretation. Repeat the run after any change to routing strategy, retry counts, cooldown settings or fallback order, and again after each upgrade. Keep the results with your change records, since they are the evidence reviewers will ask for when they check that routing and access controls behave as documented.

What to monitor, back up and document after routing goes live

This table pairs each operational area with what to watch, what to keep, and what to record after LiteLLM routing goes live. Read each row as a checklist item: the signal tells you whether routing is working, the backup or record lets you recover or explain a change. The main takeaway is that routing health depends as much on the Redis and PostgreSQL state and the change history as on the router settings themselves.

AreaWhat to watch or keepWhy it matters after go-live
Per-deployment error ratesError and timeout counts for each model deployment, grouped by provider account and model groupShows which provider account is failing before users report it and confirms retries are firing where expected
Cooldown eventsHow often each deployment enters cooldown after repeated failures, and how long it stays out of rotationFrequent cooldowns can hide a bad key or quota problem behind a router that appears to be working
Fallback countsNumber of requests served by a fallback model or priority group instead of the primaryA rising fallback rate means the primary path is degraded, and the fallback may cost more or have different limits
Latency by deploymentResponse time per deployment, compared against the baseline recorded at launchNeeded to judge whether latency-based routing is steering traffic correctly and whether a slow region needs attention
Spend per model groupSpend tracked per model group and per deployment, reconciled against provider invoicesConfirms that cost-based routing and fallbacks behave as intended and that budgets hold across provider accounts
Redis healthAvailability, memory use and connection errors on the shared Redis used for router state and rate limitsRedis is required once more than one proxy instance runs, so a Redis fault can break shared routing state and limits
PostgreSQL healthAvailability, connection counts, storage growth and the database backup job statusVirtual keys, budgets and spend records depend on PostgreSQL, and routing edits are recorded there
Config version historyVersioned copies of the proxy config file, with the date, author and reason for each versionLets the team roll back a routing change and compare the routing behavior before and after a specific edit
Backups of config and databaseStored copies of the proxy config and a tested PostgreSQL backup, kept outside the proxy hostsRestoring routing after a failed edit or host loss depends on having both the config and the database state available
Change log for routing editsRecord of each change to retries, cooldowns, fallback order and deployment lists, with the test evidenceGives auditors and on-call engineers a clear trail of who changed routing and why it was approved
Runbook for adding a provider accountStep-by-step procedure covering key creation, secret storage, config update, test calls and monitoring setupKeeps new accounts consistent with existing routing and avoids keys being placed in the wrong store
Retest after each upgradeRepeat routing, fallback and budget tests after every move to a new minor version within the supported rangeRouting behavior and database migrations can change between releases, so confirm results on the new version before relying on them

Routing questions teams ask before hiring outside help

Which routing strategy should we start with in LiteLLM?

Start with simple-shuffle, the strategy the LiteLLM router documentation recommends as the default. It spreads requests across the deployments in a model group with no extra state to tune, which makes behavior easy to read in logs. Move to usage-based, latency-based, least-busy or cost-based routing only after you have measured traffic and can name the problem you are solving, such as one slow provider account or a cost gap between two deployments. Each strategy changes how the router picks a deployment, so test the switch with representative traffic before it reaches production. Confirm the exact configuration for your model groups in a written scope.

Can fallbacks be made safe for regulated data?

Yes, but only if you decide where regulated data is allowed to go before you configure any fallback. A fallback sends the same request to a different deployment, which may be a different provider, region or contract with different data handling terms. Build the fallback order from an approved model list, so every target has been reviewed by your compliance and security teams. Keep private or self-hosted models in the chain where the data classification requires it, and make sure virtual keys are restricted to the models they may use. Review the provider terms for each fallback target, and confirm with your legal and security owners which data classes may move to a secondary provider.

How much effort does routing setup take and what drives it?

Effort depends mostly on the number of providers, model groups, environments and tests you need. Each additional provider account adds credentials, quota limits and health behavior to understand. Each model group adds a routing decision and a fallback order to review. Separate development, staging and production environments each need their own configuration and test passes. Retries, cooldowns and failover rules need load tests that show how the gateway behaves when a provider slows down or returns errors. A written scope should list those counts, so you can compare quotes on the same basis. Ask any partner to state the effort per item, not a total without detail.

Can our own team set up LiteLLM routing without outside help?

Yes, if your team already runs LiteLLM or similar gateways and has engineers who can read provider quota documentation, configure a Kubernetes deployment and write load tests. The LiteLLM routing documentation covers each strategy, retry and cooldown setting, so a capable team can start from it. Outside help usually pays off when several provider accounts, regulated data rules or multiple environments must be validated together, because the test matrix grows quickly. Decide which parts you can own after go-live, such as changing a fallback order, and which need a documented runbook first. Ask for the runbook as a deliverable in any scope you sign.

What does the work need from our team?

The work needs four inputs from your side. First, access to the provider accounts you plan to route across, with the quota and billing owners named. Second, a model inventory listing each model, its provider, region and deployment name. Third, an approved model list signed off by security and compliance, which sets the allowed fallback targets. Fourth, test traffic that resembles production requests, so latency and error behavior can be measured rather than guessed. Also name a decision owner who can approve fallback order changes. Missing any of these usually extends the timeline, so confirm each item in the written scope before work starts.

What changes after a LiteLLM upgrade to routing behavior?

Routing behavior can change between releases, so every upgrade should be treated as a change to the routing layer. The LiteLLM project supports the four most recent stable minor versions, so plan upgrades within that window and check release notes for router changes. Rerun your routing tests after each upgrade, especially retry, cooldown and fallback paths, and confirm that session affinity and priority ordering still behave as before. Database migrations may also affect router state and spend tracking, so test them in staging first. Confirm the upgrade procedure and support window with the vendor and your own change process before scheduling the work.

How do we spread traffic across several provider accounts safely?

Use one model group per logical model and list each provider account as a deployment inside that group, so the router can distribute requests. Set the rate limit values for each deployment to match its quota, so one account does not exhaust another. Use cooldowns to pull a deployment out of rotation after repeated failures, and keep a priority order for failover. Shared rate limits and router state across several proxy instances need Redis 7.0 or newer, which the LiteLLM production guide requires once more than one instance runs. Load test the group with realistic concurrency before relying on it, and confirm quota limits with each provider.

How a request moves through routing, cooldowns and fallbacks

The request starts at the client, which sends it with a virtual key to the LiteLLM proxy. The proxy first checks the key's model access and budget, then the router picks a deployment using the chosen strategy, with shared state kept in Redis when several proxy instances run. If the provider call fails, retries and cooldowns apply, and the router moves to the next priority deployment within the approved models. Check that every hop is logged to the database as spend, and that fallback targets stay inside the key's allowed models.

Request path through key checks, routing, retries, cooldowns, fallback and spend logging.

How DeployOpen scopes and hands over LiteLLM routing work

DeployOpen is a Chainscore Labs company that plans, implements, hardens, documents and supports self-hosted open-source platforms inside the client's own infrastructure, including their cloud accounts, data centers or air-gapped networks. For routing work, that means the router configuration, provider connections, retry and cooldown settings, and fallback order all run in your environment, under your change control, with your team able to read and own every setting. Most engagements are fixed-scope, so the written scope should name the routing strategy you are choosing, the providers and private models in the routing groups, the number of proxy instances, and the failure scenarios that must be tested before go-live.

Before any configuration changes, the scope, deliverables and timelines are agreed in writing. A useful routing scope lists which model groups will use simple-shuffle, usage-based, latency-based, least-busy or cost-based selection, how many provider accounts each group spans, where Redis is used for shared router state, and what evidence will show that failover works. Ask the vendor to state which deliverables are included, such as the router configuration file, a test plan that simulates provider errors and rate limits, the results of those tests, and a retest after fixes. Timelines should be tied to those deliverables rather than to calendar estimates that cannot be checked.

At handover, you should receive the routing configuration as versioned files, the test evidence for retries, cooldowns and fallbacks, and a runbook covering how to change a model group, how to take a provider out of rotation, and what to check when latency or error rates move. Ongoing support, upgrade testing and continuous testing of routing behavior are available as retainers, which suits teams that change providers or add private models often. Confirm with DeployOpen during scoping which of these items are included in the fixed scope and which would be covered by a retainer.

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.