This guide shows five real-world patterns with complete configs.
Scale One Model Across Multiple Providers
Pattern: Conditional → Load Balancer Use conditional routing to match a model alias, then send that alias to a load balancer spread across multiple providers. Traffic forclaude-sonnet distributes evenly across Anthropic, Vertex AI, and Bedrock — each with independent rate limit buckets, effectively tripling throughput.
model: "claude-sonnet" and Portkey handles the rest.
Give Each Model Its Own Fallback
Pattern: Conditional → Fallback Each conditional branch points to its own independent fallback chain. Whenclaude-sonnet is requested, Portkey tries Anthropic first, then Vertex AI, then Bedrock — in order. When gpt-4o is requested, it tries OpenAI first, then Azure. The two chains are completely isolated: an OpenAI outage has no effect on Claude routing.
on_status_codes controls when a fallback triggers. If the primary returns a 400 (bad request) but your list only includes [429, 500, 502, 503, 504], the fallback will not activate — the error is returned to the caller immediately. Tune this list based on which errors you consider recoverable.on_status_codes, retry configuration, and provider ordering.
Smart Failover by Request Context
Pattern: Fallback → Conditional Router The fallback target doesn’t have to be a static model — it can be a conditional router that picks the best available backup based on request context. This is useful for compliance and data-residency requirements: if the primary fails, EU users automatically route to an EU-hosted backup while others get a US backup. For this pattern to work, the application must pass the routing dimension in the request metadata. The conditional router reads it via themetadata.* query path:
user_region via the x-portkey-metadata header (or the metadata SDK parameter):
Fallback When the Whole Cluster Goes Down
Pattern: Fallback → Load Balancer The primary target is a load balancer across multiple providers. Individual provider failures are handled by the load balancer — traffic redistributes within the cluster. Only when all providers in the cluster fail does the outer fallback activate. This avoids over-triggering cross-model fallbacks while still guaranteeing zero downtime.Isolate Failures Between Model Families
Pattern: Load Balancer → Fallback (per slot) Each load-balanced slot is itself a fallback chain. Traffic distributes across two model families (OpenAI and Anthropic), and each family has its own independent backup. An OpenAI outage triggers the Azure fallback for that leg only — Anthropic traffic is unaffected.The Full Config
All four patterns combined: a conditional router with four model aliases, each targeting a different strategy composition.Using the Config
Setting Up AI Providers
Add each provider in the Model Catalog and assign it a slug. The slug becomes the@provider-slug prefix in model strings.
See Model Catalog for the full setup guide.
Observability
Every request is logged with its full routing path. In Portkey Logs:- Filter by Config ID to see all requests through this config
- Filter by Trace ID to see every attempt for a single request — which load-balanced target was selected, whether a fallback triggered, which conditional branch matched
- The model field shows the actual provider model used (not the alias)
trace_id for programmatic tracing:
When to Use Each Pattern
Related
- Conditional Routing — conditions, operators, and metadata-based routing
- Load Balancing — weights, sticky sessions, and multi-key distribution
- Fallbacks — status code triggers and tracing fallback chains
- Gateway Configs — creating, saving, and referencing configs
- Model Catalog — setting up AI Providers and managing model access
- Resilient load balancers with fallbacks — Node.js deep-dive

