Provider Resilience

Automatic failover, health monitoring, and resilience across AI providers

Overview

SBproxy's AI gateway is built for production reliability across multiple AI providers. When a provider goes down, responses slow, or context limits are hit, the gateway handles recovery automatically. No code changes, no manual intervention, no downtime.

Capabilities

  • Proactive health monitoring - The gateway sends lightweight probe requests to each configured provider on a regular interval. Unhealthy providers are automatically removed from the routing pool and restored once they recover.
  • Circuit breaker protection - When a provider starts returning errors, the circuit breaker opens to stop sending traffic. This prevents cascading failures and wasted API spend. The breaker closes automatically once the provider is healthy again.
  • Automatic failover - Configure a fallback chain of providers. If the primary provider fails, the gateway retries on the next provider in the chain. Clients see a single successful response without any error handling on their side.
  • Context window fallbacks - When a request is too large for the target model's context window, the gateway automatically reroutes it to a compatible model with a larger context window. No client-side token counting required.
  • Zero-downtime provider changes - Add, remove, or reconfigure providers without restarting the gateway or interrupting live traffic. Configuration changes take effect immediately.
  • Cost and usage transparency - Every response includes headers with the actual cost, token counts, which provider handled the request, and upstream latency. For streaming responses, the same data is included in the final event. Use this data for real-time cost dashboards and allocation.
  • Smart parameter handling - Enable automatic removal of request parameters that the target model does not support. This lets you send a single request format across all models without worrying about compatibility differences.
  • Request tracing - Every request gets a unique ID that flows from the client through the gateway to the provider and back. Use it for end-to-end debugging and log correlation across systems.
  • Prompt caching - Standard response caching for identical prompts, reducing latency for repeated queries. Cache hits are flagged in response metadata. Semantic caching (vector similarity matching) is available on SBproxy Cloud.

How It Works

Configure multiple providers with a routing strategy and the gateway handles the rest:

proxy:
  http_bind_port: 8080

origins:
  "ai.example.com":
    action:
      type: ai_proxy
      drop_unsupported_params: true
      providers:
        - name: openai
          api_key: sk-...
          models:
            - gpt-4o
            - gpt-4o-mini
          priority: 1
          health_check:
            enabled: true
            interval: 60s
            model: gpt-4o-mini
            timeout: 10s
        - name: anthropic
          api_key: sk-ant-...
          models:
            - claude-sonnet-4-20250514
          priority: 2
          health_check:
            enabled: true
            interval: 60s
            model: claude-sonnet-4-20250514
            timeout: 10s
      routing:
        strategy: fallback_chain
        fallback_order:
          - openai
          - anthropic
        context_fallbacks:
          gpt-4: gpt-4-turbo-128k
        retry:
          max_attempts: 3
          backoff_ms: 1000
          retry_on_status:
            - 429
            - 500
            - 502
            - 503

Test it:

curl -H "Host: ai.example.com" http://localhost:8080/v1/chat/completions   -H "Content-Type: application/json"   -d '{"model": "gpt-4o-mini", "messages": [{"role": "user", "content": "Hello"}]}'

With this configuration, requests go to OpenAI first. If OpenAI is unhealthy or returns an error, the gateway retries on Anthropic. Health checks run every 60 seconds, and context window overflows for gpt-4 automatically reroute to gpt-4-turbo-128k.

Response Metadata

Every AI proxy response includes metadata headers for observability and cost tracking:

HeaderDescription
X-Sb-AI-CostEstimated cost in USD
X-Sb-AI-Tokens-InputInput token count
X-Sb-AI-Tokens-OutputOutput token count
X-Sb-AI-ModelModel used (after any mapping or fallback)
X-Sb-AI-ProviderProvider that handled the request
X-Sb-AI-Latency-MsUpstream provider latency in milliseconds
X-Sb-AI-Cache-HitWhether the response was served from cache
X-Sb-AI-Request-IdRequest ID for end-to-end tracing

For streaming responses, the same data is included in the sb_metadata field of the final SSE event.