---
title: "Retries, cooldowns and fallbacks on model requests"
description: "How Kaeso 0.7 keeps model requests running when a provider drops a connection, returns 5xx or hits a rate limit — and why timeouts and 4xx refusals are never retried on the same model."
url: https://kaeso.app/articles/retries-and-fallbacks
markdown: https://kaeso.app/articles/retries-and-fallbacks.md
language: en
alternates:
  de: https://kaeso.app/de/articles/retries-and-fallbacks.md
  zh-CN: https://kaeso.app/zh-CN/articles/retries-and-fallbacks.md
published: 2026-11-22
authors:
  - Kaeso Team
tags:
  - gateway
  - routing
  - reliability
  - aliases
  - guide
image: https://kaeso.app/articles/retries-and-fallbacks/cover.jpg
index: https://kaeso.app/llms.txt
---

# Retries, cooldowns and fallbacks on model requests

How Kaeso 0.7 keeps model requests running when a provider drops a connection, returns 5xx or hits a rate limit — and why timeouts and 4xx refusals are never retried on the same model.

> Every page, article and docs page of Kaeso is listed in https://kaeso.app/llms.txt.

- Published: 22 November 2026
- Reading time: 5 min
- Author: Kaeso Team

When an application calls a model provider directly, a single dropped TCP connection, a brief `503` spike or a rate-limited API key surfaces straight to the user. Retrying blindly in the application is no better: retrying a request that timed out after 30 seconds can bill you twice while the upstream model is still generating the first reply.

Kaeso 0.7.0 separates transient glitches from lasting failures across three layers in the gateway: **same-model retries**, **multi-key failover within a provider**, and **alias route fallbacks with shared Valkey cooldowns**.

