1. Go to this page and download the library: Download wordpress/php-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/ */
wordpress / php-ai-client example snippets
use WordPress\AiClient\AiClient;
$text = AiClient::prompt('Write a 2-verse poem about PHP.')
->usingModel(Google::model('gemini-2.5-flash'))
->generateText();
use WordPress\AiClient\AiClient;
$text = AiClient::prompt('Write a 2-verse poem about PHP.')
->usingProvider('openai')
->generateText();
use WordPress\AiClient\AiClient;
$text = AiClient::prompt('Write a 2-verse poem about PHP.')
->generateText();
use WordPress\AiClient\AiClient;
$text = AiClient::prompt('Write a 2-verse poem about PHP.')
->usingSystemInstruction('You are a famous poet from the 17th century.')
->usingTemperature(0.8)
->generateText();
use WordPress\AiClient\AiClient;
$texts = AiClient::prompt('Write a 2-verse poem about PHP.')
->generateTexts(4);
use WordPress\AiClient\AiClient;
$text = AiClient::prompt('Write a 80-verse poem with long stanzas about PHP.')
->usingSystemInstruction('You are a famous poet from the 17th century.')
->usingTemperature(0.8)
->usingMaxTokens(8000);
->generateText();
use WordPress\AiClient\AiClient;
$imageFile = AiClient::prompt('Generate an illustration of the PHP elephant in the Caribbean sea.')
->generateImage();
use WordPress\AiClient\AiClient;
// Set your PSR-14 event dispatcher
AiClient::setEventDispatcher($yourEventDispatcher);
// Events will now be dispatched during generation
$text = AiClient::prompt('Hello, world!')
->generateText();
use WordPress\AiClient\Events\BeforeGenerateResultEvent;
use WordPress\AiClient\Events\AfterGenerateResultEvent;
// In your event listener/subscriber
class AiEventListener
{
public function onBeforeGenerate(BeforeGenerateResultEvent $event): void
{
$model = $event->getModel();
$messages = $event->getMessages();
$capability = $event->getCapability();
// Log, monitor, or perform other actions
}
public function onAfterGenerate(AfterGenerateResultEvent $event): void
{
$result = $event->getResult();
// Log the result, track usage, etc.
}
}
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.