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


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

  1. Add this package to your WordPress plugin.
    composer require wordpress/wp-ai-client
  2. Initialize the package by hooking up the WordPress\AI_Client\AI_Client::init() method to the WordPress init action:
    add_action( 'init', array( \WordPress\AI_Client\AI_Client::class, 'init' ) );
  3. With your plugin active, visit Settings > AI Credentials in WP Admin to configure AI provider credentials.
  4. 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.