![An alias route in the console editor showing a condition on x-plan, a primary model with a fallback, and a weighted split by caller](https://kaeso.app/articles/kaeso-demo/alias-route-light.png "An alias route combines per-step retries, provider key pools and cross-provider fallbacks.")

## 1. Same-model retries: only when retrying is safe

By default, Kaeso sends a request once. In 0.7.0 you can enable automatic retries either for an entire project (under the project's **Settings** › **Retries**, from **Never** to `3`) or on an individual model step inside an [alias route](https://kaeso.app/articles/alias-routes) (`retries: 0..3`).

Kaeso retries a model step **only** on short-lived transport and server failures before any stream output has been sent:

| Upstream failure | Retried on the same model? | Why |
| --- | --- | --- |
| Connection refused or reset before output | Yes (up to `retries`) | The provider never processed or finished the request |
| HTTP `5xx` or provider overloaded (`529`) | Yes (up to `retries`) | Transient upstream server error |
| Response with `Retry-After` ≤ 5 seconds on a retryable error | Yes, waiting the header's duration | Short upstream backoff |
| `Retry-After` > 5 seconds | No — moves to next key or fallback | Holding the caller open longer than 5 seconds stalls interactive apps |
| Request or first-byte **timeout** (`504`) | **Never** | The provider may still be generating and billing the timed-out request |
| Rate limit or quota (`429`) | **Never** on the same key | Retrying an exhausted rate window immediately fails again; Kaeso tries the project's next key or falls back |
| Refused request (`400`, `413`, `422`) | **Never** | The same payload to the same model will be refused again |
| Stream interrupted **after** output tokens started | **Never** | HTTP headers and partial tokens already reached the app; Kaeso emits an error event and logs `stream_interrupted` |

Before each retry, Kaeso waits between `0.25` and `2` seconds (or the provider's `Retry-After` when 5 seconds or less). All retries of a step share that step's `timeout_seconds` budget, so 3 retries cannot multiply your maximum wait time by four.

### Stream failures before the first token now fall back

In 0.7.0, a streaming request counts as answered only once it carries output. If a provider opens a stream and immediately sends an error event before any output — for instance when an account hits its plan limit — Kaeso treats the step as failed and moves on to the next provider key or the step's fallback, just as it does for a non-streamed call.

## 2. Next provider key before next model

When a project assigns [several keys of the same provider](https://kaeso.app/articles/provider-key-pools) (for example two OpenAI accounts or Azure deployments in two regions), key failover happens **inside** the model step before the route falls back to a different model:

1. Each caller starts on its sticky weighted key so prompt caches stay warm.
2. If that key is rate-limited (`429`), out of credit, signed out or refused by the provider, Kaeso marks the key as waiting in Valkey and immediately tries the project's next assigned key for that provider.
3. Only when no assigned key for that provider can serve the request does the alias route move to its fallback model step.

## 3. Alias route fallbacks and shared Valkey cooldowns

When a model step exhausts its retries (and any additional keys in the project's pool), the alias route checks the step's `fall_back_on` reasons:

- `unavailable` (default): unreachable provider, timeout, `5xx`, overloaded, refused provider key or model not served.
- `limited` (default): provider `429` or a Kaeso limit/budget for that specific model.
- `unsupported` (default): the request uses images, PDFs, tools or a JSON schema that KPMR says the model does not support — skipped before sending a byte over the network.
- `rejected` (opt-in): the provider returned `400` or `413` (such as a prompt exceeding the first model's context window when your fallback model has a larger one).

### Shared cooldowns across every gateway replica

When a step fails for a reason that lasts, testing it again on the very next request wastes latency. Kaeso places the failed step on a temporary cooldown in Valkey, shared across every gateway replica in your [Docker Compose](https://kaeso.app/articles/deploy-kaeso-on-a-linux-server) or [Kubernetes](https://kaeso.app/articles/deploy-kaeso-on-kubernetes) deployment:

| Failure kind | Cooldown in Valkey | Scope |
| --- | --- | --- |
| Unreachable, timeout, `5xx` or overloaded | 30 seconds | That model step |
| Rate limit (`429`) | `Retry-After` duration, up to 5 minutes | That key / model step |
| Model not served to the project's key | 5 minutes | That model and key |
| Refused provider key or empty balance | 5 minutes | Every model using that provider key |
| Account plan limit reached (e.g. ChatGPT plan) | 5 minutes, or as long as the provider states up to 1 hour | Every model using that account |

While a step is on cooldown — and a later fallback step in the route is ready to answer — incoming requests skip the broken step in sub-millisecond time. The first gateway replica that sees the model answer again clears the cooldown for the whole cluster.

## Shorter timeouts from the app: `kaeso-timeout`

An interactive UI often wants a faster fallback than a background job calling the same alias. Any request can send `kaeso-timeout: 20` (in seconds) to cap how long each step waits for the first byte (or a complete non-streamed reply) before failing as `unavailable` and moving to the fallback. `kaeso-timeout` can only shorten a step's or model's configured timeout, never lengthen it.

## How retries and fallbacks appear in headers, logs and metrics

Every reply to an alias carries an RFC 9651 structured `kaeso-route` header showing each step reached or skipped, its status, its duration in milliseconds when it failed, and `tries` whenever a step sent the request more than once (via same-model retry or key failover):

```http
kaeso-route: "route";model="anthropic/claude-sonnet-5-5";status=529;dur=842;tries=2, "route.fallback";model="openai/gpt-6-sol";status=200
```

- **Costs and budgets:** Failed tries and failed steps cost `$0` in Kaeso. A step that fails releases its budget reservation in Valkey before the fallback step checks its own limits ([budgets and limits](https://kaeso.app/articles/budgets-limits-and-usage)).
- **Request logs:** The [request log](https://kaeso.app/articles/request-logs-and-privacy) lists every tried or skipped step under **Tried first**, marks same-model retries as **tried again**, and lets you filter specifically for requests that **Fell back**.
- **Prometheus metrics:** `kaeso_upstream_retries_total{provider, outcome}` (`answered` vs `gave_up`) and `kaeso_alias_fallbacks_total{provider, reason}` track both layers on port 9100.

## Next steps

- [Fallbacks, conditions and splits with alias routes](https://kaeso.app/articles/alias-routes): how conditions, weighted splits and route traces work.
- [Provider key pools](https://kaeso.app/articles/provider-key-pools): spread traffic and fail over across several keys of one provider.
- [Alias routes in the docs](https://docs.kaeso.app/concepts/alias-routes): full Platform API schema and route trace endpoint.

Product names in this article belong to their owners and are used only to name the software and services involved. Kaeso is not affiliated with or endorsed by them.

By Kaeso Team

## More articles

- [Guardrails for model requests and replies](https://kaeso.app/articles/guardrails-in-kaeso.md): Check chat requests before they reach a provider, and replies before they reach your app. Built-in rules mask secrets and personal data into placeholders and restore them in the reply, and HTTP guardrails run checks of your own.
- [Key pools, weights and rotation across provider keys](https://kaeso.app/articles/provider-key-pools.md): Assign several keys of one provider to a Kaeso project with weights. Each caller sticks to one key so prompt caches stay warm, failed or rate-limited keys give way automatically, and keys rotate without app changes.

[See all articles](https://kaeso.app/articles.md)

## Own the gateway. Own the record

```bash
curl -fsSL https://kaeso.app/install.sh | sh
```

[Install Kaeso](https://docs.kaeso.app/self-hosting/installation) · [Open the live demo](https://demo.kaeso.app)
