Errors
The exception hierarchy and error taxonomy used to classify provider failures.
llm-rotate raises a small, predictable set of exceptions and internally
classifies every provider failure into an error type that drives the rotation
logic.
Exception hierarchy
All exceptions are exported from llm_rotate.
ConfigurationError
Raised for invalid configuration or misuse — for example using lm before
configure(), calling configure() twice, or a model whose provider can't be
inferred and has no fallback chain. These are programmer errors; fix them at
startup.
LMRotateError
The base runtime error for a call that failed in a way that isn't simply "all
keys exhausted". Carries provider, error_type, and a masked key_id.
LMRotateError(message, *, provider=None, error_type=None, key_id=None)NoAvailableKeyError
Raised when every eligible key — across the native provider and any fallback chain — is unavailable. Includes:
model— the requested modelhealth_report— the current health snapshotearliest_retry_at— when a key is next expected to become available
This is the natural mapping to an HTTP 503.
from llm_rotate import lm, NoAvailableKeyError
try:
resp = await lm.chat("gpt-4o-mini", [{"role": "user", "content": "Hi"}])
except NoAvailableKeyError as e:
# back off until e.earliest_retry_at, surface a 503, etc.
...Error taxonomy
Internally, each provider failure is classified into an ErrorType. This is
what decides whether a call rotates to another key, retries with backoff, or
fails fast.
| Error type | Behavior |
|---|---|
rate_limit | Cooldown the key, try the next one. |
quota_exhausted | Try the next key. |
invalid_auth | Quarantine the key, try the next one. |
permission_denied | Quarantine the key, try the next one. |
timeout | Retry with backoff. |
transient_server_error | Retry with backoff. |
connection_error | Retry with backoff. |
model_unavailable | Try the next key / provider. |
broker_route_unavailable | Try the next broker route. |
stream_interrupted | Surface — the stream had already started. |
non_retryable_request_error | Surface immediately (e.g. malformed request). |
unknown | Treated conservatively. |
A malformed request (non_retryable_request_error) is surfaced immediately
rather than retried, so a bug in your prompt or parameters won't churn through
your entire key pool.