fix: map SSE error types to correct HTTP status codes in streaming#1263
Open
Jah-yee wants to merge 1 commit intoanthropics:mainfrom
Open
fix: map SSE error types to correct HTTP status codes in streaming#1263Jah-yee wants to merge 1 commit intoanthropics:mainfrom
Jah-yee wants to merge 1 commit intoanthropics:mainfrom
Conversation
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.
Summary
When the API returns HTTP 200 (streaming started fine) but then sends an SSE error event like
overloaded_error, the SDK was creating anAPIStatusErrorwithstatus_code=200instead of the correct error code (e.g., 529 for overloaded).This happened because
_streaming.pypassed the original HTTP response (status 200) to_make_status_error, which then selected the error subclass based on that 200 status code.Fix
Added a mapping from SSE error types to HTTP status codes, and create a mock response with the correct status code when handling SSE errors in both sync and async streaming.
Changes
_SSE_ERROR_TYPE_TO_STATUSmapping in_streaming.py_get_status_code_from_sse_error()helper functionStreamandAsyncStreamto use the mapped status codeTesting
This fix ensures that:
overloaded_error→OverloadedError(status_code=529)rate_limit_error→RateLimitError(status_code=429)api_error→InternalServerError(status_code=500)Fixes: #1258