aisdk / google-agent-platform
Official Google Cloud Agent Platform (Vertex AI) provider for the PHP AI SDK.
Requires
- php: ^8.3
- aisdk/core: ^0.7
- aisdk/openai-compatible: ^0.7
- google/auth: ^1.45
Requires (Dev)
- laravel/pint: ^1.18
- nyholm/psr7: ^1.8
- pestphp/pest: ^3.0 || ^4.0
- phpstan/phpstan: ^2.0
- rector/rector: ^2.0
README
Official Google Cloud Agent Platform provider for the framework-agnostic PHP AI SDK. It uses the OpenAI-compatible endpoint for text and transcription, and native publisher model endpoints for embeddings, image, and speech generation.
Installation
composer require aisdk/google-agent-platform
Basic Usage
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;
Embeddings
$embedding = Generate::embedding(['First document to index', 'Second document to index']) ->model(GoogleAgentPlatform::embedding('gemini-embedding-001')) ->dimensions(768) ->providerOptions('google-agent-platform', [ 'task_type' => 'RETRIEVAL_DOCUMENT', 'autoTruncate' => false, ]) ->run(); $vector = $embedding->output->vector;
The package sends one native publisher-model request per input, which supports the documented single-input limit of gemini-embedding-001. Provider options use Google's documented field names: task_type, title, autoTruncate, and outputDimensionality.
Publisher and routed model IDs pass through unchanged and do not need to be registered. This package does not ship a model inventory; the SDK performs internal adapter validation before Google Cloud validates support for the selected model, project, and location.
Image and speech generation
$image = Generate::image('A clean product photograph') ->model(GoogleAgentPlatform::image('google/gemini-3.1-flash-image')) ->aspectRatio('16:9') ->run(); $speech = Generate::speech('Welcome to the application.') ->model(GoogleAgentPlatform::speech('google/gemini-3.1-flash-tts-preview')) ->voice('Kore') ->run();
Native embedding, image, and speech generation require project; a custom OpenAI-compatible baseUrl alone is not enough to construct the publisher model endpoint.
Transcription
use AiSdk\Content; use AiSdk\Generate; use AiSdk\GoogleAgentPlatform; $result = Generate::transcription(Content::audio(__DIR__.'/meeting.mp3')) ->model(GoogleAgentPlatform::transcription('google/gemini-2.5-flash')) ->run(); echo $result->output->text;
Transcription uses the routed multimodal model endpoint, so it follows the same authentication and model-id rules as text generation.
Streaming
Video Generation
$result = Generate::video('A cinematic ocean scene') ->model(GoogleAgentPlatform::video('veo-3.1-generate-001')) ->aspectRatio('16:9') ->resolution('1920x1080') ->run(timeout: 600);
Veo operations use the native publisher-model endpoint and can return inline video bytes or a Cloud Storage URI.
foreach (Generate::text('Tell me a story.')->model(GoogleAgentPlatform::model('google/gemini-2.5-flash'))->stream()->chunks() as $chunk) { echo $chunk; }
Reasoning and multimodal input
Portable reasoning maps to Google's native thinking configuration. Effort levels become thinking_level, while token budgets become thinking_budget:
$result = Generate::text('Explain the tradeoff.') ->model(GoogleAgentPlatform::model('google/gemini-3.1-pro-preview')) ->reasoning(\AiSdk\Reasoning::effort('medium')) ->run();
Google-specific extra_body.google.thinking_config provider options take precedence when supplied explicitly. Text requests also accept documented image and audio inputs; audio formats are serialized using Google's MIME-style values such as audio/wav.
Configuration
| Variable | Description |
|---|---|
GOOGLE_CLOUD_PROJECT / GOOGLE_VERTEX_PROJECT |
Google Cloud project id (required unless baseUrl set) |
GOOGLE_CLOUD_LOCATION / GOOGLE_VERTEX_LOCATION |
Region (defaults to global) |
GOOGLE_VERTEX_ACCESS_TOKEN |
Static OAuth access token |
GOOGLE_VERTEX_CREDENTIALS_PATH |
Path to a service account JSON key |
GOOGLE_APPLICATION_CREDENTIALS |
Standard ADC service-account path |
GOOGLE_VERTEX_API_KEY |
API key (express mode) |
Authentication
Authentication is powered by the official google/auth
library and supports the full set of Google credential sources:
- Application Default Credentials (ADC) — used automatically when no
explicit credential is given:
GOOGLE_APPLICATION_CREDENTIALS,gclouduser credentials, GCE/GKE metadata server, and workload identity federation. - Service account — JSON key as an array or file path (OAuth token exchange handled for you).
- Static OAuth access token — bring your own (e.g.
gcloud auth print-access-token). - API key — express mode via the
x-goog-api-keyheader.
// Application Default Credentials (nothing to configure) GoogleAgentPlatform::create(['project' => 'my-project', 'location' => 'us-central1']); // Service account file GoogleAgentPlatform::create([ 'project' => 'my-project', 'location' => 'us-central1', 'credentialsPath' => '/path/to/service-account.json', ]); // Service account array GoogleAgentPlatform::create([ 'project' => 'my-project', 'credentials' => $decodedServiceAccountJson, ]); // Static access token GoogleAgentPlatform::create(['project' => 'my-project', 'accessToken' => 'ya29....']);
Testing
composer test