Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PapiAI Google Provider

CI Latest Version Total Downloads PHP Version License

Google Gemini provider for PapiAI - A simple but powerful PHP library for building AI agents.

Installation

composer require papi-ai/google

Usage

use PapiAI\Core\Agent;
use PapiAI\Google\GoogleProvider;

$provider = new GoogleProvider(
    apiKey: $_ENV['GOOGLE_API_KEY'],
    defaultModel: GoogleProvider::MODEL_3_6_FLASH,
);

$agent = new Agent(
    provider: $provider,
    model: GoogleProvider::MODEL_3_6_FLASH,
    instructions: 'You are a helpful assistant.',
);

$response = $agent->run('Hello!');
echo $response->text;

Available Models

Gemini (text and chat)

GoogleProvider::MODEL_3_6_FLASH      // 'gemini-3.6-flash' (default)
GoogleProvider::MODEL_3_5_FLASH      // 'gemini-3.5-flash'
GoogleProvider::MODEL_3_5_FLASH_LITE // 'gemini-3.5-flash-lite'
GoogleProvider::MODEL_3_1_PRO        // 'gemini-3.1-pro-preview'
GoogleProvider::MODEL_3_FLASH        // 'gemini-3-flash-preview'
GoogleProvider::MODEL_2_5_PRO        // 'gemini-2.5-pro'
GoogleProvider::MODEL_2_5_FLASH      // 'gemini-2.5-flash'

Image generation and editing

GoogleProvider::MODEL_3_1_FLASH_IMAGE      // 'gemini-3.1-flash-image' (default)
GoogleProvider::MODEL_3_1_FLASH_LITE_IMAGE // 'gemini-3.1-flash-lite-image'
GoogleProvider::MODEL_3_PRO_IMAGE          // 'gemini-3-pro-image'
GoogleProvider::MODEL_2_5_FLASH_IMAGE      // 'gemini-2.5-flash-image'

The Imagen constants are still here but every one of them is @deprecated: the Imagen line shuts down on 17 August 2026, and its :predict endpoint has no successor. Use the Gemini image models above.

Video generation

GoogleProvider::MODEL_VEO_3_1      // 'veo-3.1-generate-preview' (default)
GoogleProvider::MODEL_VEO_3_1_LITE // 'veo-3.1-lite-generate-preview'

Features

  • Tool/function calling, including forced tool choice
  • Vision/multimodal support
  • Structured output (JSON mode)
  • Streaming support
  • Reasoning effort, mapped to Gemini's thinking levels and budgets
  • Image generation and editing
  • Video generation and text embeddings

Image Generation

use PapiAI\Google\GoogleProvider;

$provider = new GoogleProvider($_ENV['GOOGLE_API_KEY']);

$result = $provider->generateImage(
    prompt: 'A professional product photo of headphones on a white background',
    options: [
        'model' => GoogleProvider::MODEL_3_1_FLASH_IMAGE,
        'aspectRatio' => '1:1',  // 1:1, 16:9, 9:16, 4:3, 3:4, and more on 3.1 Flash Image
        'imageSize' => '2K',     // 1K, 2K or 4K ('0.5K' on 3.1 Flash Image)
    ]
);

$image = $result['images'][0];

// These models return JPEG by default, so take the extension from the response
// rather than assuming PNG.
$extension = str_replace('image/', '', $image['mimeType']);
file_put_contents("output.{$extension}", base64_decode($image['data']));

// Or save straight to disk, choosing your own path
$provider->generateImageToFile(
    prompt: 'A modern minimalist workspace',
    outputPath: '/path/to/image.jpg'
);

Leave aspectRatio and imageSize out and the model picks its own, rather than being forced into a square.

These models return one image per request. Asking for numberOfImages greater than one throws a ProviderException instead of quietly handing back a single image; call generateImage() once per image you need.

Image Editing

$result = $provider->editImage(
    imageUrl: 'https://example.com/photo.jpg',
    prompt: 'Make the sky dramatic and overcast',
);

file_put_contents('edited.jpg', base64_decode($result['images'][0]['data']));
echo $result['text']; // any commentary the model returned alongside the image

License

MIT

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages