Repository navigation
fix(OpenAI): handle rate limit and server errors on Guzzle stream requests - #816
Merged
Merged
Conversation
iBotPeaches
approved these changes
Oct 20, 2026
Collaborator
|
thanks! |
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.
What:
Description:
With Guzzle, a streamed request that gets a 429 from the API throws
ErrorExceptionand one that gets a 5xx throwsTransporterException, while the same requests without streaming throwRateLimitExceptionandServerException(#652, #757). For example,createStreamed()on a 503:The default stream handler calls Guzzle's
send(), which throwsClientExceptionorServerExceptionfor 4xx and 5xx responses becausehttp_errorsdefaults to true. The PSR-18sendRequest()used for the other requests turns it off, so only streams are affected. The catch inHttpTransporter::sendRequest()only looks for a JSON error inside aClientException, so the rate limit and server error checks inrequestStream()never run.The catch now checks for Guzzle's
BadResponseException, the parent of both exceptions, and runs the same checks in the same order as for a returned response. Doing it there rather than turning offhttp_errorsin the factory also covers custom stream handlers like the one in the README. Code that catchesErrorExceptionorTransporterExceptionfor a streamed 429 or 5xx will now getRateLimitExceptionorServerException, as it already does without streaming.