Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/phpaisdk/google/llms.txt

Use this file to discover all available pages before exploring further.

aisdk/google is the official Google Gemini provider for the PHP AI SDK. The PHP AI SDK gives you a unified, framework-agnostic interface for working with large language models in PHP — and aisdk/google plugs Google’s Gemini family of models directly into that interface. Whether you need fast text generation, server-sent-event streaming, multimodal image input, or structured tool-calling responses, this package exposes all of Gemini’s capabilities through a clean, type-safe PHP API that is ready to use in any PHP 8.3+ project.

Key Features

Text Generation

Generate prose, summaries, code, and more with any Gemini text model using the familiar Generate::text() fluent builder.

Streaming

Stream responses token-by-token with ->stream() and iterate over chunks as they arrive via server-sent events, keeping your UI responsive even for long outputs.

Image Generation

Produce images from natural-language prompts using Google::image() and the Generate::image() builder, with built-in aspect-ratio control and one-call save support.

Tool Calling

Equip Gemini with your own PHP callables and let the model decide when and how to invoke them, with the SDK handling the round-trip automatically.

Structured Output

Bind a response schema and receive strongly-typed, structured JSON from Gemini — ideal for pipelines that feed model output into downstream PHP code.

Multimodal Input

Pass text alongside images or other media in a single request to Gemini’s vision-capable models without leaving the unified SDK interface.

Reasoning

Leverage Gemini’s extended thinking capabilities for complex, multi-step problems that benefit from deeper chain-of-thought reasoning.

Raw Option Passthrough

Forward any Gemini-specific generation parameters — temperature, top-k, safety settings, and more — directly through providerOptions('google', ['raw' => [...]]) without waiting for first-class SDK support.

How It Works

aisdk/google follows the provider pattern of the PHP AI SDK. The static Google class acts as the entry point and manages a singleton GoogleProvider instance that holds your configuration (API key, base URL, custom headers). Two factory methods return model interface objects that the SDK’s generation builders understand:
  • Google::model(string $modelId) returns a TextModelInterface backed by GoogleTextModel.
  • Google::image(string $modelId) returns an ImageModelInterface backed by GoogleImageModel.
You pass the model interface directly into the core builders:
use AiSdk\Generate;
use AiSdk\Google;

// Text generation
$result = Generate::text()
    ->model(Google::model('gemini-3.5-flash'))
    ->instructions('Be concise.')
    ->prompt('What is a PHP trait?')
    ->run();

// Image generation
$result = Generate::image()
    ->model(Google::image('gemini-3.1-flash-image'))
    ->prompt('A clean app icon for a PHP AI SDK')
    ->aspectRatio('1:1')
    ->run();
Google::create() lets you configure the provider explicitly; Google::default() lazily initialises it from environment variables the first time it is called — so zero-configuration usage works out of the box as long as your API key is set in the environment.

Requirements

RequirementVersion
PHP^8.3
aisdk/core^0.2
ComposerAny current release
The package carries no other required dependencies. HTTP transport is handled by aisdk/core and can be swapped out via the Sdk option if you need to use a custom PSR-18 client.

Next Steps

Installation

Install aisdk/google via Composer and set up your Gemini API key.

Quickstart

Make your first Gemini API call in under five minutes with a complete working example.

Text Generation

Learn all the options available on the Generate::text() builder with Gemini.

Authentication

Configure API keys, custom base URLs, and extra HTTP headers programmatically.

Build docs developers (and LLMs) love