Skip to main content
Failover automatically switches between LLM providers when one fails, keeping agents running during API outages or rate limits.
The user sends a message; if the primary LLM profile fails, the agent tries the next profile in the failover chain.
Failover integrates with LLM Error Classification via FailoverDecision, which coordinates profile rotation with typed error handling.

Quick Start

1

Run an agent with failover

2

Add more profiles

3

Monitor provider health


How failover activates during retries

Failover now drives LLM retries through direct integration with the retry mechanism:
  • On every LLM call, the system first gets the current profile via get_next_profile() and applies its api_key, base_url, and model settings
  • On success, mark_success(profile) is called to track the working provider
  • On failure, mark_failure(profile, error, is_rate_limit=...) marks the provider as failed, then get_next_profile() fetches the next available provider
  • Profile switching overrides non-retryable classification—one extra attempt is always granted after switching providers
  • The LLM automatically updates request parameters (api_key, base_url, model) when switching between profiles

How It Works


Configuration Options

FailoverManager

Manager class reference

AuthProfile

Provider credential profile

Auth Profiles

Configure credentials for each provider:

Common Patterns


Failover Callbacks

React to failover events:
Sync + async parity (from PraisonAI #2386). The retry callback now fires on both the sync (agent.chat) and async (await agent.achat) LLM paths. Older versions silently skipped the callback on async calls — upgrade to get retry observability for gateway bots, async tools, and any await-based agent code.

Provider Status

Monitor provider health:

Best Practices

Always have at least 2-3 providers configured. This ensures availability even during major outages.
Enable exponential_backoff=True to avoid hammering providers during issues. This helps you stay within rate limits.
Order providers by cost and reliability. Put cheaper/faster providers first, with premium providers as fallback.
Use the on_failover callback to track when failovers occur. This helps identify provider issues early. The callback fires on both sync and async LLM paths — works the same whether your agent runs via agent.chat() or await agent.achat().
Pair failover with LLM Error Classification so FailoverDecision coordinates profile rotation with typed errors.
Load keys from environment variables or a secrets manager — never commit credentials to version control.

LLM Error Classification

Typed errors that drive failover decisions

Providers

Supported LLM providers