Skip to content

Implement AWS Bedrock Provider via Converse API#181

Closed
junaidbhura wants to merge 5 commits intoWordPress:trunkfrom
junaidbhura:feature/aws-bedrock
Closed

Implement AWS Bedrock Provider via Converse API#181
junaidbhura wants to merge 5 commits intoWordPress:trunkfrom
junaidbhura:feature/aws-bedrock

Conversation

@junaidbhura
Copy link
Copy Markdown

Closes #180

Summary

This PR introduces the AwsBedrockProvider and its associated infrastructure. By leveraging the AWS Bedrock Converse API, this implementation provides a unified interface for multiple foundation models (Anthropic Claude, Meta Llama, Mistral, etc.) while adhering to enterprise-level security and compliance standards.

Key Implementation Details

  • Authentication: Implements AwsBedrockApiKeyRequestAuthentication. This utilizes Bedrock’s native API Key (Bearer Token) support, ensuring the SDK remains lightweight without requiring the full AWS PHP SDK or SigV4 signing.
  • Unified Converse API: Maps the library's internal structures to Bedrock's converse and converse-stream logic.
  • Multimodal Support: Full support for image and document inputs via MessagePart and File DTOs.
  • Tool Calling: Reliable mapping of FunctionDeclaration to Bedrock's toolConfig, including support for toolResult and toolUse blocks.
  • Dynamic Discovery: The AwsBedrockModelMetadataDirectory automatically infers model capabilities (Text, Image, Tools) from the AWS Control Plane.

Technical Architecture

  • Dual-Plane URLs: Correctly separates Control Plane (bedrock.region.amazonaws.com) for model listing and Runtime (bedrock-runtime.region.amazonaws.com) for inference.
  • Finish Reason Mapping: Bedrock-specific stopReason values are mapped to the library's FinishReasonEnum.

Testing & Verification

I have verified this implementation against the following scenarios using the anthropic.claude-3-5-sonnet-20241022-v2:0 model:

Test Case Status Notes
Simple Text Generation ✅ Pass System instructions and temperature respected.
Token Usage Tracking ✅ Pass Metadata correctly extracted from usage object.
Stop Sequences ✅ Pass Model successfully halts at custom stop tokens.
Multimodal (Vision) ✅ Pass Successfully described PNG/JPEG images via Base64.
Tool Calling ✅ Pass Correctly parsed toolUse arguments into FunctionCall DTOs.

Example Usage

// Set `AWS_BEDROCK_API_KEY` and `AWS_BEDROCK_REGION` environment variables 

use WordPress\AiClient\AiClient;
use WordPress\AiClient\ProviderImplementations\AwsBedrock\AwsBedrockProvider;

// The provider resolves the region via AWS_BEDROCK_REGION env variable
$result = AiClient::prompt('Summarize the benefits of using a unified AI SDK.')
    ->usingModel(AwsBedrockProvider::model('anthropic.claude-3-5-sonnet-20241022-v2:0'))
    ->usingTemperature(0.7)
    ->generateTextResult();

echo "Tokens Used: " . $result->getTokenUsage()->getTotalTokens();

@github-actions
Copy link
Copy Markdown

github-actions bot commented Jan 23, 2026

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: junaidbhura <junaidbhura@git.wordpress.org>
Co-authored-by: JasonTheAdams <jason_the_adams@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@junaidbhura
Copy link
Copy Markdown
Author

junaidbhura commented Jan 30, 2026

Hi @JasonTheAdams @felixarntz what do you think about this feature?

@JasonTheAdams
Copy link
Copy Markdown
Member

Hi @junaidbhura!

Thank you for sharing this! Our goal is to get the PHP and WP AI Clients into WordPress 7.0. As a part of this effort, we're actually going to be removing all providers from the PHP AI Client repository and moving them to their own repositories to be standalone packages/plugins. The reason for this is to decouple WordPress from any one provider, making use of packages and the wp.org plugins repository for folks to use the provider they want.

We encourage you to do the same! We've discussed having some sort of a community list, but there aren't clear plans for how we want to do that yet. For now, users can find your provider plugin on the .org repository once it's accepted.

@junaidbhura
Copy link
Copy Markdown
Author

junaidbhura commented Jan 31, 2026

Thanks @JasonTheAdams and @felixarntz. I wasn't sure how exactly this package is going to get merged into WordPress Core. Since this is currently a Composer package, I've gone ahead and released my feature as a Composer package as well, with this package as a dependency:

https://github.com/Aysnc-Labs/wordpress-php-ai-client-bedrock
https://packagist.org/packages/aysnc/wordpress-php-ai-client-bedrock

I'll go ahead and close this Pull Request. I'll keep the issue #180 open for you to close out as needed.

@junaidbhura junaidbhura deleted the feature/aws-bedrock branch January 31, 2026 08:23
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.

Support for AWS Bedrock (via Converse API)

2 participants