wordpress / ai-provider-for-anthropic
AI Provider for Anthropic for the PHP AI Client SDK. Works as both a Composer package and WordPress plugin.
Package info
github.com/WordPress/ai-provider-for-anthropic
pkg:composer/wordpress/ai-provider-for-anthropic
Requires
- php: >=7.4
Requires (Dev)
- dealerdirect/phpcodesniffer-composer-installer: ^1.0
- phpcompatibility/php-compatibility: dev-develop
- phpstan/phpstan: ~2.1
- phpunit/phpunit: ^9.6
- slevomat/coding-standard: ^8.20
- squizlabs/php_codesniffer: ^3.7 || ^4.0
- wordpress/php-ai-client: ^1.3.1
Suggests
- wordpress/php-ai-client: Required. The core PHP AI Client SDK that this provider extends.
Provides
None
Conflicts
None
Replaces
None
README
An Anthropic (Claude) provider for the PHP AI Client SDK. Works as both a Composer package and a WordPress plugin.
Requirements
- PHP 7.4 or higher
- When using with WordPress, requires WordPress 7.0 or higher
- If using an older WordPress release, the wordpress/php-ai-client package must be installed
Installation
As a Composer Package
composer require wordpress/ai-provider-for-anthropic
As a WordPress Plugin
- Download the plugin files
- Upload to
/wp-content/plugins/ai-provider-for-anthropic/ - Activate the plugin through the WordPress admin
- Add your Anthropic API key under Settings > Connectors
Usage
With WordPress
The provider automatically registers itself with the PHP AI Client on the init hook. Add your API key under Settings > Connectors, or configure it in code:
// Set your Anthropic API key (or use the ANTHROPIC_API_KEY environment variable) putenv('ANTHROPIC_API_KEY=your-api-key'); // Use the provider $result = AiClient::prompt('Hello, world!') ->usingProvider('anthropic') ->generateTextResult();
As a Standalone Package
use WordPress\AiClient\AiClient; use WordPress\AnthropicAiProvider\Provider\AnthropicProvider; // Register the provider $registry = AiClient::defaultRegistry(); $registry->registerProvider(AnthropicProvider::class); // Set your API key putenv('ANTHROPIC_API_KEY=your-api-key'); // Generate text $result = AiClient::prompt('Explain quantum computing') ->usingProvider('anthropic') ->generateTextResult(); echo $result->toText();
Supported Models
Available models are dynamically discovered from the Anthropic API. This includes Claude models for text generation with multimodal input support. See the Anthropic documentation for the full list of available models.
Configuration
The provider uses the ANTHROPIC_API_KEY environment variable for authentication. You can set this in your environment or via PHP:
putenv('ANTHROPIC_API_KEY=your-api-key');
In WordPress 7.0 and above, you can instead save the key under Settings > Connectors, or define an ANTHROPIC_API_KEY constant in wp-config.php. A key provided via the environment variable or constant takes precedence over one saved in the Connectors screen.
Maintainers
Maintainers for this repo are David Stone (@superdav42), Felix Arntz (@felixarntz), Jason Adams (@JasonTheAdams), Jeffrey Paul (@jeffpaul), and Lauri Saarni (@saarnilauri); all can be reached using the @WordPress/ai-provider-for-anthropic-maintainers team.
License
GPL-2.0-or-later