LLM APIs often have inexplicable failures. With Portkey, you can rescue a substantial number of your requests with our in-built automatic retries feature.
Retry-After
headers for rate-limited requestsretry
param to your config object.
on_status_codes
param in your retry config and manually inputting the error codes on which retry will be triggered.
on_status_codes
param is present, retries will be triggered only on the error codes specified in that Config and not on Portkey’s default error codes for retries (i.e. [429, 500, 502, 503, 504])retry-after-ms
, x-ms-retry-after-ms
and retry-after
response headers when encountering rate limits. This enables more intelligent retry timing based on the provider’s response headers rather than using the default exponential backoff strategy.
To enable this feature, add the use_retry_after_headers
parameter to your retry config. By default this behaviour is disabled, and use_retry_after_headers
is set to false
.
use_retry_after_headers
is set to true
and the provider includes Retry-After
or Retry-After-ms
headers in their response, Portkey will use these values to determine the wait time before the next retry attempt, overriding the exponential backoff strategy.If the provider doesn’t include these headers in the response, Portkey will fall back to the standard exponential backoff strategy.The cumulative retry wait time for a single request is capped at 60 seconds. For example, if the first retry has a wait time of 20 seconds, and the second retry response includes a Retry-After value of 50 seconds, the request will fail since the total wait time (20+50=70) exceeds the 60-second cap. Similarly, if any single Retry-After value exceeds 60 seconds, the request will fail immediately.Attempt | Time out between requests |
---|---|
Initial Call | Immediately |
Retry 1st attempt | 1 second |
Retry 2nd attempt | 2 seconds |
Retry 3rd attempt | 4 seconds |
Retry 4th attempt | 8 seconds |
Retry 5th attempt | 16 seconds |
retry
param to your config object.
on_status_codes
param in your retry config and manually inputting the error codes on which rety will be triggered.
on_status_codes
param is present, retries will be triggered only on the error codes specified in that Config and not on Portkey’s default error codes for retries (i.e. [429, 500, 502, 503, 504])Attempt | Time out between requests |
---|---|
Initial Call | Immediately |
Retry 1st attempt | 1 second |
Retry 2nd attempt | 2 seconds |
Retry 3rd attempt | 4 seconds |
Retry 4th attempt | 8 seconds |
Retry 5th attempt | 16 seconds |
x-portkey-retry-attempt-count
header which provides information about retry attempts:
-1
: This means that Portkey exhausted all the retry attempts and the request was unsuccessful0
: This means that there were no retries configured>0
: This means that Portkey attempted retries and this is the exact number at which the request was successful