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

# Router Fallback

> Router serves the first candidate that answers, so a rate limit or an outage at one provider falls through to the next instead of failing the run.

Router serves the first candidate that answers, so a rate limit or an outage at one provider falls through to the next instead of failing the run. Candidates are the `catalog_id` values from `GET https://api.router.com/v1/models`, optionally suffixed with a service tier.

```python fallback.py theme={null}
"""
Router Fallback
===============

Cookbook example for `ramp/fallback.py`.

Router serves the first candidate that answers, so a rate limit or an outage at one provider
falls through to the next instead of failing the run. Candidates are the `catalog_id` values
from `GET https://api.router.com/v1/models`, optionally suffixed with a service tier.

`models` replaces `id` rather than adding to it: Router rejects a request that carries both.
"""

from agno.agent import Agent
from agno.models.ramp import RampRouter

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------

agent = Agent(
    model=RampRouter(
        models=[
            "openai:gpt-5.6-luna",
            "anthropic:claude-haiku-4-5",
            "openai:gpt-5-nano:flex",
        ],
        # Move on to the next candidate if a provider has not answered in time
        provider_timeout=30,
        # Attribute the spend in the Router dashboard
        metadata={"team": "platform"},
    ),
    markdown=True,
)

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------

if __name__ == "__main__":
    agent.print_response("Write a haiku about routing", stream=True)
```

## Run the Example

<Steps>
  <Snippet file="create-venv-step.mdx" />

  <Step title="Install dependencies">
    ```bash theme={null}
    uv pip install -U agno openai
    ```
  </Step>

  <Step title="Export your API keys">
    <CodeGroup>
      ```bash Mac/Linux theme={null}
      export RAMP_ROUTER_API_KEY="your_ramp_router_api_key_here"
      ```

      ```bash Windows theme={null}
      $Env:RAMP_ROUTER_API_KEY="your_ramp_router_api_key_here"
      ```
    </CodeGroup>
  </Step>

  <Step title="Run the example">
    Save the code above as `fallback.py`, then run:

    ```bash theme={null}
    python fallback.py
    ```
  </Step>
</Steps>

Full source: [cookbook/90\_models/ramp/fallback.py](https://github.com/agno-agi/agno/blob/v3.0.4/cookbook/90_models/ramp/fallback.py)
