Skip to content

Circuit breaker

The circuit breaker automatically stops routing traffic to a provider that is consistently failing, then probes it after a cooldown period to detect recovery. This prevents cascading failures where a broken provider repeatedly consumes retries on every request.

State machine

The circuit breaker operates as a three-state machine:

stateDiagram-v2
    [*] --> CLOSED
    CLOSED --> OPEN      : failures ≥ threshold
    OPEN --> HALF_OPEN   : cooldown elapsed
    HALF_OPEN --> CLOSED : probe succeeds
    HALF_OPEN --> OPEN   : probe fails (restart cooldown)
State Behaviour
Closed (healthy) All requests route normally
Open Requests skip this provider entirely; the next target in the fallback chain is tried
Half-open (probation) Requests are admitted again to test recovery. The first attempt that delivers an answer closes the breaker; the first failure re-opens it and restarts the cooldown (the shared Myra model breakers follow a two-tenant rule instead — see the Myra note below)

The default state is Closed. No state is stored until the first failure is recorded.

💡 Note: While the breaker is half-open, every incoming request is admitted to probe recovery — not strictly a single one. The probe is judged on the attempt's delivered outcome, not on the HTTP status: an upstream that answers 200 with no answer at all has not proven recovery, so it neither closes the breaker nor clears the failure count.

Configuration fields

Field Type Default Description
enabled boolean false Set to true to activate the circuit breaker
failure_threshold integer 5 Number of failures within window_sec before the breaker opens. Whole number from 1 to 10000
window_sec integer 60 Window in seconds over which failures are counted. The counter is created by the first failure with a lifetime of window_sec and is not extended by later failures, so the window is tumbling, not sliding: failures are counted for window_sec seconds from the first one and then the count resets in one step. A burst that straddles the end of a window can therefore need up to twice the threshold (minus one) in failures to open. Must be a whole number from 1 to 86400
cooldown_ms integer 30000 Milliseconds to wait in the Open state before allowing a probe. Whole number from 1 to 86400000
failure_status_codes array [500,502,503,504] HTTP status codes that count as failures. Connection and timeout errors always count regardless of this list. Must be a JSON array of whole numbers; an empty array [] means "never trip on any HTTP status" (connection/timeout errors still count).

Entering the numbers in the gateway settings. The three number fields (failure threshold, window, cooldown) accept digits only. Anything that is not a whole number inside the range shown above (for example 1e, 1.5, +5, 0x10, abc, or a number that is too large) is refused inline with an error and nothing is saved. A field left empty uses its default.

Validation & fail-safe. failure_status_codes is validated when a gateway is created or updated: a value that is not an array of whole numbers (a string, a number, a non-empty object, or an array containing a non-integer element) is rejected with 400. Should a malformed value ever be present in stored config (e.g. written by an older client), the runtime fails closed to the default [500,502,503,504] rather than erroring — the breaker always has a well-defined set.

What counts as a failure

