Resilient backoff retries with RetryBackoffConfig and RunOutcome
Handle transient 429 rate limits with exponential backoff + jitter
Production APIs hit transient 429 rate limits and brief 503 blips. RetryBackoffConfig configures exponential backoff with random jitter so 50 concurrent workers don't slam the provider at the exact same millisecond.
Example
from praisonai import RetryBackoffConfig, RunOutcome
backoff = RetryBackoffConfig(
base_delay=0.5,
max_delay=15.0,
jitter_ratio=0.2,
max_retries=3,
)
print('Backoff config -> base:', backoff.base_delay, 's | max:', backoff.max_delay, 's | jitter:', backoff.jitter_ratio, '| retries:', backoff.max_retries)
print('RunOutcome exported:', RunOutcome.__name__)Example explained
- jitter_ratio=0.2 — Spreads retry timestamps slightly to prevent thundering-herd retry storms.
- max_delay=15.0 — Caps wait time so interactive requests don't hang forever.
Know what to retry vs fail fast
Retry transient network errors, HTTP 429, and HTTP 502/503/504. Never retry HTTP 401 (bad API key) or HTTP 400 (invalid schema) — fail fast and alert immediately.
Common pitfall: retrying without jitter across parallel workers
Fixed 2-second sleeps cause every worker to collide again at t=2s, t=4s, and t=6s. Always keep jitter_ratio > 0.
Reference: documentation