Configuration
Maximum number of retry attempts. The gateway supports up to 5 retries per target. Must be a positive integer.
HTTP status codes that trigger a retry. Defaults to
[429, 500, 502, 503, 504].
Errors with codes not in this list cause the request to fail immediately without retrying.Default retry behavior
The default retryable status codes are:| Status code | Meaning |
|---|---|
429 | Too Many Requests (rate limited) |
500 | Internal Server Error |
502 | Bad Gateway |
503 | Service Unavailable |
504 | Gateway Timeout |
Exponential backoff
The gateway uses an exponential backoff strategy between retry attempts to prevent network overload. Retry intervals increase with each failed attempt. The total retry window is capped at 60 seconds (MAX_RETRY_LIMIT_MS). If a provider’s retry-after header specifies a wait time longer than the remaining window, the retry is skipped and the error is returned immediately.
Provider-supplied retry delays
When a429 response includes a retry-after, retry-after-ms, or x-ms-retry-after-ms header, the gateway honors that delay before retrying:
Retries and timeouts
If arequest_timeout is set on the target, each individual attempt is subject to that timeout. A timed-out request returns a 408 status and — if 408 is in on_status_codes — is retried.
Retries with fallbacks
Retries and fallbacks are applied in sequence:- The gateway sends the request to the first target.
- If it fails with a retryable status code, it retries (up to
attemptstimes). - Only after all retry attempts are exhausted does the gateway move to the next fallback target.
Response headers
The gateway includes retry metadata in the response headers:| Header | Description |
|---|---|
x-portkey-retry-attempt-count | Number of retry attempts made for the final response |