Skip to content

feat(amazon-bedrock): return request body from doGenerate and doStream#13928

Open
dontgitit wants to merge 1 commit intovercel:mainfrom
dontgitit:fix/bedrock-return-request-body
Open

feat(amazon-bedrock): return request body from doGenerate and doStream#13928
dontgitit wants to merge 1 commit intovercel:mainfrom
dontgitit:fix/bedrock-return-request-body

Conversation

@dontgitit
Copy link
Copy Markdown

Summary

BedrockChatLanguageModel.doGenerate() and doStream() do not return a request field, so consumers that rely on the request body (observability frameworks, onFinish callbacks, etc.) receive undefined. There was an existing // TODO request? comment at the doStream return 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 },
 };

args is the Bedrock Converse API command object (the same value passed as body to postJsonToApi), so it captures the full request payload including model config, messages, tools, and inference parameters.

Motivation

Observability frameworks like Mastra use the request field from provider doStream()/doGenerate() to populate tracing span inputs (e.g., model_step.input). With the Bedrock provider, this is always undefined, resulting in empty span attributes — making it impossible to see what was sent to the LLM.

The @ai-sdk/anthropic provider already returns request: { body: args } from both methods (ref).

Fixes #13927
Related: #5129

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>
@tigent tigent bot added ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label bug Something isn't working as documented provider/amazon-bedrock Issues related to the @ai-sdk/amazon-bedrock provider labels Mar 30, 2026
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 bug Something isn't working as documented 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.

@ai-sdk/amazon-bedrock: doStream() and doGenerate() do not return request body

1 participant