Function: retryAfterStrategy()
@providerprotocol/ai / @providerprotocol/ai / retryAfterStrategy
Function: retryAfterStrategy()
Section titled “Function: retryAfterStrategy()”retryAfterStrategy(
options):RetryStrategyFactory
Defined in: src/http/retry.ts:239
Creates a retry strategy that respects server-provided Retry-After headers.
When servers return a 429 (Too Many Requests) response, they often include a Retry-After header indicating when the client should retry. This strategy uses that information for precise retry timing.
Benefits over fixed backoff strategies:
- Follows server recommendations for optimal retry timing
- Avoids retrying too early and wasting requests
- Adapts to dynamic rate limit windows
If no Retry-After header is provided, falls back to a configurable delay. Only retries on RATE_LIMITED errors.
Parameters
Section titled “Parameters”options
Section titled “options”RetryAfterStrategyOptions = {}
Configuration options
Returns
Section titled “Returns”RetryStrategyFactory
A factory that creates fresh strategy instances per request
Example
Section titled “Example”// Use server-recommended retry timingconst retryAfter = retryAfterStrategy({ maxAttempts: 5, // Retry up to 5 times fallbackDelay: 10000 // 10s fallback if no header});
const provider = createOpenAI({ retryStrategy: retryAfter});