> ## Documentation Index
> Fetch the complete documentation index at: https://docs.portkey.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Fallbacks

> Automatically switch to backup LLMs when the primary fails.

> [!NOTE]
>
> Available on all Portkey [plans](https://portkey.ai/pricing).

Specify a prioritized list of providers/models. If the primary LLM fails, Portkey automatically falls back to the next in line.

![](https://mintcdn.com/portkey-docs/VWP2Y8zxPP5N4jE6/images/product/ai-gateway/ai-12.avif?fit=max\&auto=format\&n=VWP2Y8zxPP5N4jE6\&q=85\&s=dfa00c4b86100e925367b2a7a93dbdb5)

## Examples

```json Between Models theme={"system"}
{
  "strategy": { "mode": "fallback" },
  "targets": [
    { "override_params": { "model": "@openai-prod/gpt-4o" } },
    { "override_params": { "model": "@anthropic-prod/claude-3-5-sonnet-20241022" } }
  ]
}
```

```json Between Providers (model from request) theme={"system"}
{
  "strategy": { "mode": "fallback" },
  "targets": [
    { "provider": "@openai-prod" },
    { "provider": "@azure-prod" }
  ]
}
```

```json On Rate Limit Only (429) theme={"system"}
{
  "strategy": { "mode": "fallback", "on_status_codes": [429] },
  "targets": [
    { "provider": "@openai-prod" },
    { "provider": "@azure-prod" }
  ]
}
```

```json Multi-tier Fallback theme={"system"}
{
  "strategy": { "mode": "fallback" },
  "targets": [
    { "override_params": { "model": "@openai-prod/gpt-4o" } },
    { "override_params": { "model": "@anthropic-prod/claude-3-5-sonnet-20241022" } },
    { "override_params": { "model": "@google-prod/gemini-1.5-pro" } }
  ]
}
```

> [!NOTE]
>
> The `@provider-slug/model-name` format automatically routes to the correct provider. Set up providers in [Model Catalog](https://app.portkey.ai/model-catalog).

[Create](https://docs.portkey.ai/docs/product/ai-gateway/configs.md#creating-configs) and [use](https://docs.portkey.ai/docs/product/ai-gateway/configs.md#using-configs) configs in your requests.

## Trigger on Specific Status Codes

By default, fallback triggers on any **non-2xx** status code.

Customize with `on_status_codes`:

```json theme={"system"}
{
  "strategy": { "mode": "fallback", "on_status_codes": [429, 503] },
  "targets": [
    { "provider": "@openai-prod" },
    { "provider": "@azure-prod" }
  ]
}
```

## Tracing Fallback Requests

Portkey logs all requests in a fallback chain. To trace:

1. Filter logs by `Config ID` to see all requests using that config
2. Filter by `Trace ID` to see all attempts for a single request

![](https://mintcdn.com/portkey-docs/VWP2Y8zxPP5N4jE6/images/product/ai-gateway/ai-13.avif?fit=max\&auto=format\&n=VWP2Y8zxPP5N4jE6\&q=85\&s=e46ffcdece7f95da96a4c0e2b1d49f7d)

## Combine with Other Strategies

Fallback targets are fully composable — each target can be a load balancer, a conditional router, or another fallback. Any strategy can nest inside any other.

> [card] [Fallback When the Whole Cluster Goes Down](https://docs.portkey.ai/docs/guides/use-cases/combining-routing-strategies.md#fallback-when-the-whole-cluster-goes-down)
>
> The primary target is a load balancer cluster. Individual endpoint failures stay within the cluster — only a full provider outage triggers the cross-model backup.

> [card] [Smart Failover by Request Context](https://docs.portkey.ai/docs/guides/use-cases/combining-routing-strategies.md#smart-failover-by-request-context)
>
> When the primary fails, a conditional router picks the best backup based on request context — keeping EU users on EU infrastructure even during outages.

> [card] [Isolate Failures Between Model Families](https://docs.portkey.ai/docs/guides/use-cases/combining-routing-strategies.md#isolate-failures-between-model-families)
>
> Give each load-balanced slot its own independent fallback chain. One model family failing doesn't trigger another family's backup.

> [card] [All Patterns Together](https://docs.portkey.ai/docs/guides/use-cases/combining-routing-strategies.md#the-full-config)
>
> See a complete config combining conditional routing, load balancing, and fallbacks across four model families.

## Considerations

* Ensure fallback LLMs are compatible with your use case
* A single request may invoke multiple LLMs
* Each LLM has different latency and pricing

***

> [card] [Portkey is now PRISMA AIRS AI Gateway. See it in action.](https://www.paloaltonetworks.in/ai-security/ai-gateway?utm_source=portkey\&utm_medium=referral\&utm_campaign=prisma_airs\&utm_content=docs_nav#contact)
>
> Contact Us


## Related topics

- [Testing Application Resilience with Fallbacks](https://docs.portkey.ai/docs/guides/use-cases/fallbacks-test.md)
- [Fallback from SDXL to Dall-e-3](https://docs.portkey.ai/docs/guides/use-cases/fallback-from-sdxl-to-dall-e-3.md)
- [Setup OpenAI -> Azure OpenAI Fallback](https://docs.portkey.ai/docs/guides/use-cases/setup-openai-greater-than-azure-openai-fallback.md)
- [Smart Fallback with Model-Optimized Prompts](https://docs.portkey.ai/docs/guides/use-cases/smart-fallback-with-model-optimized-prompts.md)
- [Combining Routing Strategies: Conditional, Load Balancing & Fallbacks](https://docs.portkey.ai/docs/guides/use-cases/combining-routing-strategies.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.