Skip to content

Fix bedrock ConverseStream undocumented /delta/stop_sequence#11410

Merged
gaspar09 merged 2 commits intomainfrom
gaspar/bedrock-undocumented-stopSequence
Dec 23, 2025
Merged

Fix bedrock ConverseStream undocumented /delta/stop_sequence#11410
gaspar09 merged 2 commits intomainfrom
gaspar/bedrock-undocumented-stopSequence

Conversation

@gaspar09
Copy link
Copy Markdown
Collaborator

@gaspar09 gaspar09 commented Dec 23, 2025

background

PR #11286 attempted to expose the stop sequence from Bedrock's Converse API, but had a bug: it was reading from the wrong response path. The AWS Bedrock API actually returns the stop sequence nested under a delta object: additionalModelResponseFields.delta.stop_sequence, not directly at additionalModelResponseFields.stop_sequence.

summary

Fixed stop sequence extraction to read from correct API response path

  • Changed extraction path from additionalModelResponseFields.stop_sequence to additionalModelResponseFields.delta.stop_sequence
  • Updated TypeScript schema to include delta wrapper in BedrockAdditionalModelResponseFieldsSchema
  • Updated tests to match actual AWS Bedrock API response structure
  • Verified fix works with both generateText and streamText

implementation details

The AWS Bedrock Converse API returns additional model response fields nested under a delta object when using additionalModelResponseFieldPaths: ['/delta/stop_sequence']. The previous implementation incorrectly assumed the field would be at the top level of additionalModelResponseFields.

Correct structure:

{
  messageStop: {
    stopReason: "stop_sequence",
    additionalModelResponseFields: {
      delta: {
        stop_sequence: "END"  // ← nested under delta
      }
    }
  }
}

verification

Tested with streamText using stopSequences: ['END']. Confirmed providerMetadata.bedrock.stopSequence now correctly returns "END" when the stop sequence is triggered (previously returned undefined).


Fixes: #11286

@vercel-ai-sdk vercel-ai-sdk bot added ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label provider/amazon-bedrock Issues related to the @ai-sdk/amazon-bedrock provider labels Dec 23, 2025
@gaspar09 gaspar09 changed the title Fix bedrock ConverseStream undocumented stop sequence Fix bedrock ConverseStream undocumented /delta/stop_sequence Dec 23, 2025
@gaspar09 gaspar09 merged commit afe9730 into main Dec 23, 2025
21 checks passed
@gaspar09 gaspar09 deleted the gaspar/bedrock-undocumented-stopSequence branch December 23, 2025 22:09
@dancer dancer added the backport Admins only: add this label to a pull request in order to backport it to the prior version label Dec 23, 2025
vercel-ai-sdk bot pushed a commit that referenced this pull request Dec 23, 2025
@vercel-ai-sdk vercel-ai-sdk bot removed the backport Admins only: add this label to a pull request in order to backport it to the prior version label Dec 23, 2025
@vercel-ai-sdk
Copy link
Copy Markdown
Contributor

vercel-ai-sdk bot commented Dec 23, 2025

⚠️ Backport to release-v5.0 created but has conflicts: #11414

gaspar09 added a commit that referenced this pull request Dec 24, 2025
…ce` (#11414)

This is an automated backport of #11410 to the release-v5.0 branch. FYI
@gaspar09
This backport has conflicts that need to be resolved manually.

### `git cherry-pick` output

```
Auto-merging packages/amazon-bedrock/src/bedrock-chat-language-model.test.ts
CONFLICT (content): Merge conflict in packages/amazon-bedrock/src/bedrock-chat-language-model.test.ts
Auto-merging packages/amazon-bedrock/src/bedrock-chat-language-model.ts
CONFLICT (content): Merge conflict in packages/amazon-bedrock/src/bedrock-chat-language-model.ts
error: could not apply afe9730... Fix bedrock ConverseStream undocumented `/delta/stop_sequence` (#11410)
hint: After resolving the conflicts, mark them with
hint: "git add/rm <pathspec>", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
```

---------

Co-authored-by: Gaspar Garcia Jr <gaspar@vercel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label provider/amazon-bedrock Issues related to the @ai-sdk/amazon-bedrock provider

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants