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.

GoogleProvider is the concrete provider instance that sits between the static Google facade and the individual model classes. It extends BaseProvider from the core SDK contracts, holds an immutable GoogleOptions value object, and acts as a factory for GoogleTextModel and GoogleImageModel instances. In normal usage you never construct GoogleProvider directly — it is created and stored by Google::create().

Namespace

use AiSdk\Google\GoogleProvider;

Constructor

public function __construct(public readonly GoogleOptions $options)
Accepts a single GoogleOptions instance and stores it as a public read-only property. Because GoogleOptions is an immutable value object, a GoogleProvider instance is effectively immutable after construction.
options
GoogleOptions
required
A fully resolved GoogleOptions value object containing the API key, base URL, custom headers, and optional HTTP client override. Normally created via GoogleOptions::fromArray() inside Google::create().
You typically do not instantiate GoogleProvider directly. Use Google::create() instead, which builds the GoogleOptions from a plain config array and stores the resulting provider as the package-wide default.

Methods

name()

public function name(): string
Returns the canonical provider identifier string. This value comes from the PROVIDER_NAME constant defined on GoogleOptions. Returns string — always 'google'
$provider = Google::create(['apiKey' => 'key']);

echo $provider->name(); // 'google'

textModel()

public function textModel(string $modelId): TextModelInterface
Creates and returns a new GoogleTextModel instance for the given model ID. The model is initialised with the provider’s GoogleOptions (containing authentication headers and the base URL) and the shared model registry inherited from BaseProvider.
modelId
string
required
The Gemini text model identifier, for example 'gemini-2.5-flash' or 'gemini-2.5-pro'.
Returns TextModelInterface (concretely GoogleTextModel)
$provider = Google::create(['apiKey' => $_ENV['GEMINI_API_KEY']]);

$model = $provider->textModel('gemini-2.5-flash');
Internally this is equivalent to calling the static shorthand Google::model('gemini-2.5-flash'), which delegates to this method on the default provider instance.

imageModel()

public function imageModel(string $modelId): ImageModelInterface
Creates and returns a new GoogleImageModel instance for the given model ID, initialised with the same GoogleOptions and model registry as textModel().
modelId
string
required
The Gemini image model identifier, for example 'gemini-2.0-flash-preview-image-generation'.
Returns ImageModelInterface (concretely GoogleImageModel)
$provider = Google::create(['apiKey' => $_ENV['GEMINI_API_KEY']]);

$model = $provider->imageModel('gemini-2.0-flash-preview-image-generation');
Internally this is equivalent to calling the static shorthand Google::image('gemini-2.0-flash-preview-image-generation').

Direct Instantiation Example

While Google::create() is the recommended entry point, direct instantiation is occasionally useful — for example when you need multiple independent provider instances with different API keys in the same request lifecycle.
use AiSdk\Google\GoogleOptions;
use AiSdk\Google\GoogleProvider;

$options = GoogleOptions::fromArray([
    'apiKey'  => 'your-gemini-api-key',
    'headers' => ['X-Environment' => 'staging'],
]);

$provider = new GoogleProvider($options);

$textModel  = $provider->textModel('gemini-2.5-flash');
$imageModel = $provider->imageModel('gemini-2.0-flash-preview-image-generation');

Build docs developers (and LLMs) love