Skip to content

fix(amazon-bedrock): return request.body from doGenerate and doStream#16969

Closed
xianjianlf2 wants to merge 1 commit into
vercel:mainfrom
xianjianlf2:fix/bedrock-request-body-13927
Closed

fix(amazon-bedrock): return request.body from doGenerate and doStream#16969
xianjianlf2 wants to merge 1 commit into
vercel:mainfrom
xianjianlf2:fix/bedrock-request-body-13927

Conversation

@xianjianlf2

Copy link
Copy Markdown

Background

AmazonBedrockChatLanguageModel.doGenerate() and doStream() never populated the request field of their result (there was an explicit // TODO request? in doStream). Consumers that rely on request.body for observability/tracing — e.g. Mastra, which uses it to populate span inputs — received undefined instead of the Converse API request payload, resulting in empty tracing attributes.

Other providers (@ai-sdk/anthropic, @ai-sdk/google, @ai-sdk/cohere, …) already return request: { body: args }, so this gap was specific to the Bedrock provider.

Summary

  • Return request: { body: args } from both doGenerate() and doStream() (where args is the Converse API command built by getArgs()), matching the behavior of the other providers.
  • Removed the stale // TODO request? marker.
  • Added regression tests for both methods asserting result.request?.body contains the request payload, and updated the affected doGenerate result snapshots (purely additive — only the new request field).

Manual Verification

Verified with the provider's mock-server test harness (no live AWS credentials required):

  • The new should return the request body tests assert result.request?.body for both doGenerate and doStream. Their inline snapshots show the real Converse command (messages, system, additionalModelResponseFieldPaths, …) — i.e. the payload that was previously undefined.
  • The updated doGenerate result snapshots confirm request.body matches the body actually sent to the mock server (server.calls[0].requestBodyJson).
  • Full package suite green: pnpm test in packages/amazon-bedrock132 passed. pnpm check (oxlint + oxfmt) clean, and @ai-sdk/amazon-bedrock builds with type declarations.

Checklist

  • All commits are signed (PRs with unsigned commits cannot be merged)
  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features) — not needed; request.body is already part of the LanguageModelV4 result contract, this only fixes the Bedrock provider to honor it
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • I have reviewed this pull request (self-review)

Related Issues

Fixes #13927

…vercel#13927)

`BedrockChatLanguageModel.doGenerate()` and `doStream()` never populated
the `request` field (there was an explicit `// TODO request?`), so
consumers relying on it for observability/tracing (e.g. Mastra) received
`undefined` instead of the Converse API request payload.

Return `request: { body: args }` from both methods, matching the behavior
of other providers (`@ai-sdk/anthropic`, `@ai-sdk/google`, etc.).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@aayush-kapoor

Copy link
Copy Markdown
Collaborator

Marking as closed in favor of #17248

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.

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

2 participants