> ## Documentation Index
> Fetch the complete documentation index at: https://portkey-docs-vertex-context-caching-1771339020.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Fallbacks

> Automatically switch to backup LLMs when the primary fails.

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

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

<Frame>
  <img src="https://mintcdn.com/portkey-docs-vertex-context-caching-1771339020/e3ex2N6Ne-m7rqqL/images/product/ai-gateway/ai-12.avif?fit=max&auto=format&n=e3ex2N6Ne-m7rqqL&q=85&s=6874ffdd34a3a33329e1cf5f50d95a69" width="800" height="732" data-path="images/product/ai-gateway/ai-12.avif" />
</Frame>

## Examples

<CodeGroup>
  ```json Between Models theme={null}
  {
    "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={null}
  {
    "strategy": { "mode": "fallback" },
    "targets": [
      { "provider": "@openai-prod" },
      { "provider": "@azure-prod" }
    ]
  }
  ```

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

  ```json Multi-tier Fallback theme={null}
  {
    "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" } }
    ]
  }
  ```
</CodeGroup>

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

[Create](/product/ai-gateway/configs#creating-configs) and [use](/product/ai-gateway/configs#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={null}
{
  "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

<Frame>
  <img src="https://mintcdn.com/portkey-docs-vertex-context-caching-1771339020/e3ex2N6Ne-m7rqqL/images/product/ai-gateway/ai-13.avif?fit=max&auto=format&n=e3ex2N6Ne-m7rqqL&q=85&s=343ffe30aabdbe946b56862090d8f64d" width="640" height="710" data-path="images/product/ai-gateway/ai-13.avif" />
</Frame>

## Considerations

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