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.

The aisdk/google package is the official Google Gemini provider for the PHP AI SDK. It bridges the PHP AI SDK’s unified interface with Google’s Generative Language API, giving you access to the full Gemini model family — including text generation, streaming, image generation, tool calling, structured output, and multimodal input — through a clean, type-safe PHP API.

Quickstart

Get a working Gemini text generation call running in under five minutes.

Installation

Install via Composer and configure your API key.

Text Generation

Generate text with any Gemini model, including system instructions.

Streaming

Stream tokens in real time using Server-Sent Events.

Image Generation

Generate images with Gemini image models, control aspect ratio and size.

Tool Calling

Use function calling to let Gemini invoke your PHP functions.

Structured Output

Get back validated JSON objects and arrays from Gemini.

API Reference

Full reference for every public class, method, and option.

Why aisdk/google?

The aisdk/google package plugs into the PHP AI SDK’s provider system so you get a portable, framework-agnostic interface to Gemini without writing HTTP boilerplate. Switch between Gemini model generations — 1.5, 2.0, 2.5, and 3.x — without changing application code.

Text & Streaming

Full text generation with SSE streaming and token usage reporting.

Images

Native image generation with aspect ratio and resolution control.

Multimodal

Send images, audio, and files alongside text prompts.

Tool Calling

Function calling with streaming deltas and multi-turn tool loops.

Structured Output

JSON output with schema enforcement via response_schema.

Reasoning

Control Gemini’s thinking depth with low, medium, or high effort.

Quick Example

quickstart.php
use AiSdk\Generate;
use AiSdk\Google;

$result = Generate::text()
    ->model(Google::model('gemini-3.5-flash'))
    ->instructions('Write short, clear answers.')
    ->prompt('Explain closures in PHP.')
    ->run();

echo $result->text;
1

Install the package

composer require aisdk/google
2

Set your API key

export GOOGLE_GENERATIVE_AI_API_KEY=your-api-key-here
3

Generate your first response

Call Google::model() with any Gemini model ID and chain it into Generate::text()->run().
4

Explore the guides

Learn streaming, image generation, tool calling, and more in the Guides section.

Build docs developers (and LLMs) love