feat(amazon-bedrock): return request body from doGenerate and doStream#13928
Open
dontgitit wants to merge 1 commit intovercel:mainfrom
Open
feat(amazon-bedrock): return request body from doGenerate and doStream#13928dontgitit wants to merge 1 commit intovercel:mainfrom
dontgitit wants to merge 1 commit intovercel:mainfrom
Conversation
Both `doGenerate()` and `doStream()` in `BedrockChatLanguageModel` were
missing the `request` field in their return objects (`doStream` had a
`// TODO request?` comment in its place). This meant consumers relying
on the request body — such as observability/tracing frameworks — received
`undefined`, making it impossible to inspect what was sent to the model.
Add `request: { body: args }` to both methods, matching the pattern used
by `@ai-sdk/anthropic`'s `AnthropicMessagesLanguageModel`.
Fixes vercel#13927
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
BedrockChatLanguageModel.doGenerate()anddoStream()do not return arequestfield, so consumers that rely on the request body (observability frameworks,onFinishcallbacks, etc.) receiveundefined. There was an existing// TODO request?comment at thedoStreamreturn site.This PR adds
request: { body: args }to both methods, matching the pattern used by@ai-sdk/anthropic:// doGenerate return return { content, finishReason: { ... }, usage: convertBedrockUsage(response.usage), + request: { body: args }, response: { ... }, warnings, }; // doStream return return { stream: response.pipeThrough(...), - // TODO request? + request: { body: args }, response: { headers: responseHeaders }, };argsis the Bedrock Converse API command object (the same value passed asbodytopostJsonToApi), so it captures the full request payload including model config, messages, tools, and inference parameters.Motivation
Observability frameworks like Mastra use the
requestfield from providerdoStream()/doGenerate()to populate tracing span inputs (e.g.,model_step.input). With the Bedrock provider, this is alwaysundefined, resulting in empty span attributes — making it impossible to see what was sent to the LLM.The
@ai-sdk/anthropicprovider already returnsrequest: { body: args }from both methods (ref).Fixes #13927
Related: #5129