wordpress / wp-ai-client
An AI client and API for WordPress to communicate with any generative AI models of various capabilities using a uniform API.
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 19
Watchers: 3
Forks: 6
Open Issues: 4
pkg:composer/wordpress/wp-ai-client
Requires
- php: >=7.4
- ext-json: *
- nyholm/psr7: ^1.5
- wordpress/php-ai-client: ^0.2
Requires (Dev)
- automattic/vipwpcs: ^3.0
- dealerdirect/phpcodesniffer-composer-installer: ^1.0
- phpcompatibility/phpcompatibility-wp: ^2.1
- phpstan/phpstan: ^1.10 | ^2.1
- slevomat/coding-standard: ^8.0
- squizlabs/php_codesniffer: ^3.7
- szepeviktor/phpstan-wordpress: ^2.0
- wp-coding-standards/wpcs: ^3.0
- wp-phpunit/wp-phpunit: ^6.8
- yoast/phpunit-polyfills: ^4.0
- dev-trunk
- 0.1.0
- dev-prepare/0.1.0-release
- dev-docs/16-enhance-readme
- dev-add/prompt-builder-tests
- dev-fix-builder-chaining
- dev-add/phpunit-tests-setup
- dev-enhance/ignore-ai-config-files
- dev-enhance/client-package-setup
- dev-http-adapter
- dev-add/api-credentials-management
- dev-prompt-builder
- dev-fix/license
This package is auto-updated.
Last update: 2025-11-14 22:00:11 UTC
README
Part of the AI Building Blocks for WordPress initiative
An AI client and API for WordPress to communicate with any generative AI models of various capabilities using a uniform API.
Built on top of the PHP AI Client, adapted for the WordPress ecosystem.
Features
- WordPress-native Prompt Builder: Fluent API for building and configuring AI prompts, built directly on top of the PHP AI Client while following WordPress Coding Standards and best practices.
- Admin Settings Screen: Integrated settings screen in WP Admin to provision AI provider API credentials.
- Automatic Credential Wiring: Automatic wiring up of AI provider API credentials based on storage in a WordPress database option.
- PSR-compliant HTTP Client: HTTP client implementation using the WordPress HTTP API, fully compatible with PSR standards.
Installation and Configuration
- Add this package to your WordPress plugin.
composer require wordpress/wp-ai-client
- Initialize the package by hooking up the
WordPress\AI_Client\AI_Client::init()method to the WordPressinitaction:add_action( 'init', array( \WordPress\AI_Client\AI_Client::class, 'init' ) );
- With your plugin active, visit Settings > AI Credentials in WP Admin to configure AI provider credentials.
- Get started prompting various AI models by using the
WordPress\AI_Client\AI_Client::prompt( )method.
Configuration
Code examples
Text generation using a specific model
use WordPress\AI_Client\AI_Client; $text = AI_Client::prompt( 'Write a 2-verse poem about PHP.' ) ->using_model( Google::model( 'gemini-2.5-flash' ) ) ->generate_text();
Text generation using any compatible model from a specific provider
use WordPress\AI_Client\AI_Client; $text = AI_Client::prompt( 'Write a 2-verse poem about PHP.' ) ->using_provider( 'openai' ) ->generate_text();
Text generation using any compatible model
use WordPress\AI_Client\AI_Client; $text = AI_Client::prompt( 'Write a 2-verse poem about PHP.' ) ->generate_text();
Text generation with additional parameters
use WordPress\AI_Client\AI_Client; $text = AI_Client::prompt( 'Write a 2-verse poem about PHP.' ) ->using_system_instruction( 'You are a famous poet from the 17th century.' ) ->using_temperature( 0.8 ) ->generate_text();
Text generation with multiple candidates using any compatible model
use WordPress\AI_Client\AI_Client; $texts = AI_Client::prompt( 'Write a 2-verse poem about PHP.' ) ->generate_texts( 4 );
Image generation using any compatible model
use WordPress\AI_Client\AI_Client; $imageFile = AI_Client::prompt( 'Generate an illustration of the PHP elephant in the Caribbean sea.' ) ->generate_image();
See the Prompt_Builder class and its public methods for all the ways you can configure the prompt.
More documentation is coming soon.
Further reading
See the contributing documentation for more information on how to get involved.