Skip to content

Added Configurable Exception Handler via Backoff Library#102

Merged
xzrderek merged 3 commits intomainfrom
derekx/exception-handler
Aug 20, 2025
Merged

Added Configurable Exception Handler via Backoff Library#102
xzrderek merged 3 commits intomainfrom
derekx/exception-handler

Conversation

@xzrderek
Copy link
Copy Markdown
Contributor

simple one:

    exception_handler_config=ExceptionHandlerConfig(
        retryable_exceptions={
            litellm.RateLimitError,
            litellm.APIConnectionError,
        }
    ),

sophisticated one:

def api_retry_strategy(e):
    """Sophisticated retry logic for API calls"""
    if isinstance(e, litellm.AuthenticationError):
        return True  # Don't retry auth failures
    if isinstance(e, litellm.RateLimitError):
        return False  # Always retry rate limits
    if hasattr(e, 'response'):
        status = e.response.status_code
        return 400 <= status < 500 and status != 429  # Retry 429 but not other 4xx
    return False

@evaluation_test(
    completion_params=[{"model": "gpt-4o-mini"}],
    input_messages=[[Message(role="user", content="Test")]],
    exception_handler_config=ExceptionHandlerConfig(
        retryable_exceptions={
            litellm.RateLimitError,
            litellm.InternalServerError,
            litellm.APIConnectionError,
            requests.exceptions.RequestException,
        },
        backoff_config=BackoffConfig(
            strategy="expo",
            max_tries=7,
            base_delay=1.0,
            max_delay=120.0,
            factor=1.5,
            giveup_func=api_retry_strategy,
        )
    ),
)
def advanced_api_test(rows): ...

@xzrderek xzrderek requested review from benjibc and dphuang2 August 19, 2025 23:05
@xzrderek xzrderek merged commit 871675e into main Aug 20, 2025
7 checks passed
@xzrderek xzrderek deleted the derekx/exception-handler branch August 20, 2025 05:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants