Circuit Breaker

Track per-provider:model health across four states (healthy, degraded, down, throttled) to prevent cascading failures and minimize wasted latency.

Four-State Model

Each provider-model combination maintains its own independent health state:

              3 consecutive 5xx          5 consecutive 5xx
  ┌──────────┐  ──────────▶  ┌──────────┐  ──────────▶  ┌──────────┐
  │ healthy  │               │ degraded │               │   down   │
  │          │  ◀──────────  │          │  ◀──────────  │          │
  └──────────┘   success     └──────────┘   success     └──────────┘
                                                              │
                                                     30s probe │ success
                                                              ▼
                                                        back to healthy


                          429 received
  ┌──────────┐  ──────────────────────▶  ┌───────────┐
  │ any state│                           │ throttled │
  │          │  ◀──────────────────────  │           │
  └──────────┘     60s cooldown expires  └───────────┘

State Definitions

StateConditionBehavior
healthyNo recent failures, or a successful probeRequests routed normally
degraded3+ consecutive 5xx errorsRequests still routed, but flagged. The router prefers this provider less if alternatives exist.
down5+ consecutive 5xx errorsRequests blocked. One probe request allowed every 30 seconds to test recovery.
throttledReceived HTTP 429Requests blocked for 60 seconds. Automatic recovery after cooldown.

Next Steps