The following events increment the failure counter:

  • HTTP 5xx from the provider — only codes listed in failure_status_codes count (default: 500, 502, 503, 504).
  • Connection errors — DNS failure, connection refused, TLS error — always counted regardless of failure_status_codes.
  • Timeouts — treated as connection errors.

  • A dead turn from a self-hosted (inline) model — a turn that finishes cleanly with 200 (finish_reason: stop) but produces no answer at all (an instant end-of-turn). The gateway retries such a turn once automatically; only a turn that is still dead after the retry counts as a failure. This bypasses failure_status_codes — the status was 200. A turn that produced no answer because it was length-capped (finish_reason: length, Anthropic stop_reason: max_tokens — a caller's tiny max_tokens, such as a one-token health probe, or a prompt that filled the window) is not a dead turn: it is neither retried nor counted (see the neither-success-nor-failure list below).

The following events do not increment the failure counter:

  • 4xx responses from the provider — bad request, auth failure, and similar client errors are not treated as provider failures, unless the status is listed in failure_status_codes. Note that 429 is counted for the built-in Myra fleet breaker.

💡 Note: The built-in Myra fleet breakers are separate from the per-gateway breaker and are not configurable. They trip after 3 failures within one failure window (window_sec 30 — failures are counted for 30 seconds from the first one; see failures below), stay open for 15 seconds, and count HTTP 500, 502, 503, 504, and 429 — deliberately different from the per-gateway defaults (5 failures / 60 s / 30 s cooldown) described above. They are kept per model: each self-hosted model runs on its own deployment, so failures of one model (for example a degraded gemma-4-31b-it pod returning 502, or a hung pod timing out) affect that model only — every other Myra model, including the default qwen3.8-27b, keeps serving.

Each Myra model has two breakers. Your gateway's own breaker for the model counts the failures of your gateway's requests and, once open, skips the model for your gateway only. The shared breaker for the model is common to every tenant, but it opens only when the failures in its window come from at least two different tenants — a single tenant's failures, however many, can never take a model offline for anybody else (several gateways of the same tenant count as one tenant; requests of the anonymous public documentation assistant, and requests without a usable tenant id, never count as a second tenant). It protects against one tenant, not against one party acting through two tenants — for example two accounts, or another tenant's public email, form or webhook trigger that runs a prompt as that tenant. A request counts at most once per model, however many retries it makes, so one failing request with the default retries is one failure, not three. When the shared breaker's cooldown has elapsed it lets requests through again (half-open); it closes only on a successfully delivered answer, and a failure re-opens it only when it comes from a tenant other than the tenant whose request first went through after the cooldown (the probing tenant — a request that your gateway's own breaker or the fleet breaker still skips does not probe). The probing tenant's own failures leave it half-open (they count against that tenant's own breaker instead), and so does a failure without a usable tenant id. If the first request after the cooldown has no usable tenant id, the first tenant whose request then fails takes the probing role. A shared breaker stays half-open until a delivered answer closes it or another tenant's failure re-opens it; it does not fall back to closed on a timer.

A separate fleet breaker covers the shared entry point: when the gateway cannot establish a connection to the Myra fleet at all (connection refused, DNS failure, connect timeout, TLS handshake failure), those failures count against the fleet breaker, and while it is open every Myra model is skipped for everyone. A failure on an already established connection (a reset, a read timeout) counts against the model's breakers. The TCP connect and the TLS handshake to the fleet are each bounded by a fixed 5 seconds, independent of any gateway or rule timeout_ms. A timeout that fires under a deadline you chose yourself is not counted against any Myra breaker — it reflects your own budget, not an unhealthy model: a gateway or rule timeout_ms below 20 seconds, or a routing-rule timeout_ms below 180 seconds (the platform's own response budget for very long prompts) when the rule's own deadline is the one that fired — a tighter platform limit firing still counts. If the fleet is reachable but every model answers with server errors, each model's breakers open on their own failures: your gateway's own breaker after three of your failing requests, the shared one once at least two tenants have failed. Your gateway's own Myra model breakers are always active, even when the gateway's circuit breaker setting is disabled. Breaker state is kept per gateway node: each node of an active-active deployment trips on the failures it sees itself, so "two tenants" means two tenants failing on the same node. A Myra endpoint that a gateway overrides itself (provider_base_urls.myra) is not the shared fleet: it has only the per-gateway breakers (one per model), with the built-in Myra settings above, active even when the gateway's own breaker is disabled.

What counts as a success — and what counts as neither

Only an attempt that actually delivered an answer records a success (and a success is the only thing that closes a breaker and clears its failure count).

The following outcomes record neither a success nor a failure. They can never trip a healthy breaker, and they can never close one that real failures opened:

  • A discarded attempt — one the gateway retried itself (an automatic dead-turn retry, an unparseable response, a failed streaming leg). The retry's own outcome decides.
  • A turn the client cancelled mid-stream — pressing Stop tells you nothing about the provider.
  • A stream that broke mid-flight, or one the provider terminated with an error event.
  • A turn that delivered zero visible characters — for example a reasoning model that spent its whole budget on internal reasoning, or a turn cut off by the caller's max_tokens before any visible token (a one-token health probe). (Applies to the OpenAI-compatible and buffered response paths; the Anthropic-native passthrough does not classify empty responses.)

Interaction with retries and fallbacks

The circuit breaker is checked once per target in the fallback chain — not before each same-provider retry. Consider a request with retry_count: 2 and one fallback, where the breaker of OpenAI is open:

  1. Check the breaker of OpenAI → Open → skip OpenAI entirely.
  2. Check the breaker of Anthropic → Closed → attempt Anthropic.
  3. Anthropic succeeds → record success → return response.

