aysnc / wordpress-php-ai-client-bedrock
AWS Bedrock provider for the WordPress PHP AI Client SDK.
Package info
github.com/Aysnc-Labs/wordpress-php-ai-client-bedrock
pkg:composer/aysnc/wordpress-php-ai-client-bedrock
Requires
- php: ^8.3
Requires (Dev)
- aysnc/wordpress-php-cs-fixer: ^0.3.0
- aysnc/wordpress-phpcs: ^0.1.0
- guzzlehttp/psr7: ^1.0 || ^2.0
- php-http/curl-client: ^2.0
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^9.6
- squizlabs/php_codesniffer: ^3.13.5
- wordpress/php-ai-client: ^0.4
- yoast/phpunit-polyfills: ^2.0
This package is not auto-updated.
Last update: 2026-06-11 07:05:57 UTC
README
AWS Bedrock provider for the WordPress PHP AI Client framework, which ships in WordPress core as of WordPress 7.0.
This package was originally contributed to the core PHP AI Client repository. The WordPress team is decoupling all providers into standalone packages ahead of WordPress 7.0 core integration, so this provider is maintained here as an independent Composer library.
Requirements
- PHP 8.3+
- WordPress 7.0+ (provides the
WordPress\AiClientframework in core)
Note: Do not add
wordpress/php-ai-clientto your project'scomposer.jsonwhen running WordPress 7.0+. WordPress 7.0 ships the sameWordPress\AiClientnamespace in core — having both present causes a fatal class declaration conflict on boot.
Installation
composer require aysnc/wordpress-php-ai-client-bedrock
Configuration
Set the following environment variables:
| Variable | Required | Description |
|---|---|---|
AWS_BEDROCK_API_KEY |
Yes | Bearer token for Bedrock API authentication |
AWS_BEDROCK_REGION |
No | AWS region (defaults to AWS_DEFAULT_REGION, then us-east-1) |
AWS_DEFAULT_REGION |
No | Fallback AWS region |
Usage
Register the Provider
use WordPress\AiClient\AiClient; use Aysnc\WordPress\PhpAiClientBedrock\AwsBedrockProvider; AiClient::defaultRegistry()->registerProvider( AwsBedrockProvider::class );
Generate Text
$text = AiClient::prompt( 'Explain quantum computing in simple terms.' ) ->usingModel( AwsBedrockProvider::model( 'anthropic.claude-3-5-sonnet-20241022-v2:0' ) ) ->usingMaxTokens( 1000 ) ->generateText(); echo $text;
Full Result with Metadata
$result = AiClient::prompt( 'Explain quantum computing in simple terms.' ) ->usingModel( AwsBedrockProvider::model( 'anthropic.claude-3-5-sonnet-20241022-v2:0' ) ) ->usingMaxTokens( 1000 ) ->generateTextResult(); echo $result->toText(); echo $result->getTokenUsage()->getTotalTokens();
With Configuration
$result = AiClient::prompt( 'Hello' ) ->usingModel( AwsBedrockProvider::model( 'anthropic.claude-3-5-sonnet-20241022-v2:0' ) ) ->usingSystemInstruction( 'You are a helpful assistant.' ) ->usingMaxTokens( 1000 ) ->usingTemperature( 0.7 ) ->generateTextResult();
Custom Region
Set the AWS_BEDROCK_REGION environment variable, or fall back to AWS_DEFAULT_REGION:
export AWS_BEDROCK_REGION="eu-west-1"