1. Go to this page and download the library: Download kozmonos/vertex-ai 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/ */
kozmonos / vertex-ai example snippets
use Kozmonos\VertexAi\Vertex\VertexConfig;
$config = VertexConfig::fromArray(
use Kozmonos\VertexAi\Infrastructure\Auth\GoogleAuthTokenProvider;
use Kozmonos\VertexAi\Infrastructure\Http\VertexHttpTransport;
use Kozmonos\VertexAi\Support\AiModelRegistry;
use Kozmonos\VertexAi\Vertex\VertexTextProvider;
$registry = AiModelRegistry::fromDefaults();
$transport = new VertexHttpTransport($config, new GoogleAuthTokenProvider($config));
$text = new VertexTextProvider($transport, $registry);
$result = $text->generateText(
systemPrompt: 'You are helpful.',
userPrompt: 'Say hello.',
modelId: 'vertex-gemini-3.1-pro',
);
use Kozmonos\VertexAi\Support\HttpReferenceImageLoader;
use Kozmonos\VertexAi\Vertex\VertexVideoProvider;
$video = new VertexVideoProvider($transport, $registry, new HttpReferenceImageLoader($allowedHosts));
// Text → video
$result = $video->generateVideo(
prompt: 'A red balloon drifting over a city',
modelId: 'veo-3.1-fast-vertex',
durationSeconds: 4,
options: [
'aspect_ratio' => '16:9',
'storage_uri' => 'gs://my-bucket/veo-output/',
],
);
// Image → video: HTTP/MinIO/data URIs are loaded via ReferenceImageLoader
// (bytesBase64Encoded + mimeType). gs:// URIs are sent as gcsUri + mimeType.
$result = $video->generateVideo(
prompt: 'Slow camera push-in',
modelId: 'veo-3.1-fast-vertex',
durationSeconds: 4,
options: [
'source_image_url' => 'https://cdn.example.com/frame.png',
// or: 'source_image_url' => 'gs://bucket/refs/frame.png',
// or: 'source_image_base64' => $base64, 'source_image_mime_type' => 'image/png',
],
);
use Kozmonos\VertexAi\Batch\Support\VertexBatchJsonl;
use Kozmonos\VertexAi\Infrastructure\Batch\FakeBatchJobGateway;
use Kozmonos\VertexAi\Infrastructure\Gcs\InMemoryGcsObjectStore;
use Kozmonos\VertexAi\Vertex\VertexBatchService;
$batch = new VertexBatchService($config, new InMemoryGcsObjectStore('my-bucket'), new FakeBatchJobGateway());
$submission = $batch->submitBatchJob(
jsonlContent: VertexBatchJsonl::encode([['key' => 'line-1', 'request' => ['contents' => []]]]),
modelResource: 'publishers/google/models/gemini-2.5-flash',
displayName: 'my-batch',
);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.