Skip to main content
Portrix lets you define fallback models and distribute load across providers so your application stays available even when individual providers hit rate limits or experience outages. Instead of your users seeing a hard error, Portrix silently retries the request against the next model in your chain — all within the same API call.

Why fallbacks matter

AI provider reliability is not guaranteed. Providers can:
  • Go down — planned or unplanned outages affect even major providers
  • Rate limit your account — high-traffic periods can trigger 429 responses
  • Introduce latency spikes — cold model starts or traffic surges slow responses significantly
Without fallbacks, any of these events surfaces directly as an error in your application. With fallbacks configured in Portrix, the gateway retries transparently before returning an error to your code.

Setting up fallbacks

Using the x-portrix-fallback header

Pass a comma-separated list of fallback model IDs in the x-portrix-fallback header. Portrix tries the primary model first, then each fallback in the order listed.
In the examples above, Portrix will:
  1. Attempt openai/gpt-4o first
  2. If that fails, attempt anthropic/claude-3-5-sonnet
  3. If that also fails, attempt mistral/mistral-large
  4. If all three fail, return an error to the caller

Fallback conditions

Portrix triggers a fallback when the upstream provider returns any of the following: Fallbacks are not triggered for client errors (4xx other than 429), such as invalid request shapes or authentication failures. Those are returned immediately.

Load balancing

Using x-portrix-route: balanced

When you want to spread traffic evenly across multiple models — distributing cost or staying within per-provider rate limits — set the routing strategy to balanced alongside a fallback list:
With balanced routing, Portrix distributes requests round-robin across openai/gpt-4o, anthropic/claude-3-5-sonnet, and google/gemini-2.0-flash. If any node is unhealthy, it is temporarily removed from the rotation and the remaining nodes absorb its share. Available routing strategies:

Dashboard configuration

Sending headers on every request works well for dynamic configurations, but for stable production setups you can define named routes in the Portrix dashboard:
1

Open the Routes section

Navigate to Gateway → Routes in the Portrix dashboard.
2

Create a new route

Click New Route, give it a name (e.g. production-chat), and add your primary model plus ordered fallbacks.
3

Set the routing strategy

Choose balanced, cheapest, or fastest from the dropdown.
4

Use the route name in requests

Reference the route by name instead of a model ID:
Named routes are updated centrally — changing a fallback chain in the dashboard immediately affects all requests using that route, with no code changes required.

Testing fallbacks

To verify your fallback chain is working, temporarily swap the primary model for an invalid model ID. Portrix will fail on the primary and cascade to your first fallback:
The model field in the response reflects whichever model actually served the request, making it easy to confirm which fallback was used.
Fallback models may have different capabilities, context windows, or output styles. A prompt carefully tuned for openai/gpt-4o may produce different results on mistral/mistral-large. Test every model in your fallback chain with your actual prompts before enabling fallbacks in production.