AI › AI Tools

Verifying retries, cooldowns, and fallbacks in LiteLLM Proxy

How LiteLLM Proxy v1.112.0 runs num_retries, cooldowns, and fallbacks during 503 outages, and why x-litellm-attempted-retries misses prior failures.

Verifying retries, cooldowns, and fallbacks in LiteLLM Proxy

When an upstream LLM deployment returns HTTP 503, LiteLLM Proxy handles recovery across three separate layers: num_retries, allowed_fails with cooldown_time, and fallbacks. Testing ghcr.io/berriai/litellm:v1.112.0 against a stateful local OpenAI-compatible mock server showed that order priority changes how response headers count fallbacks, and that x-litellm-attempted-retries on a fallback response reports 0 even after four upstream 503 calls.

All configurations and measurements below come from non-streaming requests executed against ghcr.io/berriai/litellm:v1.112.0 on Docker Engine 29.9.3 (macOS) paired with a local Python OpenAI-compatible upstream server that injects HTTP 200/503 responses on demand.

How retries, cooldowns, and fallbacks divide the work

Consider an order and payment notification summary service (order-digest-api) that has to turn shipping delay events into one-line customer alerts within a tight latency budget. If one upstream inference deployment starts returning HTTP 503, the service should keep answering without leaking transient failures to callers. LiteLLM Proxy splits that fault handling into three distinct mechanisms:

  1. Same-group retries (num_retries): Multiple deployments (primary-a, primary-b) share one logical model name (primary-chat). When one deployment returns a retryable error, the router tries again inside the same group.
  2. Deployment cooldowns (allowed_fails, cooldown_time): Once a specific deployment crosses the failure threshold, the router excludes it from selection for a fixed window so later requests skip the broken endpoint.
  3. Cross-group fallbacks (fallbacks): When every deployment in primary-chat fails or sits in cooldown, the router switches the request to a separate backup group (backup-chat).
flowchart TD
    A["order-digest-api\n(model: primary-chat)"] --> B["LiteLLM Proxy Router"]
    B --> C{"primary-chat deployments\n(primary-a / primary-b)"}
    C -->|"HTTP 503"| D["Same-group retry &\ncooldown isolation"]
    D -->|"All primary failed"| E["Fallback to backup-chat\n(backup-a)"]
    C -->|"HTTP 200"| F["Response + x-litellm-* headers"]
    E -->|"HTTP 200"| F

Each setting solves a different failure mode, so it helps to separate what you expect from each one before editing config.yaml:

SettingScopeTriggerWhat it fixesPrimary signal to inspect
num_retriesDeployments in one model groupRetryable errors (429, 5xx)Absorbs transient errors within one requestx-litellm-attempted-retries, upstream logs
allowed_fails + cooldown_timeSingle deployment (model_info.id)Failures exceed thresholdCuts tail latency by skipping unhealthy endpointsx-litellm-model-id on subsequent requests
fallbacksSeparate model groupsPrimary group exhausted or cooled downPreserves availability via another region or providerx-litellm-model-group, x-litellm-attempted-fallbacks

That setup isn’t always the right default. If your application’s OpenAI SDK or HTTP client already retries two or three times on 5xx errors, stacking LiteLLM Proxy retries on top creates retry amplification: a single overloaded upstream gets hit by client retries multiplied by proxy retries across every deployment. Auto-fallback can also break callers silently if order-digest-api depends on strict JSON Schema enforcement or provider-specific tool calling that the backup model doesn’t honor identically. In those cases, HTTP 200 masks a downstream parser failure unless you test contract parity first.

Setting up a deterministic fault-injection environment

Live LLM APIs don’t fail on cue or recover exactly 15 seconds later, so verifying router state transitions requires a controllable upstream. I ran the official ghcr.io/berriai/litellm:v1.112.0 container in Docker Compose and pointed all three deployments at a local Python HTTP server on port 18102.

1
2
3
4
5
6
7
8
9
10
11
12
13
# compose.yaml
services:
  litellm:
    image: ghcr.io/berriai/litellm:v1.112.0
    ports:
      - "14002:4000"
    environment:
      LITELLM_MASTER_KEY: ${LITELLM_MASTER_KEY}
    volumes:
      - ./config.yaml:/app/config.yaml:ro
    command: ["--config", "/app/config.yaml", "--port", "4000"]
    extra_hosts:
      - "host.docker.internal:host-gateway"

