RetryWrapper class
Wraps HTTP transport execution with retry logic.
This implements exponential backoff with jitter for retrying failed requests.
In the OpenAI client integration, this wrapper is applied by the interceptor
chain only for regular http.Request instances. Multipart and streamed
requests are not retried to avoid issues with request body re-consumption.
Retry Conditions
Retries are attempted for:
- Rate limit responses (HTTP 429) - always retried regardless of method
- Server errors (HTTP 5xx) - idempotent methods only
- Timeout exceptions - idempotent methods only
- Connection errors - idempotent methods only
Retries are NOT attempted for:
- Client errors (HTTP 4xx except 429)
- Aborted requests
- Non-idempotent methods (POST, PATCH) for 5xx, timeout, or connection errors
Note: HTTP 429 (rate limit) is always retried regardless of method, as the request was not processed due to rate limiting.
Example
final wrapper = RetryWrapper(config: config);
final response = await wrapper.executeWithRetry(
request,
() async {
final streamedResponse = await httpClient.send(request);
return http.Response.fromStream(streamedResponse);
},
null,
'req_123',
);
Constructors
- RetryWrapper({required OpenAIConfig config})
- Creates a RetryWrapper with the given configuration.
Properties
- config → OpenAIConfig
-
The configuration containing retry policy settings.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
executeWithRetry(
BaseRequest request, Future< Response> execute(), Future<void> ? abortTrigger, String correlationId) → Future<Response> - Executes an HTTP request with retry logic.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited