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.

Google is the primary entry point for the aisdk/google package — a static facade in the AiSdk namespace that manages a singleton GoogleProvider instance and vends model objects. Rather than constructing provider and option classes manually, you interact with the Google class exclusively through its static methods for the vast majority of use cases. The class uses the RegistersModels trait from AiSdk\Support\Concerns, which provides the underlying model registry infrastructure.

Namespace / Import

use AiSdk\Google;

Methods

Google::create()

public static function create(array $config = []): GoogleProvider
Creates a new GoogleProvider from the given configuration array and stores it as the package-wide default singleton. Any subsequent call to Google::default(), Google::model(), or Google::image() will use this provider until Google::reset() is called or Google::create() is called again. If called with an empty array (or no argument), all config values fall back to environment variables or their built-in defaults — see GoogleOptions::fromArray() for the full resolution order.
config
array
default:"[]"
Associative configuration array. All keys are optional.
Returns GoogleProvider — the newly created provider, which is also stored as the default singleton.

Google::default()

public static function default(): GoogleProvider
Returns the current singleton GoogleProvider. If no provider has been created yet (i.e. Google::create() has not been called), this method calls Google::create() with an empty config array, relying entirely on environment variables for the API key and all other settings. Returns GoogleProvider

Google::model()

public static function model(string $modelId): TextModelInterface
Convenience shorthand for Google::default()->textModel($modelId). Returns a GoogleTextModel configured for the specified Gemini model ID. The returned object implements TextModelInterface from the core SDK contracts.
modelId
string
required
The Gemini text model identifier, for example 'gemini-2.5-flash' or 'gemini-2.5-pro'.
Returns TextModelInterface (concretely GoogleTextModel)
$model = Google::model('gemini-2.5-flash');

Google::image()

public static function image(string $modelId): ImageModelInterface
Convenience shorthand for Google::default()->imageModel($modelId). Returns a GoogleImageModel configured for the specified Gemini image model ID. The returned object implements ImageModelInterface from the core SDK contracts.
modelId
string
required
The Gemini image model identifier, for example 'gemini-2.0-flash-preview-image-generation'.
Returns ImageModelInterface (concretely GoogleImageModel)
$model = Google::image('gemini-2.0-flash-preview-image-generation');

Google::reset()

public static function reset(): void
Sets the singleton provider back to null. Any subsequent call to Google::default(), Google::model(), or Google::image() will create a fresh provider. Call this in your test teardown methods (tearDown() / afterEach()) to prevent provider state — including API keys, custom headers, and HTTP client overrides — from leaking between test cases.
protected function tearDown(): void
{
    Google::reset();
}

Full Usage Example

The example below shows the complete flow: configure the provider once with Google::create(), obtain a text model with Google::model(), then generate a response.
use AiSdk\Google;
use AiSdk\Facades\Generate;

// 1. Configure the provider (once, e.g. in a service provider or bootstrap file).
Google::create([
    'apiKey'  => $_ENV['GEMINI_API_KEY'],
    'headers' => ['X-Request-Source' => 'my-app'],
]);

// 2. Obtain a model and generate text.
$result = Generate::text()
    ->using(Google::model('gemini-2.5-flash'))
    ->withPrompt('Explain the difference between abstractions and interfaces in PHP.')
    ->run();

echo $result->text;
If you only have GEMINI_API_KEY set in your environment and need no extra configuration, you can skip Google::create() entirely:
use AiSdk\Google;
use AiSdk\Facades\Generate;

$result = Generate::text()
    ->using(Google::model('gemini-2.5-flash'))
    ->withPrompt('What is the capital of France?')
    ->run();

echo $result->text;

Build docs developers (and LLMs) love