PHPackages                             fabianternis/google-agent-platform-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. fabianternis/google-agent-platform-php

ActiveLibrary[API Development](/categories/api)

fabianternis/google-agent-platform-php
======================================

A lightweight, dependency-free PHP wrapper for the Google Agent Platform (formerly Vertex AI) — supports Gemini, Claude (Anthropic), Veo video, Imagen images, TTS, and file uploads.

0.6.0(1mo ago)04[1 PRs](https://github.com/fabianternis/google-agent-platform-php/pulls)Apache-2.0PHPPHP &gt;=8.1

Since May 2Pushed 3w agoCompare

[ Source](https://github.com/fabianternis/google-agent-platform-php)[ Packagist](https://packagist.org/packages/fabianternis/google-agent-platform-php)[ RSS](/packages/fabianternis-google-agent-platform-php/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (7)Dependencies (1)Versions (11)Used By (0)

Google Agent Platform PHP SDK
=============================

[](#google-agent-platform-php-sdk)

A lightweight, dependency-free PHP wrapper for the **Google Agent Platform** (formerly known as **Vertex AI**). Google rebranded Vertex AI to "Agent Platform" to reflect its expanded focus on agentic AI workflows. All existing Vertex AI endpoints remain fully compatible.

> **API Keys:** Manage your API keys at

---

Installation
------------

[](#installation)

```
composer require fabianternis/google-agent-platform-php
```

Requires PHP 8.1+, `ext-curl`, `ext-json`, `ext-fileinfo`.

---

Quick Start
-----------

[](#quick-start)

```
require 'vendor/autoload.php';

use GoogleAgentPlatform\Client;

// Express Mode — API key
$client = new Client(['api_key' => 'YOUR_API_KEY']);

// Google Cloud Mode — OAuth token (required for Claude, Veo, Imagen, File API)
$client = new Client([
    'project_id'   => 'your-gcp-project-id',
    'access_token' => 'YOUR_ACCESS_TOKEN',
    'location'     => 'us-central1',
]);
```

> **Tip:** Run `gcloud auth application-default print-access-token` locally to get a token.

---

Architecture
------------

[](#architecture)

As of v0.5.0 the SDK uses a resource-based structure. Each capability lives in its own class, accessible as a property on `Client`. The legacy flat methods are still fully supported.

```
src/
├── Client.php                  ← main entry point (facade)
├── Http/
│   └── HttpClient.php          ← all cURL logic
├── Resources/
│   ├── TextResource.php        ← Gemini text generation
│   ├── ImageResource.php       ← Imagen image generation
│   ├── AudioResource.php       ← Text-to-Speech
│   ├── VideoResource.php       ← Veo video generation
│   ├── ClaudeResource.php      ← Anthropic Claude
│   └── FileResource.php        ← local file embed + File API upload
└── Support/
    └── MimeTypes.php           ← MIME detection and extension mapping

```

### Resource API (recommended)

[](#resource-api-recommended)

```
$client->text->generate([...]);
$client->images->generate('A red fox in the snow');
$client->audio->synthesize('Hello world');
$client->video->generate('A timelapse of a blooming flower');
$client->claude->messages([...]);
$client->files->withFile('/tmp/photo.jpg', 'What is in this image?');
$client->files->uploadFile('/tmp/large-video.mp4');
```

### Legacy flat API (fully backward-compatible)

[](#legacy-flat-api-fully-backward-compatible)

```
$client->generateContent([...]);
$client->generateImage('A red fox...');
$client->synthesizeSpeech('Hello world');
$client->generateVideo('A timelapse...');
$client->claudeMessages([...]);
```

---

Sending Files to Models
-----------------------

[](#sending-files-to-models)

Two strategies depending on file size and reuse needs.

### Strategy 1 — inlineData (local file, &lt; ~20 MB)

[](#strategy-1--inlinedata-local-file--20-mb)

Reads the file from disk, base64-encodes it, and embeds it directly in the request. Best for images, short audio clips, and small PDFs.

```
// Single file
$contents = $client->files->withFile(
    filePath: '/tmp/photo.jpg',
    text:     'What is in this image?'
);
$response = $client->generateContent($contents);
echo $response['candidates'][0]['content']['parts'][0]['text'];
```

```
// Multiple files in one request
$contents = $client->files->withFiles(
    files: [
        '/tmp/chart.png',
        ['path' => '/tmp/report.pdf', 'mimeType' => 'application/pdf'],
    ],
    text: 'Summarize the report and explain the chart.'
);
$response = $client->generateContent($contents);
```

MIME type is auto-detected via `finfo` (magic bytes). You can override it:

```
$contents = $client->files->withFile('/tmp/data.bin', 'Analyze this.', 'application/octet-stream');
```

### Strategy 2 — File API upload (any size, reusable for 48 h)

[](#strategy-2--file-api-upload-any-size-reusable-for-48-h)

Uploads the file to Google's File API via a resumable upload. Returns a URI you can reference in any subsequent request. Best for large files (&gt; 20 MB), videos, and files used across multiple requests.

```
// Step 1: Upload once
$file = $client->files->uploadFile('/tmp/large-video.mp4');
// $file['uri']      → 'https://generativelanguage.googleapis.com/v1beta/files/abc123'
// $file['mimeType'] → 'video/mp4'
// $file['name']     → 'files/abc123'

// Step 2: Reference in any request
$contents = $client->files->fromUri(
    fileUri:  $file['uri'],
    mimeType: $file['mimeType'],
    text:     'Summarize this video.'
);
$response = $client->generateContent($contents);
```

```
// Or build the fileData part manually (GCS URI also works)
$response = $client->generateContent([[
    'role'  => 'user',
    'parts' => [
        ['fileData' => ['mimeType' => 'video/mp4', 'fileUri' => $file['uri']]],
        ['text'     => 'What happens in this video?'],
    ],
]]);
```

```
// List and inspect uploaded files
$list = $client->files->listFiles(pageSize: 20);
$meta = $client->files->getFile('files/abc123');
```

---

Text Generation — Gemini
------------------------

[](#text-generation--gemini)

```
$response = $client->text->generate([
    ['role' => 'user', 'parts' => [['text' => 'How does AI work?']]]
]);
echo $response['candidates'][0]['content']['parts'][0]['text'];

// Specific model
$response = $client->text->generate($contents, 'gemini-3.1-pro-preview');

// Streaming
$response = $client->text->stream($contents, 'gemini-3.1-pro-preview');
```

---

Image Generation — Imagen 3
---------------------------

[](#image-generation--imagen-3)

### Available Models

[](#available-models)

Model IDNotes`imagen-3.0-generate-001`Highest quality (default)`imagen-3.0-fast-generate-001`Faster, lower cost```
$client = new Client([
    'project_id'   => 'your-gcp-project-id',
    'access_token' => 'YOUR_ACCESS_TOKEN',
    'location'     => 'us-central1',
]);

// Generate and save to disk
$images = $client->images->generate(
    prompt:      'A photorealistic red fox sitting in a snowy forest at dusk.',
    sampleCount: 2,
    aspectRatio: '16:9',
    outputDir:   '/tmp/images'
);
foreach ($images as $img) {
    echo $img['savedPath'] . PHP_EOL;
}

// Return as base64 (no file saving)
$images = $client->images->generate('An oil painting of a lighthouse at sunset.');
$base64 = $images[0]['base64'];
//

// Advanced parameters
$images = $client->images->generate(
    prompt:           'A futuristic city skyline at night.',
    aspectRatio:      '9:16',
    outputDir:        '/tmp/images',
    additionalParams: [
        'negativePrompt'   => 'blurry, low quality, cartoon',
        'personGeneration' => 'dont_allow',
    ]
);
```

---

Text-to-Speech (TTS)
--------------------

[](#text-to-speech-tts)

### Available Models

[](#available-models-1)

Model IDDescription`gemini-3.1-flash-tts-preview`**Default** — low latency, style control via prompts`gemini-2.5-pro-tts`High-quality TTS`gemini-2.5-flash-tts`Fast TTS`elevenlabs/elevenlabs-tts-v2-5`Third-party ElevenLabs**Gemini 3.1 Flash TTS Preview** supports style control via natural language prompts (accents, tone, whisper, emotions), dynamic performance for poetry/newscasts/storytelling, and enhanced pace and pronunciation control.

```
// Synthesize and save to file
$audio = $client->audio->synthesize(
    text:        'Hello, welcome to the Agent Platform.',
    voiceConfig: ['prebuiltVoiceConfig' => ['voiceName' => 'en-US-Standard-A']],
    stylePrompt: 'Speak in a calm, friendly tone with a slight British accent.',
    outputFile:  '/tmp/speech.mp3'
);
echo $audio['savedPath'];  // /tmp/speech.mp3

// Return raw bytes (stream to browser)
$audio = $client->audio->synthesize('The quick brown fox.', 'gemini-2.5-flash-tts');
header('Content-Type: ' . $audio['mimeType']);
echo $audio['bytes'];

// ElevenLabs via Agent Platform
$audio = $client->audio->synthesize(
    text:    'Hello from ElevenLabs.',
    modelId: 'elevenlabs/elevenlabs-tts-v2-5',
    extra:   ['voice_id' => 'YOUR_VOICE_ID']
);
```

---

Anthropic Claude
----------------

[](#anthropic-claude)

### Available Models

[](#available-models-2)

Model IDFull Publisher Path`anthropic/claude-sonnet-4-6``publishers/anthropic/models/claude-sonnet-4-6``anthropic/claude-opus-4-6``publishers/anthropic/models/claude-opus-4-6`Requires Cloud Mode. Recommended location: `us-east5`.

Key differences from the direct Anthropic API:

- `model` is **not** a valid body parameter — it's part of the endpoint URL.
- `anthropic_version` is **required** and automatically set to `vertex-2023-10-16`.

```
$client = new Client([
    'project_id'   => 'your-gcp-project-id',
    'access_token' => 'YOUR_ACCESS_TOKEN',
    'location'     => 'us-east5',
]);

$response = $client->claude->messages(
    messages:  [['role' => 'user', 'content' => 'Give me a banana bread recipe.']],
    modelId:   'anthropic/claude-sonnet-4-6',
    maxTokens: 1024
);
echo $response['content'][0]['text'];

// Streaming
$response = $client->claude->messages(
    messages:  [['role' => 'user', 'content' => 'Write a short story.']],
    maxTokens: 1024,
    stream:    true
);
```

---

Video Generation — Veo 3.1
--------------------------

[](#video-generation--veo-31)

Veo uses a long-running operation pattern: submit a job, then poll until complete.

### Available Models

[](#available-models-3)

Model IDFull Publisher Path`google/veo-3.1-generate-001``publishers/google/models/veo-3.1-generate-001````
$client = new Client([
    'project_id'   => 'your-gcp-project-id',
    'access_token' => 'YOUR_ACCESS_TOKEN',
    'location'     => 'us-central1',
]);

// Step 1: Submit
$operation = $client->video->generate(
    prompt:           'A timelapse of a sunflower blooming in a garden.',
    sampleCount:      1,
    outputStorageUri: 'gs://your-bucket/output/'  // optional
);

// Step 2: Poll
do {
    sleep(5);
    $status = $client->video->getOperation($operation['name']);
} while (empty($status['done']));

print_r($status['response']);

// Advanced parameters
$operation = $client->video->generate(
    prompt:           'Aerial drone shot of a mountain range at sunrise.',
    sampleCount:      2,
    outputStorageUri: 'gs://your-bucket/output/',
    additionalParams: ['generateAudio' => true, 'durationSeconds' => 8]
);
```

---

Model Reference
---------------

[](#model-reference)

Model IDTypeResourceNotes`gemini-3.1-flash-lite-preview`Text`$client->text`**Default model**`gemini-3.1-pro-preview`Text`$client->text`High capability`imagen-3.0-generate-001`Image`$client->images`Highest quality`imagen-3.0-fast-generate-001`Image`$client->images`Faster, lower cost`gemini-3.1-flash-tts-preview`TTS`$client->audio`Low-latency, style control`gemini-2.5-pro-tts`TTS`$client->audio`High quality`gemini-2.5-flash-tts`TTS`$client->audio`Fast`anthropic/claude-sonnet-4-6`Text`$client->claude`Requires Cloud Mode`anthropic/claude-opus-4-6`Text`$client->claude`Requires Cloud Mode`google/veo-3.1-generate-001`Video`$client->video`Long-running operation`elevenlabs/elevenlabs-tts-v2-5`TTS`$client->audio`Third-party---

About Google Agent Platform (formerly Vertex AI)
------------------------------------------------

[](#about-google-agent-platform-formerly-vertex-ai)

Google Agent Platform was formerly known as **Vertex AI**. The rebrand reflects Google's strategic shift toward agentic AI — systems that can plan, reason, and act autonomously. The underlying infrastructure and all Vertex AI API endpoints remain fully compatible. Existing code using Vertex AI endpoints will continue to work without changes.

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance94

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

6

Last Release

38d ago

PHP version history (2 changes)0.3.0PHP &gt;=8.0

0.5.0PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/25ed173126e37245c1c13ddf3703e864583fe99aa26264efa39884fa562b177f?d=identicon)[fabianternis](/maintainers/fabianternis)

---

Top Contributors

[![fabianternis](https://avatars.githubusercontent.com/u/151365993?v=4)](https://github.com/fabianternis "fabianternis (31 commits)")

---

Tags

googleaifile-uploadGeminiclaudellmanthropictext-to-speechttsmultimodalveoagent-platformvertex-aiimagen

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/fabianternis-google-agent-platform-php/health.svg)

```
[![Health](https://phpackages.com/badges/fabianternis-google-agent-platform-php/health.svg)](https://phpackages.com/packages/fabianternis-google-agent-platform-php)
```

###  Alternatives

[mozex/anthropic-laravel

Laravel integration for the Anthropic API: facade, config publishing, install command, testing fakes, messages, streaming, tool use, thinking, and batches.

74287.1k1](/packages/mozex-anthropic-laravel)[cognesy/instructor-php

The complete AI toolkit for PHP: unified LLM API, structured outputs, agents, and coding agent control

317117.1k1](/packages/cognesy-instructor-php)[mozex/anthropic-php

PHP client for the Anthropic API: messages, streaming, tool use, thinking, web search, code execution, batches, and more.

49480.9k16](/packages/mozex-anthropic-php)[vizra/vizra-adk

Vizra Agent Development Kit - A comprehensive Laravel package for building intelligent AI agents.

29431.7k](/packages/vizra-vizra-adk)[gemini-api-php/client

API client for Google's Gemini API

225255.2k5](/packages/gemini-api-php-client)[claude-php/claude-php-sdk-laravel

Laravel integration for the Claude PHP SDK - Anthropic Claude API

5219.2k](/packages/claude-php-claude-php-sdk-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
