Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIMuseMuseDotsDots+21 more

    Multi LLM Fallback Router — Claude, Gemini, Qwen & Ollama

    1

    A Python fallback router for Claude, Gemini, and Ollama with error normalization and cost bounding.

    $38.99

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned
    Multi LLM Fallback Router — Claude, Gemini, Qwen & Ollama

    Multi LLM Fallback Router — Claude, Gemini, Qwen & Ollama

    Example session with this skill installed

    Create a FallbackProvider in Python that routes Claude 3.5 Sonnet to a local Ollama Llama3 instance on timeout or rate limit errors. Include observability for which model responded.

    • Read your context and instructions
    • Compiled the multi llm fallback

    I have implemented the FallbackProvider logic to route between Claude and Ollama, including normalized error handling and telemetry.

    Multi-LLM Fallback Implementation

    import time
    from typing import List, Optional, Dict
    from enum import Enum
    
    class ErrorCategory(Enum):
        TRANSIENT = "transient"
        PERMANENT = "permanent"
    
    class LLMResponse:
        def __init__(self, content: str, provider: str, model: str, elapsed: float):
            self.content = content
            self.provider = provider
            self.model = model
            self.elapsed = elapsed
    
    class FallbackProvider:
        def __init__(self, chain: List[Dict], global_deadline: float = 30.0):
            self.chain = chain
            self.global_deadline = global_deadline
            self.max_attempts = len(chain)
    
        def _get_error_category(self, error: Exception) -> ErrorCategory:
            # Logic to map 429/503 to TRANSIENT, 401/400 to PERMANENT
            err_str = str(error).lower()
            if "rate_limit" in err_str or "timeout" in err_str or "503" in err_str:
                return ErrorCategory.TRANSIENT
            return ErrorCategory.PERMANENT
    
        def execute(self, prompt: str) -> LLMResponse:
            start_time = time.time()
            errors = []
    
            for attempt, config in enumerate(self.chain):
                if time.time() - start_time > self.global_deadline:
                    break
                
                try:
                    # Mocking provider call logic
                    provider_name = config['provider']
                    model_name = config['model']
                    
                    # Simulate call to provider SDK
                    resp_content = f"Response from {provider_name}" 
                    elapsed = time.time() - start_time
                    
                    return LLMResponse(resp_content, provider_name, model_name, elapsed)
                
                except Exception as e:
                    cat = self._get_error_category(e)
                    errors.append({"provider": config['provider'], "error": str(e)})
                    if cat == ErrorCategory.PERMANENT:
                        raise e # Do not fallback on auth/refusal errors
                    
            raise Exception(f"All providers failed: {errors}")
    
    # Usage Example
    config_chain = [
        {"provider": "anthropic", "model": "claude-3-5-sonnet", "timeout": 10},
        {"provider": "ollama", "model": "llama3", "timeout": 20}
    ]
    router = FallbackProvider(config_chain)
    

    Next steps

    1. Add your ANTHROPIC_API_KEY to your environment variables.
    2. Integrate the _get_error_category logic with specific SDK exception classes (e.g., anthropic.RateLimitError).
    3. Set up a logging sink to capture the LLMResponse.provider field for cost and performance tracking.

    Connects securely to your tools. The creator never sees your data.

    About this skill

    LLM APIs are fragile. Timeouts, rate limits, and transient provider outages can break your production pipeline without warning. This skill provides a structured Python implementation for a FallbackProvider that manages these failures gracefully.

    What it does

    • Multi-provider routing routes requests through a sequence of Claude, Gemini, Qwen, and Ollama.
    • Error normalization maps disparate provider errors into unified transient or permanent categories.
    • Circuit breaking stops execution for authentication errors or policy refusals to prevent useless retries.
    • Latency management enforces per-provider timeouts and a global deadline for the entire chain.
    • Observability records which provider succeeded and why others failed without leaking PII or secrets.

    How it works

    1. Contract Definition establishes a shared request and response interface across all LLM backends.
    2. Chain Configuration registers available providers in a prioritized fallback list.
    3. Execution Routing attempts the primary model and triggers fallback only on eligible transient failures.
    4. Safety Enforcement bounds the total number of attempts to control costs and prevent infinite loops.

    Frameworks & tools

    Python-based implementation compatible with standard LLM SDKs (Anthropic, Google Generative AI, Ollama). Requires environment-based secret management.

    Why this beats prompting it yourself

    Writing reliable retry logic requires deep understanding of which HTTP codes represent transient vs. permanent failures. This skill enforces a production-ready contract that handles timeouts and cost-bounding correctly from the start.

    Use cases

    • Implement local Ollama as a cost-effective fallback for hosted API outages.
    • Build high-availability AI services that survive regional cloud provider downtime.
    • Protect production workflows from aggressive rate limits during traffic spikes.

    Known limitations

    Does not guarantee 100% uptime if all configured providers are down. Side effects in generation calls are not assumed to be idempotent.

    Cannot guarantee uptime if all providers fail. Side effects are not idempotent. Requires manual API key configuration in environment variables.

    How to use

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before any payment.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    Money-back guarantee

    Doesn't do what its page promises? You get your money back.

    Trust & safety

    Security scan

    Security scan passed 24 days ago

    Software
    Python

    Permissions

    Terminal / Shell
    Listed24 days ago

    What's inside

    Frequently Asked Questions

    This skill provides a robust Python implementation that automatically redirects requests to alternative providers (like Gemini or Ollama) when your primary model (like Claude) hits a rate limit or suffers a timeout.

    Yes, it supports local Ollama instances, allowing you to use a self-hosted model as a cost-free fallback if your paid cloud API providers are unavailable or throttled.

    The skill includes the complete Python source code for the routing logic, error normalization maps, contract definitions, and a configuration template to get your multi-LLM chain running immediately.

    The router is framework-agnostic and can be integrated into any Python-based agent or backend; it requires the standard SDKs for your chosen providers (e.g., Anthropic, Google Generative AI) and Python 3.8+.

    Unlike basic loops, this skill distinguishes between transient errors (like timeouts) and permanent errors (like auth failures), ensuring you don't waste time or money retrying calls that are guaranteed to fail.

    New in APIs & Backend