Skip to content

fix(amazon-bedrock): preserve multibyte characters in streamed event payloads - #19992

Open
wasim-builds wants to merge 2 commits into
vercel:mainfrom
wasim-builds:fix/13299-bedrock-gateway-multibyte-stream
Open

fix(amazon-bedrock): preserve multibyte characters in streamed event payloads#19992
wasim-builds wants to merge 2 commits into
vercel:mainfrom
wasim-builds:fix/13299-bedrock-gateway-multibyte-stream

Conversation

@wasim-builds

Copy link
Copy Markdown
Contributor

Description

Fixes #13299.

When using streaming models on Amazon Bedrock (or through the AI Gateway which proxies Bedrock), multibyte characters (such as Korean, Japanese, Chinese, or emojis) were occasionally getting corrupted (``).

This happened because the raw byte stream from AWS events could be split across boundaries that truncate a multibyte character. The TextDecoder was initialized without the { stream: true } option, so instead of maintaining the partial byte state for the next chunk, it immediately emitted replacement characters.

This PR fixes the issue by maintaining a persistent TextDecoder and passing { stream: true } during decoding in both the general Bedrock event stream decoder and the Anthropic-specific Bedrock fetch implementation.

Testing

  • Verified locally that Amazon Bedrock tests pass successfully.
  • Confirmed the TextDecoder preserves stream byte state across chunks.

Copilot AI lite review requested due to automatic review settings August 29, 2026 18:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@wasim-builds
wasim-builds force-pushed the fix/13299-bedrock-gateway-multibyte-stream branch from 3215853 to 453a2e0 Compare August 30, 2026 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Korean/multibyte text corrupted via @ai-sdk/gateway with Bedrock BYOK keys

2 participants