Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

17 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ‡ FallbackRabbit

Auto-generate, test, and optimize LLM fallback chains.

CI PyPI Python 3.11+ License: MIT Tests: 556 Code Style: Ruff

When your primary LLM goes down, FallbackRabbit makes sure you fail gracefully β€” not catastrophically. Build routing chains, simulate outages, measure latency, and export configs for your production stack.

Features

  • πŸ”— Smart Fallback Chains β€” Define priority-ordered provider chains with automatic failover
  • πŸ§ͺ Simulation Engine β€” Run prompts through chains with simulated outages, rate limits, and timeouts
  • ⚑ Real Provider Calls β€” Test against OpenAI, Anthropic, Azure, Ollama, or custom endpoints
  • πŸ“¦ Multi-Format Export β€” Export to LiteLLM, OpenRouter, LangChain, Haystack, or custom Jinja2 templates
  • 🌐 REST API β€” 15 endpoints for chain CRUD, testing, export, and import
  • πŸ“‘ WebSocket β€” Live test progress and chain lifecycle events
  • πŸ“Š Web Dashboard β€” Dark-themed SPA at /dashboard β€” create chains, run tests, export configs
  • πŸ”‘ API Key Auth β€” Static keys with labeled key names, Bearer token, and query param support
  • ⏱️ Rate Limiting β€” Token bucket, per-IP + global limits with burst control
  • πŸ’Ύ Persistent Storage β€” In-memory or SQLite backends
  • πŸ–₯️ Rich CLI β€” Tables, panels, progress bars via Rich

Quick Start

Install

pip install fallbackrabbit
# or
uv add fallbackrabbit

CLI Usage

# Create a starter chain config
fallbackrabbit init my-chain.yaml

# Validate a chain
fallbackrabbit validate my-chain.yaml

# Test a chain with simulated prompts
fallbackrabbit test my-chain.yaml --prompts 10

# Export to LiteLLM config
fallbackrabbit export my-chain.yaml --format litellm --output litellm.yaml

# Start the REST API server
fallbackrabbit serve --port 8000

Python SDK

import asyncio
from fallbackrabbit.models import Chain, Provider, FallbackRule, ErrorType, FallbackAction
from fallbackrabbit.simulator import Simulator, generate_test_prompts

async def main():
    chain = Chain(
        name="production-chain",
        providers=[
            Provider(name="GPT-4", model_id="gpt-4", api_base="https://api.openai.com/v1", priority=0),
            Provider(name="Claude", model_id="claude-3-sonnet", api_base="https://api.anthropic.com", priority=1),
            Provider(name="Llama3", model_id="llama3", api_base="http://localhost:11434", priority=2),
        ],
        fallback_rules=[
            FallbackRule(condition=ErrorType.RATE_LIMIT, action=FallbackAction.RETRY, max_retries=2, wait_seconds=1.0),
            FallbackRule(condition=ErrorType.TIMEOUT, action=FallbackAction.FAILOVER),
        ],
    )

    sim = Simulator(chain=chain)
    prompts = generate_test_prompts(10)
    report = await sim.run_batch(prompts)

    print(f"Success rate: {report.success_rate:.1%}")
    print(f"Average latency: {report.avg_latency_ms:.0f}ms")

asyncio.run(main())

REST API

# Start the server
fallbackrabbit serve --port 8000

# Create a chain
curl -X POST http://localhost:8000/chains \
  -H "Content-Type: application/json" \
  -d '{"name": "my-chain", "providers": [{"name": "gpt-4", "model_id": "gpt-4", "api_base": "https://api.openai.com/v1", "priority": 1}]}'

# Test it
curl -X POST http://localhost:8000/chains/{id}/test \
  -H "Content-Type: application/json" \
  -d '{"prompts": ["Hello"], "outages": [{"provider": "gpt-4", "error_type": "timeout"}]}'

# Export to LiteLLM config
curl -X POST http://localhost:8000/chains/{id}/export \
  -H "Content-Type: application/json" \
  -d '{"format": "litellm"}'

Docker

# Build and run
docker compose up -d

# Or build manually
docker build -t fallbackrabbit .
docker run -p 8000:8000 -v ./data:/app/data fallbackrabbit

The API will be available at http://localhost:8000 and the dashboard at http://localhost:8000/dashboard.

API Endpoints

Method Path Description
GET /health Health check
POST /chains Create a new chain
GET /chains List all chains
GET /chains/{id} Get chain details
PATCH /chains/{id} Update a chain
DELETE /chains/{id} Delete a chain
GET /chains/{id}/routing Get routing table
GET /chains/{id}/summary Get chain summary
GET /chains/{id}/validate Validate chain
POST /chains/{id}/optimize Optimize provider order
POST /chains/{id}/apply-rules Apply fallback rules
POST /chains/{id}/test Run test simulation
GET /chains/{id}/test/single Test single prompt
POST /chains/{id}/export Export chain config
POST /chains/{id}/export/template Template-based export
GET /chains/import Import chain from file
GET /ws WebSocket (all events)
GET /ws/chain/{id} WebSocket (per-chain)
GET /dashboard Web dashboard

CLI Reference

Command Description
init Create a starter chain YAML
validate Validate a chain config
test Run a test simulation
optimize Optimize chain order by latency
export Export chain (litellm/langchain/haystack/template)
serve Start the REST API server

Configuration

Environment Variable Default Description
FALLBACKRABBIT_API_KEYS unset Comma-separated API keys for auth
FALLBACKRABBIT_RATE_LIMIT_RPM unset Requests per minute limit
FALLBACKRABBIT_RATE_LIMIT_BURST unset Burst limit for rate limiter
FALLBACKRABBIT_STORAGE_URL memory Storage URL (sqlite:///path.db)
OPENAI_API_KEY unset OpenAI API key for real calls
ANTHROPIC_API_KEY unset Anthropic API key for real calls

Examples

Check the examples/ directory:

Documentation

Full documentation is available at fallbackrabbit.melabuilt.ai.

Architecture

Provider β†’ Chain β†’ FallbackRule β†’ Simulator β†’ ChainReport
                                    ↓
                            Real Provider Calls (optional)
                                    ↓
                         Config Export (5 formats + templates)

Development

# Clone
git clone https://github.com/MelaBuilt-AI/FallbackRabbit.git
cd FallbackRabbit

# Install dev dependencies
uv sync

# Run tests
uv run pytest tests/ -v

# Lint
uv run ruff check fallbackrabbit/ tests/

# Build
uv run python -m build

See CONTRIBUTING.md for detailed development guide.

Tech Stack

  • FastAPI β€” REST API framework
  • Pydantic β€” Data validation
  • Click β€” CLI framework
  • httpx β€” Async HTTP client for real provider calls
  • Rich β€” Terminal output
  • Jinja2 β€” Template-based export
  • PyYAML β€” YAML chain config support

License

MIT β€” see LICENSE.


Built by MelaBuilt AI 🐺

About

AI tool that generates, tests, and optimizes LLM fallback chains

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages