1. Go to this page and download the library: Download wordpress/wp-ai-client library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use WordPress\AiClient\Messages\Enums\ModalityEnum;
$result = wp_ai_client_prompt( 'Create a recipe for a chocolate cake and
wp_die( $result->get_error_message() );
}
// Iterate through the message parts.
foreach ( $result->toMessage()->getParts() as $part ) {
if ( $part->isText() ) {
echo wp_kses_post( $part->getText() );
} elseif ( $part->isFile() && $part->getFile()->isImage() ) {
echo '<img src="' . esc_url( $part->getFile()->getDataUri() ) . '" alt="">';
}
}
$summary = wp_ai_client_prompt( 'Summarize the history of the printing press.' )
->using_temperature( 0.1 )
->using_model_preference(
'claude-sonnet-4-5',
'gemini-3-pro-preview',
'gpt-5.1'
)
->generate_text();
use WordPress\AI_Client\AI_Client;
$text = AI_Client::prompt( 'Explain quantum computing in complicated terms.' )
->using_max_tokens( 8000 )
->generate_text();
use WordPress\AiClient\ProviderImplementations\Anthropic\AnthropicProvider as Anthropic;
$text = wp_ai_client_prompt( 'Explain quantum computing in simple terms.' )
->using_model( Anthropic::model( 'claude-sonnet-4-5' ) )
->generate_text();
$prompt = wp_ai_client_prompt( 'Explain quantum computing in simple terms.' )
->using_temperature( 0.2 );
if ( $prompt->is_supported_for_text_generation() ) {
// Safe to generate.
$text = $prompt->generate_text();
} else {
// Fallback: Hide feature or show setup instructions.
}