Skip to content

fix: convert Bedrock streaming error SSE events to APIStatusError#1485

Open
xodn348 wants to merge 1 commit intoanthropics:mainfrom
xodn348:fix/issue-1477
Open

fix: convert Bedrock streaming error SSE events to APIStatusError#1485
xodn348 wants to merge 1 commit intoanthropics:mainfrom
xodn348:fix/issue-1477

Conversation

@xodn348
Copy link
Copy Markdown

@xodn348 xodn348 commented May 2, 2026

Fixes #1477

What

The Bedrock stream decoder (AWSEventStreamDecoder) raises a raw ValueError when it encounters a non-200 status code in an SSE event (e.g., internalServerException with status 400/500). This bypasses the SDK's error handling, so users see ValueError: Bad response code, expected 200: ... instead of a proper APIStatusError subclass like InternalServerError or BadRequestError.

This fix changes _parse_message_from_event to emit a ServerSentEvent(event="error") for non-200 status codes instead of raising ValueError. The existing error handling in Stream.__stream__ / AsyncStream.__stream__ already catches event="error" SSE events and converts them to the appropriate APIStatusError subclass via _make_status_error.

Verification

  • Build: pass
  • Tests: pass (14 passed, including 2 new tests for the fix)
  • Lint: pass (ruff)
  • Type check: pass (pyright, 0 errors)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bedrock streaming SSE events errors are not handled gracefully

1 participant