AWS Bedrock provider for the WordPress PHP AI Client SDK.
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.
- PHP 8.3+
- wordpress/php-ai-client ^0.4
composer require aysnc/wordpress-php-ai-client-bedrockSet 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 |
use WordPress\AiClient\AiClient;
use Aysnc\WordPress\PhpAiClientBedrock\AwsBedrockProvider;
AiClient::defaultRegistry()->registerProvider( AwsBedrockProvider::class );$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;$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();$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();Set the AWS_BEDROCK_REGION environment variable, or fall back to AWS_DEFAULT_REGION:
export AWS_BEDROCK_REGION="eu-west-1"