1. Go to this page and download the library: Download aisdk/google-agent-platform 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/ */
aisdk / google-agent-platform example snippets
use AiSdk\Generate;
use AiSdk\GoogleAgentPlatform;
$result = Generate::text()
->model(GoogleAgentPlatform::model('google/gemini-2.5-flash'))
->prompt('Explain closures in PHP.')
->run();
echo $result->text;
$image = Generate::image('A clean product photograph')
->model(GoogleAgentPlatform::model('google/gemini-3.1-flash-image'))
->aspectRatio('16:9')
->run();
$speech = Generate::speech('Welcome to the application.')
->model(GoogleAgentPlatform::model('google/gemini-3.1-flash-tts-preview'))
->voice('Kore')
->run();
use AiSdk\Content;
use AiSdk\Generate;
use AiSdk\GoogleAgentPlatform;
$result = Generate::transcription(Content::audio(__DIR__.'/meeting.mp3'))
->model(GoogleAgentPlatform::model('google/gemini-2.5-flash'))
->run();
echo $result->output->text;
use AiSdk\GoogleAgentPlatform;
use AiSdk\Live;
use AiSdk\Live\AudioDelta;
use AiSdk\Live\TranscriptDelta;
use AiSdk\Transport;
$session = Live::voice()
->model(GoogleAgentPlatform::model('gemini-live-2.5-flash-native-audio'))
->instructions('You are a concise customer-support agent.')
->voice('Kore')
->language('en-US')
->connect(Transport::auto());
// Send 16 kHz mono PCM chunks while reading events concurrently.
$session->sendAudio($pcmBytes);
foreach ($session->events() as $event) {
if ($event instanceof AudioDelta) {
playAudio($event->bytes);
}
if ($event instanceof TranscriptDelta) {
echo $event->delta;
}
}
foreach (Generate::text('Tell me a story.')->model(GoogleAgentPlatform::model('google/gemini-2.5-flash'))->stream()->chunks() as $chunk) {
echo $chunk;
}