Skip to content
Sign in Create account

Routing and failover

The gateway routes each request with your account’s routing defaults and the provider features it supports, in this order:

  1. Capability check. If the API key does not allow the requested model, the gateway returns 403.
  2. Your own provider key (BYOK). If you have connected your own provider credentials for this model, the gateway uses them. The provider key is stored encrypted and is decrypted in memory only for the duration of one request.
  3. Saved routing rules. You can save and validate provider-routing rules in the portal, but they are not applied to requests yet; requests follow the account’s default routing.
  4. Failover. When failover is enabled, an upstream 5xx or 429, or an open circuit breaker, can move the request to the next eligible provider. Failover is off for trial requests and when the remaining balance is at or below the configured low-balance threshold. The receipt records the route.
  5. Streaming. For stream: true, the gateway proxies the SSE stream and computes the receipt over the final accumulated content.

Failover behavior

  • With failover enabled and a provider_preference list (a payload field or the X-CloakAPI-Provider-Preference header), the gateway tries eligible providers in order. It skips a provider whose circuit breaker is open and moves on after a retryable upstream error.
  • Trial requests, and requests at or below the configured low-balance threshold, use only the primary provider.
  • Caller errors (400, 401, 403, 404, 422) are returned immediately; the gateway does not try the next provider.
  • The x-cloakapi-provider-used response header names the provider that served the request.
  • Receipt continuity: when the tenant chain cursor is available, the receipt advances that chain by one sequence number. If the cursor is unavailable, the gateway can issue an unlinked fallback receipt. See the chain fields in the protocol.

Routing configuration

GET /api/v1/providers/routing returns the routing configuration for your tenant. Example:

{
"providers": ["anthropic", "openai"],
"arbitrage": {
"enabled": true,
"latency_weight": 0.3,
"cost_weight": 0.5,
"quality_weight": 0.2,
"cache_ttl": 60
},
"default": "anthropic",
"complete_local": false
}

The providers array lists the providers that are enabled, configured and available to your tenant. The values above are examples; the response shows the gateway’s current configuration. The arbitrage fields describe configuration only: they do not mean that saved provider-routing rules are applied to requests.