feat: add backoff_factor and max_backoff for customizable retry backoff#3045
feat: add backoff_factor and max_backoff for customizable retry backoff#3045crawfordxx wants to merge 1 commit intoopenai:mainfrom
Conversation
…y backoff Allow users to customize the exponential backoff behavior when using max_retries. The new backoff_factor parameter controls the initial delay multiplier (default 0.5s) and max_backoff controls the maximum wait time between retries (default 8s). Existing behavior is fully preserved when parameters are not provided. Closes openai#1102
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d5d2ca507a
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| backoff_factor=backoff_factor if backoff_factor is not None else self._backoff_factor, | ||
| max_backoff=max_backoff if max_backoff is not None else self._max_backoff, |
There was a problem hiding this comment.
Avoid forwarding backoff kwargs into incompatible subclasses
OpenAI.copy() now always forwards backoff_factor/max_backoff into self.__class__(...), which breaks subclasses whose __init__ signatures do not accept those keywords. In this repo, AzureOpenAI.copy() and AsyncAzureOpenAI.copy() delegate to super().copy(), so calling copy()/with_options() on either Azure client now raises TypeError for unexpected keyword arguments, regressing an existing workflow for Azure users.
Useful? React with 👍 / 👎.
Summary
Adds two new optional parameters to the
OpenAIandAsyncOpenAIclient constructors:backoff_factor(float | None) — multiplier for the exponential backoff delay between retries (default:0.5seconds, matching current behavior)max_backoff(float | None) — maximum wait time between retries (default:8.0seconds, matching current behavior)These parameters are threaded through
BaseClient,SyncAPIClient,AsyncAPIClient, and thecopy()/with_options()methods so they work consistently everywhere.Usage
Backward compatibility
When
backoff_factorandmax_backoffare not provided (the default), the existing constantsINITIAL_RETRY_DELAY(0.5) andMAX_RETRY_DELAY(8.0) are used, so there is zero behavior change for existing users.Closes #1102