LIVE · Thursday 3 December

Best LLM Gateway With Automatic Failover (2026): LiteLLM, Portkey, OpenRouter, Bifrost Compared by Trigger

No independent benchmark has timed these gateways under the same outage. Their own docs show the difference that matters: which errors trigger failover, and what happens to a provider that keeps failing.

By Thomas10 min read

There is no single best LLM gateway with automatic failover; the right one depends on where it runs and which errors you need it to catch. For a self-hosted gateway, LiteLLM's documented failover rules tell errors apart, with separate fallbacks for context-length and content-policy errors and fleet-wide cooldowns. Portkey lets you choose exactly which status codes fail over (on_status_codes) and offers a configurable circuit breaker, OpenRouter needs the least setup but runs only as a managed service, and teams already on Cloudflare or Kong can fail over inside the gateway they have. As of November 17, 2026, no independent, rerunnable benchmark has measured how fast any of them fails over under the same injected outage.

What a gateway's failover actually does

Every gateway in this comparison does the same three things in some order. It retries the request against the same model, perhaps on a different key or deployment. When retries run out, it falls back to the next model or provider on a list. And, in some of them, it stops sending traffic to a provider that keeps failing, so that every request during an outage does not pay for a doomed first attempt.

The differences are in the details of each step, and they decide whether failover helps or hurts. A rate-limit error (429) is worth retrying after a pause. A server error (503) is worth sending elsewhere. A "prompt too long" error is not worth retrying at all, and sending it to the next provider in line only helps if that provider's model has a bigger context window. A content-policy refusal may succeed on a different model, or may be exactly the answer you want to keep. A gateway that treats all of these the same will fail over when it should not, or fail to when it should.

What triggers failover, gateway by gateway

LiteLLM sorts failures by kind before it decides anything. Its router documentation, updated November 6, says every decision reads the failure's kind (rate limit, context window, content policy, auth, not found, timeout), its status code and its Retry-After header. A context-window error goes straight to the chain in context_window_fallbacks without being retried, and a content-policy error goes to content_policy_fallbacks; LiteLLM maps both error types across providers, so the same rule works whether the refusal came from OpenAI or Anthropic. Other failures are retried first, then walk down lower-priority deployments of the same model, then go to the generic fallbacks list. A fallback target can override request parameters for that hop, for example setting temperature to 0 on the backup model, and the walk stops after five hops by default.

Portkey works from HTTP status codes. Its fallback documentation says fallback "triggers on any non-2xx status code" by default, and on_status_codes narrows that, for example to [429, 503]. Retries are separate: up to five attempts, by default on 429, 500, 502, 503, 504 and 529, with backoff from 1 to 16 seconds and an option to honour the provider's Retry-After header. Fallback targets can nest, so a load-balanced cluster can sit in front of a cross-model backup that only fires when the whole cluster fails.

Bifrost, an Apache 2.0 gateway written in Go, is simpler. Its fallbacks page says it moves to the first fallback "whatever the error" once the primary's retries are spent, and that provider timeouts and time-to-first-token timeouts also trigger fallback. Each fallback gets its own retry budget, so a primary with three retries and two fallbacks configured the same way can make up to 12 attempts. The page does not describe a fallback rule per status code.

OpenRouter takes a models list in the request. Its documentation says that by default "any error can trigger the use of a fallback model," naming context-length validation errors, moderation flags, rate limiting and downtime. It also reroutes between providers serving the same model, controlled by allow_fallbacks, which is on by default. On its Anthropic-compatible Messages endpoint the separate fallbacks parameter accepts at most three entries, carries only the model name (no per-attempt max_tokens or thinking), and cannot be combined with models.

Cloudflare AI Gateway chains steps on its Universal endpoint: an array of providers and models, with "as many fallbacks as you need." Its documentation, last updated April 20, 2026, says a fallback runs when a request returns an error or hits a set timeout; it does not list specific status codes. Retries and timeouts are set per request with headers (cf-aig-max-attempts, up to five retries, and cf-aig-request-timeout in milliseconds). The cf-aig-step response header tells you which step answered: 0 for the primary, 1 for the first fallback, and so on.

Kong does failover through its AI Proxy Advanced plugin, which its documentation says is "only available as part of our AI Gateway Enterprise offering." Its failover_criteria default to error and timeout, and can add specific codes such as http_429, http_503 or http_504. Client errors do not trigger failover, so a context-length error will not move the request.

What happens when a provider keeps failing

Fail over on every request during a long outage and each one still pays for the failed first attempt. The answer is a cooldown or circuit breaker, and the gateways differ most here.

LiteLLM cools a deployment down after it fails more than allowed_fails times, or by an error-rate rule over the last 60 seconds, and keeps it out of every pick for the cooldown time: the deployment's own setting, then the provider's Retry-After, then a router default of five seconds. When Redis is configured, the cooldown applies across every process in the fleet. There is no probe request; the deployment simply becomes eligible again when the timer ends.

Portkey's circuit breaker opens on a failure count or a failure percentage, after a minimum number of requests, and closes after a cooldown_interval of at least 30 seconds. Which codes count as failures is configurable, and defaults to errors above 500. If every target is open, Portkey bypasses the breaker and tries them all anyway.

Kong added the same idea in version 3.13: after max_fails failures a target is skipped for fail_timeout, which defaults to 10 seconds. max_fails defaults to zero, which disables it, so it has to be turned on. Bifrost's fallbacks page describes no provider-level cooldown; its Enterprise edition can hold a refused key out of rotation for at least 10 seconds. OpenRouter's and Cloudflare's failover pages don't mention a breaker you can configure.

Gateway Fails over on Persistent failures Self-host
LiteLLM Error kind: context window, content policy, general Cooldown, fleet-wide with Redis Yes, MIT
Portkey Any non-2xx, or chosen codes Circuit breaker, 30 s minimum Yes, MIT gateway
Bifrost Any error after retries, plus timeouts Enterprise key hold-out Yes, Apache 2.0
OpenRouter Any error, incl. context length and moderation Provider rerouting No
Cloudflare Errors and timeouts Retries via headers No
Kong Error, timeout, chosen codes Breaker from 3.13, off by default Yes, Enterprise plugin

How fast, and how much latency: unmeasured

The question readers most want answered, how many milliseconds each gateway takes to fail over and how many requests fail during an outage, has not been measured independently. The figures in circulation are each project's own. LiteLLM's benchmark page reports 2 ms median and 13 ms p99 gateway overhead at 1,170 requests per second on four instances against a mock endpoint. Bifrost's README reports 11 microseconds of added latency at 5,000 requests per second on a t3.xlarge, without describing the setup further. Portkey's README says its gateway adds under 1 ms. None of these tests injects an outage, and none uses the same traffic or hardware as another, so they cannot be ranked against each other.

A fair test is not hard to describe: the same traffic mix through each gateway, the same OpenAI to Anthropic to Bedrock chain, and scripted 429s, 5xx errors, timeouts, context-length errors and refusals, with time to fail over, added p50 and p99 latency, failed requests and cost recorded per fault. The gateways make the result visible: Cloudflare's cf-aig-step header, OpenRouter's model field in each response, and Portkey's x-portkey-retry-attempt-count header all show which attempt answered. Until such a test is published, treat any ranking by failover speed as a claim.

The part failover doesn't fix: the answer changes

Failover keeps the service up by sending the request to a different model, and a different model gives a different answer. Whether the failed-over answers still pass a task's checks, such as valid JSON, correct tool calls or the same accuracy, has not been measured for any of these gateways. The documentation is candid about the risk. Portkey's fallback page says to "ensure fallback LLMs are compatible with your use case." LiteLLM will not continue a broken stream on a fallback model once it has emitted tool calls, thinking blocks or JSON-mode output, because the new model cannot be trusted to pick up mid-structure.

The practical defence is to test the fallback path as carefully as the primary: run your evaluation set against every model on the chain, and use per-hop overrides where the gateway allows them (LiteLLM does; OpenRouter's Anthropic endpoint rejects them).

Some vendors tackle the problem below the gateway. Parsec, a small language model lab, routes per turn rather than per request and serves models post-trained on the customer's own traffic, which its routers page says the customer owns. The same page says a universal K/V cache lets a conversation switch models without the usual cache loss, claiming the next model picks the same next token 89 to 95% of the time; it defines no workload or baseline for that figure. Parsec is a different kind of product and is not ranked against the gateways here, and it publishes no price for the service.

What failover costs

The cost change on a single failed-over request is usually small, and depends mostly on two things: the fallback model's list price and whether its prompt cache is warm. OpenRouter's documentation says requests are priced at "the model that was ultimately used."

Take a workload of 1 million requests a month, each with 4,000 input tokens (3,000 of them a fixed system prompt and tool list that the provider caches) and 400 output tokens. On OpenAI's gpt-6.2-sol at $2 per million input tokens, $0.10 cached and $10 output, a request costs $0.0063, or $6,300 a month. Claude Sonnet 5.5 has the same prices ($2 input, $0.10 cache hit, $10 output), so a warm fallback costs the same $0.0063. A cold one does not: with no cache, the request is $0.012, and the first request that writes the cache, at $2.50 per million, is $0.0135. Falling back to Claude Opus 5.5 instead ($4 input, $20 output) costs $0.0126 warm and $0.024 cold.

A one-hour outage on this workload moves about 1,389 requests. Sending them all to a cold Sonnet adds about $8; sending them to a cold Opus adds about $25. The standing cost of the gateway itself is larger. OpenRouter adds no markup to model prices but charges 5.5% when you buy credits by card, about $347 a month on $6,300 of usage. Cloudflare's core gateway features are free; its optional Unified Billing adds 5% to credits. LiteLLM, Bifrost and the Portkey gateway are free to self-host, with the server cost yours.

Which gateway fits which setup

Setup Pick Why
Self-hosted, high traffic, mixed errors LiteLLM with Redis Per-error-kind fallbacks, fleet-wide cooldowns
Self-hosted, simple chain Bifrost Falls back on any error after retries
Managed, fine control Portkey on_status_codes and a circuit breaker
Least setup OpenRouter A models list in the request
Already on Cloudflare or Kong Built-in fallbacks No new gateway to run

Bottom line

If you self-host at high traffic and need failover that tells a context-length error from an outage, choose LiteLLM, with Redis so cooldowns hold across the fleet; Bifrost, written in Go, is the alternative if "fail over on any error" is enough. If you want a managed service with control over exactly which status codes fail over and a real circuit breaker, choose Portkey, noting that Palo Alto Networks has owned it since May 29, 2026, and its closing announcement does not address existing customer contracts. If you want the least setup, use OpenRouter's models list and budget for the 5.5% credit fee. If you already run Cloudflare or Kong Enterprise, use their built-in failover and turn on Kong's circuit breaker yourself. Whichever you pick, run your test set against every model on the fallback chain before an outage does it for you.

Sources

More in Products

All Products →