Function: linearBackoff()
@providerprotocol/ai / @providerprotocol/ai / linearBackoff
Function: linearBackoff()
Section titled “Function: linearBackoff()”linearBackoff(
options):RetryStrategyFactory
Defined in: src/http/retry.ts:148
Creates a linear backoff retry strategy.
Unlike exponential backoff, linear backoff increases delays at a constant rate:
- Attempt 1: delay * 1 (e.g., 1000ms)
- Attempt 2: delay * 2 (e.g., 2000ms)
- Attempt 3: delay * 3 (e.g., 3000ms)
This strategy is simpler and more predictable than exponential backoff, suitable for scenarios where gradual delay increase is preferred over aggressive backoff.
Only retries on transient errors: RATE_LIMITED, NETWORK_ERROR, TIMEOUT, PROVIDER_ERROR
Parameters
Section titled “Parameters”options
Section titled “options”LinearBackoffOptions = {}
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 delay increment)const retry = linearBackoff();
// Custom configurationconst customRetry = linearBackoff({ maxAttempts: 4, // Up to 4 retry attempts delay: 2000 // 2s, 4s, 6s, 8s delays});
// Use with providerconst provider = createAnthropic({ retryStrategy: customRetry});