(v5): Add support for bedrock provies tools #7572
Draft
+988
−233
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.
Background
Amazon Bedrock provides access to Anthropic's powerful Claude models, which offer advanced features that go beyond standard text generation. These include "Computer Use" tools (Bash, Text Editor, Computer), which allow models to interact with system resources in sophisticated ways.
To leverage these features, API requests to Bedrock must include specific
anthropic_beta
headers and use a distinct, provider-specific format for tool configuration. The existing AI SDK Bedrock provider lacked the logic to handle these requirements, preventing users from accessing the full capabilities of Claude models on Bedrock. This PR adds the necessary support to bridge that gap.Summary
This PR introduces comprehensive support for Anthropic's provider-defined tools within the Amazon Bedrock provider, enabling the use of advanced "Computer Use" features. The core logic has been significantly enhanced to correctly format requests for Bedrock and manage the required beta flags.
The key changes include:
bedrock-prepare-tools.ts
) has been overhauled to differentiate between standardfunction
tools and Anthropic'sprovider-defined
tools. It now correctly processes tools likecomputer
,bash
, andtextEditor
, transforming them into the format required by the Bedrock API.anthropic_beta
flag (e.g.,computer-use-2024-10-22
) into theadditionalModelRequestFields
of the request payload.anthropicBeta
Provider Option: A newproviderOptions.bedrock.anthropicBeta
array has been added, allowing users to manually opt-in to other Anthropic beta features that don't have an associated tool.bedrock-chat-language-model.ts
has been refactored to correctly merge SDK-managed fields (like beta flags and prepared tools) with user-providedadditionalModelRequestFields
, ensuring a valid final payload.bash
,textEditor
, andcomputer
tools, and explains how to enable other beta features.bedrock-prepare-tools.test.ts
) have been added to validate the new tool preparation logic. Core model tests have also been updated to assert that beta flags and mixed tool configurations are handled correctly.Verification
The changes have been verified through the newly added and updated unit tests, which confirm that the request payload sent to the Bedrock API is correctly formatted for various tool and beta flag combinations.
Tasks
pnpm changeset
in the project root)pnpm prettier-fix
in the project root)Future Work
execute
logic for the Computer Use tools is currently left to the user. Future work could involve creating higher-level abstractions or more detailed examples for common use cases, especially for thecomputer
tool which involves screen coordinates and actions.One thing to note is that Amazon documentation is conflicting on the
Interleaved-thinking
beta:Here it says

Interleaved-thinking-2025-05-14
:While here, it says

interleaved-thinking-2025-05-14
:Related Issues