Without a circuit breaker, the gateway would exhaust two retry attempts on a failing OpenAI before trying Anthropic.

Configuring the circuit breaker

Before you begin, ensure the following conditions are met:

  • ☑ You have admin access.
  • ☑ A gateway exists.

Screenshot: Gateway configuration page with circuit breaker section The circuit breaker configuration of the gateway.

Proceed as follows to configure the circuit breaker for a gateway:

  1. Open Organisation › AI setup › Gateways.
    • The gateway list opens.
  2. Click on the gateway you want to configure.
    • The gateway page opens on the Endpoint & keys tab.
  3. Click on the Edit button in the Gateway card header.
    • The gateway settings page opens (…/gateways/<gateway>/settings).
  4. Open the Reliability tab and select the Enable circuit breaker check box.
    • The circuit breaker configuration fields appear.
  5. Enter a value in the Failure threshold text field.
    • The failure threshold is set.
  6. Enter a value in the Window (s) text field (in seconds).
    • The counting window is set.
  7. Enter a value in the Cooldown (ms) text field (in milliseconds).
    • The cooldown period is set.
  8. Click on the Save Changes button in the bar at the bottom of the page.

-> The circuit breaker configuration is saved and takes effect immediately.

💡 Note: The editor exposes only the enable check box, failure threshold, window, and cooldown. The set of HTTP status codes that count as failures (failure_status_codes) is configurable through the API only — see the example below.

To configure the circuit breaker via the API:

{
  "circuit_breaker": {
    "enabled": true,
    "failure_threshold": 5,
    "window_sec": 60,
    "cooldown_ms": 30000,
    "failure_status_codes": [500, 502, 503, 504]
  }
}

Status API

Check the current state of the breaker for all providers on a gateway:

GET /admin/v1/gateways/{id}/circuit-breaker

Response:

{
  "openai": {
    "state": "open",
    "failures": 7,
    "opened_at": 1748123456
  },
  "anthropic": {
    "state": "half_open",
    "failures": 5,
    "opened_at": 1748123401
  }
}

Only providers whose breaker is currently open or half-open appear in the response. A missing provider entry means the breaker is closed; when a breaker closes, its recorded state and failure count are cleared.

💡 Note: failures counts only while the breaker is closed — it is not incremented while a breaker is open or half-open, and the counter expires on its own window_sec after the first failure. A row reading "state": "open", "failures": 0 is therefore normal for a breaker that has been open for a while, not a bug.

Every state transition is also logged with a [circuit_breaker] prefix (transition=closed->open reason=provider_5xx failures=3/3 ...) and counted in the aig_circuit_breaker_transitions_total metric, labelled by provider, scope (gateway or global), transition and reason. For the Myra breakers the provider label — and the provider= field of the log line and the provider field of the circuit_open webhook — is myra/<model> for a model breaker (for example myra/gemma-4-31b-it) and myra for the fleet breaker (the fleet breaker's circuit_open webhook is unchanged). A failure that does not move the shared Myra breaker because all its evidence comes from one tenant is counted under the transitions closed->held and half_open->held. Your gateway's own Myra model breakers appear in the per-gateway status API above (as myra/<model>) and send your gateway's circuit_open webhook; the shared Myra breakers are not tied to one gateway, so they appear in neither — use the log lines and the metric (scope global).

The dashboard UI shows this status in a live table on the Models & routing tab of the gateway page when the circuit breaker is enabled. The Circuit Breaker card is collapsed on first load; expand it to see the live status table.

Example configurations

Conservative — trip only on sustained outage

{
  "circuit_breaker": {
    "enabled": true,
    "failure_threshold": 10,
    "window_sec": 120,
    "cooldown_ms": 60000
  }
}

Opens after 10 failures in 2 minutes. Probes after 1 minute. Appropriate when providers have occasional transient errors.

Aggressive — trip fast, recover fast

{
  "circuit_breaker": {
    "enabled": true,
    "failure_threshold": 3,
    "window_sec": 30,
    "cooldown_ms": 10000
  }
}

Opens after 3 failures in 30 seconds. Probes after 10 seconds. Appropriate when you have multiple healthy fallbacks and want to shed load immediately.

See also