In config.yaml, primary-chat owns two deployments (primary-a and primary-b), and backup-chat owns backup-a. Setting model_info.id on every entry makes x-litellm-model-id human-readable instead of an opaque hash.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# config.yaml (priority-ordered variant used for cooldown and fallback tests)
model_list:
  - model_name: primary-chat
    litellm_params:
      model: openai/primary-a
      api_base: http://host.docker.internal:18102/primary-a/v1
      api_key: dummy-upstream-key
      order: 1
    model_info:
      id: primary-a

  - model_name: primary-chat
    litellm_params:
      model: openai/primary-b
      api_base: http://host.docker.internal:18102/primary-b/v1
      api_key: dummy-upstream-key
      order: 2
    model_info:
      id: primary-b

  - model_name: backup-chat
    litellm_params:
      model: openai/backup-a
      api_base: http://host.docker.internal:18102/backup-a/v1
      api_key: dummy-upstream-key
    model_info:
      id: backup-a

router_settings:
  routing_strategy: simple-shuffle
  enable_pre_call_checks: true
  num_retries: 1
  allowed_fails: 1
  cooldown_time: 15
  fallbacks:
    - primary-chat:
        - backup-chat

general_settings:
  master_key: os.environ/LITELLM_MASTER_KEY

Removing order: 1, order: 2, and enable_pre_call_checks: true produces the equal-weight simple-shuffle baseline tested in the next section.

The local mock upstream (upstream.py) uses Python’s standard ThreadingHTTPServer. It exposes /_admin/state to flip each deployment between 200 and 503, /_admin/reset to clear counters between steps, and records every incoming call with a timestamp.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# upstream.py (core handler excerpt, listening on :18102)
STATUS_MAP = {"primary-a": 200, "primary-b": 200, "backup-a": 200}
COUNTS = {"primary-a": 0, "primary-b": 0, "backup-a": 0}
EVENTS = []

# Inside POST /<target>/v1/chat/completions
for target in ("primary-a", "primary-b", "backup-a"):
    if self.path.startswith(f"/{target}/v1/chat/completions"):
        with LOCK:
            code = STATUS_MAP[target]
            COUNTS[target] += 1
            EVENTS.append({"ts": round(time.time(), 3), "target": target, "status": code})
        if code != 200:
            self._send_json(code, {"error": {"message": f"Injected {code} from {target}", "code": str(code)}})
            return
        self._send_json(200, {
            "id": f"chatcmpl-{target}-{COUNTS[target]}",
            "object": "chat.completion",
            "model": target,
            "choices": [{"index": 0, "message": {"role": "assistant", "content": f"[{target}] Order #88412 is delayed and expected tomorrow morning."}, "finish_reason": "stop"}],
            "usage": {"prompt_tokens": 32, "completion_tokens": 24, "total_tokens": 56},
        })
        return

With the mock server running on the host and LiteLLM Proxy started via docker compose up -d, I sent POST /v1/chat/completions requests for primary-chat and compared the proxy’s x-litellm-* headers against the upstream’s recorded call log.

Same-group retries vs. priority ordering

First, I set primary-a to return 503 while keeping primary-b and backup-a healthy (200). Even inside the same primary-chat group, equal-weight simple-shuffle and order-based priority routing behaved differently in both upstream call count and response headers.

Router configActual upstream call sequencex-litellm-model-groupx-litellm-model-idx-litellm-attempted-retriesx-litellm-attempted-fallbacks
Equal weight (no order)primary-a (503) → primary-b (200)primary-chatprimary-b10
Priority (order: 1/2, enable_pre_call_checks: true)primary-a (503) → primary-a (503) → primary-b (200)primary-chatprimary-b01

With no order field, the initial hit on primary-a failed with 503, and the router retried once on primary-b to return HTTP 200. backup-a received zero calls, and the headers matched intuition: x-litellm-attempted-retries: 1 and x-litellm-attempted-fallbacks: 0.

With order: 1 and order: 2, the router exhausted num_retries: 1 against primary-a first (two 503s total) before moving down to primary-b. Although the request stayed inside primary-chat and never touched backup-a, the response reported x-litellm-attempted-fallbacks: 1 and x-litellm-attempted-retries: 0. If your alerting rules treat x-litellm-attempted-fallbacks > 0 as “we fell back to the backup model,” priority-ordered deployments will trigger false positives unless you check x-litellm-model-group alongside it.

Isolating failing deployments with cooldowns

Surviving one request isn’t enough if every new request keeps hitting a dead primary first. Using allowed_fails: 1, cooldown_time: 15, and order: 1/2, I sent three consecutive requests right after primary-a failed, then restored primary-a to 200 after the 15-second window expired.

