Skip to content

Function: exponentialBackoff()

@providerprotocol/ai


@providerprotocol/ai / @providerprotocol/ai / 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

ExponentialBackoffOptions = {}

Configuration options

RetryStrategyFactory

A factory that creates fresh strategy instances per request

// Default configuration (3 retries, 1s base, 30s max, jitter enabled)
const retry = exponentialBackoff();
// Custom configuration
const 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 provider
const provider = createOpenAI({
retryStrategy: customRetry
});