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

# Multi-Key Failover

> Configure multiple provider keys for automatic failover across rate limits and errors.

Add multiple provider keys to the same routing rule in an [access key configuration](/ai-gateway/guides/access-key-configurations). The gateway tries keys in order when one fails.

Your application sends only an [access key](/ai-gateway/concepts/access-keys)—provider keys are stored in app.ngrok.ai and referenced by the configuration.

## Setup

1. [Add two or more provider keys](/ai-gateway/guides/attaching-provider-keys#add-a-provider-key) for the same provider
2. Create or edit a configuration with an ordered `user` step listing both key IDs
3. Assign the configuration to your access key

```json theme={null}
{
  "router": {
    "rules": [
      {
        "provider": "openai",
        "steps": [
          {
            "type": "user",
            "keySelectionStrategy": "ordered",
            "keys": [
              { "id": "aigpk_primary" },
              { "id": "aigpk_backup" }
            ]
          }
        ]
      }
    ]
  }
}
```

## Failover sequence

```
1. Request arrives with access key
2. Try primary OpenAI key → Rate limited (429)
3. Try backup OpenAI key → Success
```

## Next steps

* [Multi-key failover guide](/ai-gateway/guides/key-selection-failover): Full details
* [Bring your own provider key](/ai-gateway/guides/attaching-provider-keys): Store credentials
* [Multi-provider failover](/ai-gateway/examples/multi-provider-failover): Fail over across providers
