Function: exponentialBackoff()
@providerprotocol/ai / @providerprotocol/ai / exponentialBackoff
Function: exponentialBackoff()
Section titled “Function: exponentialBackoff()”exponentialBackoff(
options):RetryStrategyFactory
Defined in: src/http/retry.ts:74
Creates an exponential backoff retry strategy.
The delay between retries doubles with each attempt, helping to:
- Avoid overwhelming servers during outages
- Reduce thundering herd effects when many clients retry simultaneously
- Give transient issues time to resolve
Delay formula: min(baseDelay * 2^(attempt-1), maxDelay) With jitter: delay * random(0.5, 1.0)
Only retries on transient errors: RATE_LIMITED, NETWORK_ERROR, TIMEOUT, PROVIDER_ERROR
Parameters
Section titled “Parameters”options
Section titled “options”ExponentialBackoffOptions = {}
Configuration options
Returns
Section titled “Returns”RetryStrategyFactory
A factory that creates fresh strategy instances per request
Example
Section titled “Example”// Default configuration (3 retries, 1s base, 30s max, jitter enabled)const retry = exponentialBackoff();
// Custom configurationconst customRetry = exponentialBackoff({ maxAttempts: 5, // Up to 5 retry attempts baseDelay: 500, // Start with 500ms delay maxDelay: 60000, // Cap at 60 seconds jitter: false // Disable random jitter});
// Use with providerconst provider = createOpenAI({ retryStrategy: customRetry});