Honor retry-after headers when OpenAI requests a retry - #1796
Open
1fanwang wants to merge 2 commits into
Open
Conversation
The delay parsed from retry-after-ms and retry-after was discarded on the x-should-retry: true path, which re-raised the raw error instead of an ApplicationError carrying next_retry_delay. Fold the header into the shared retryable computation so every path carries the delay. Signed-off-by: 1fanwang <1fannnw@gmail.com>
brianstrauch
requested changes
Aug 30, 2026
brianstrauch
left a comment
Member
There was a problem hiding this comment.
Thanks for the PR! Can we preserve APIStatusError instead of returning an untyped ApplicationError? I should be able to opt out of retry with RetryPolicy(non_retryable_error_types=["APIStatusError"]).
Signed-off-by: 1fanwang <1fannnw@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When OpenAI answers an agent activity with
x-should-retry: trueand a retry-after header, the SDK drops that delay and uses the activity's configured interval. A server asking for 5 seconds can therefore get another request after 1 second. This change honors the server delay. Users can also opt out throughRetryPolicy(non_retryable_error_types=["APIStatusError"]), including for concrete errors such asRateLimitError.The status handler now converts every
APIStatusErrorsubclass to anApplicationErrorwhose type remainsAPIStatusError. The same raise carries the retry decision and parsed delay, so the explicittrueandfalseheaders still take precedence over the HTTP status.How I tested it
Before: retry delay was lost
Before: the converted error had no type
After
The warnings are the existing workflow sandbox notices for
pydantic_coreimports.