Skip to main content
Every provider failure is raised as a typed RouteHub exception carrying the status code, provider and model. Each one subclasses the matching OpenAI SDK exception, so existing except openai.RateLimitError handlers keep working. The original error is chained as __cause__.

Exceptions

All of them are importable from routehub or routehub.exceptions.
Timeout is not a routehub.APIConnectionError, and ServiceUnavailableError is not a routehub.InternalServerError. Catch openai.APIConnectionError or openai.InternalServerError to cover both.

Retries

RouteHub retries rate limits, 5xx errors, timeouts and connection failures twice by default, with exponential backoff that honours retry-after. Set num_retries= per call, or num_retries=0 to handle every failure yourself.

Fall back to another model

RouteHub has no fallbacks argument. Catch the error and call the next model:

Errors inside a stream

Errors raised mid-stream, such as an overloaded event from Claude, are mapped to the same exceptions, so the same handlers cover streaming and non-streaming calls.