Skip to content

fix(bedrock): throw APIError for error events delivered in chunk frames#1021

Merged
felixfbecker merged 1 commit into
mainfrom
fix/bedrock-chunk-error-passthrough
Apr 30, 2026
Merged

fix(bedrock): throw APIError for error events delivered in chunk frames#1021
felixfbecker merged 1 commit into
mainfrom
fix/bedrock-chunk-error-passthrough

Conversation

@manar-ant

Copy link
Copy Markdown
Contributor

When a Bedrock response stream delivers an Anthropic-format error payload ({"type":"error","error":{...}}) inside a chunk event-stream frame, the iterator previously yielded it as a regular message event. Downstream, MessageStream.#accumulateMessage would then throw Unexpected event order, got error before "message_start" — discarding the underlying error type and message.

This change detects type: "error" in chunk payloads and throws APIError with the error type preserved (matching the base SDK SSE handling), so consumers see the actual error and retry logic can engage.

Adds tests/streaming.test.ts exercising the full de_ResponseStream → iterator path with real event-stream encoding.

Closes #387
Refs anthropics/anthropic-sdk-python#1472 (same issue, Python SDK)

When a Bedrock response stream wraps an Anthropic-format error payload
({"type":"error","error":{...}}) inside a chunk frame, the iterator now
throws an APIError instead of yielding the payload to MessageStream,
which would otherwise fail with "Unexpected event order, got error
before message_start" and discard the underlying error.

Closes #387
Refs anthropics/anthropic-sdk-python#1472
@manar-ant manar-ant requested a review from a team as a code owner April 29, 2026 22:53
@felixfbecker felixfbecker merged commit 3ae887b into main Apr 30, 2026
12 checks passed
@felixfbecker felixfbecker deleted the fix/bedrock-chunk-error-passthrough branch April 30, 2026 19:08
@stainless-app stainless-app Bot mentioned this pull request Apr 30, 2026
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.

AWS Bedrock SDK: Error information is lost when streaming

3 participants