1
2
3
4
5
6
7
8
# Send 3 requests immediately after primary-a enters cooldown
for i in 1 2 3; do
  curl -sS -D - -o /dev/null http://127.0.0.1:14002/v1/chat/completions \
    -H "Authorization: Bearer $LITELLM_MASTER_KEY" \
    -H "Content-Type: application/json" \
    -d '{"model":"primary-chat","messages":[{"role":"user","content":"Summarize the shipping delay for order #88412 in one sentence."}]}' \
    | grep -iE "^HTTP/|x-litellm-(model-id|attempted-)"
done

The upstream counters confirmed clean isolation and automatic recovery:

  • Inside the 15-second cooldown (+0.25s, +0.26s, +0.27s): All three calls returned HTTP 200 directly from primary-b with x-litellm-attempted-retries: 0 and x-litellm-attempted-fallbacks: 0. Upstream call counts for this window were primary-a: 0, primary-b: 3, backup-a: 0.
  • After cooldown expiration (+17.04s): Once primary-a was restored to 200, the very next request routed back to primary-a (x-litellm-model-id: primary-a, upstream counts primary-a: 1, primary-b: 0).

Without manual intervention, cooldowns act as a per-deployment circuit breaker that eliminates repeated 503 probes during an outage and returns traffic to the preferred deployment once the window lapses.

Full primary outage fallback and header blind spots

Next, I injected 503 on both primary-a and primary-b while keeping backup-a at 200, then called primary-chat. The client received HTTP 200 from backup-chat, but comparing the proxy headers with the upstream server’s event log exposed an observability gap:

1
2
3
4
5
6
7
8
9
10
11
12
13
# Final response headers returned by LiteLLM Proxy
HTTP/1.1 200 OK
x-litellm-model-group: backup-chat
x-litellm-model-id: backup-a
x-litellm-attempted-fallbacks: 1
x-litellm-attempted-retries: 0

# Actual events recorded by the local upstream server for that single request
1) primary-a -> 503 (seq 1)
2) primary-a -> 503 (seq 2)
3) primary-b -> 503 (seq 1)
4) primary-b -> 503 (seq 2)
5) backup-a  -> 200 (seq 1)

Even though the upstream server absorbed four HTTP 503 calls (primary-a twice and primary-b twice) before backup-a succeeded, the final response header still reported x-litellm-attempted-retries: 0. That header reflects retries attempted on the winning deployment (backup-a), not the cumulative retry load across the failed primary group.

Terminal output from LiteLLM Proxy v1.112.0 showing same-group retry, 15-second cooldown isolation and recovery, and backup fallback header counts vs upstream 503 logs Figure 1. Verification output from LiteLLM Proxy v1.112.0 and the local fault-injection upstream server covering same-group retry, 15-second cooldown isolation and recovery, and the discrepancy between x-litellm-attempted-retries: 0 and four actual upstream 503 calls.

If you build upstream health dashboards solely from x-litellm-attempted-retries, every outage that lands on a healthy backup on the first try looks like zero retries. Pair x-litellm-model-group and x-litellm-attempted-fallbacks with proxy or upstream error logs when tracking real retry traffic.

Production caveats and checklist

Before rolling these settings out beyond a single local container, check four operational constraints:

Warning: Single-replica cooldowns live in memory Without a shared Redis store, cooldown state stays inside each LiteLLM Proxy process. When you run multiple replicas behind a load balancer, replica B won’t know that replica A already cooled down a failing deployment unless Redis state sharing is configured.

  • Avoid double retries: When LiteLLM Proxy owns num_retries and fallbacks, set your application SDK’s built-in retry count to 0 (or keep it tightly capped) so 503 storms don’t multiply upstream load.
  • Check x-litellm-model-group for real fallbacks: With order-based priority routing, x-litellm-attempted-fallbacks: 1 also fires on same-group priority switches. Alert on x-litellm-model-group changes when you want to detect backup group usage.
  • Measure upstream 5xx from logs, not attempted-retries: Because x-litellm-attempted-retries resets on the winning fallback deployment, pull real failure counts from proxy logs, Prometheus metrics, or upstream telemetry.
  • Test contract parity on backup-chat: Confirm that your backup model matches the primary group’s JSON Schema, tool-calling format, and context limits before enabling automatic fallback for strict API consumers like order-digest-api.

References

Set up automatic provider failover in LiteLLM. If a model or provider fails after num_retries, fallback to another model group for high availability and reliability.
LiteLLM Router for load balancing, routing, retries, cooldowns, and fallbacks (failover) across multiple LLM deployments and providers.
When you make a request to the proxy, the proxy will return the following headers:
This post is licensed under CC BY 4.0 by the author.