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.
GoogleOptions is an immutable value object that holds all provider-level configuration for the aisdk/google package — the resolved API key, the API base URL, any custom HTTP headers, and an optional PSR-18 HTTP client override. Once constructed, none of its properties can be changed; to use different settings you create a new instance. In practice, GoogleOptions is created for you inside Google::create() via its fromArray() static factory, but you can also construct it directly when you need precise control.
Namespace
Constants
The default Gemini REST API base URL used when no override is supplied through config or environment variables.
The canonical provider name string returned by
GoogleProvider::name().Constructor
fromArray() when you want the full environment-variable fallback chain.
The resolved Gemini API key that will be sent with every request via the
x-goog-api-key header. Must be a non-empty string; pass a value returned by Env::loadApiKey() or resolved through fromArray() to guarantee this.The API base URL. Trailing slashes are stripped by
fromArray(); if you construct GoogleOptions directly, supply a clean URL without a trailing slash.Extra HTTP headers that are merged into every outgoing request alongside the authentication header. Both keys and values must be strings.
An optional
AiSdk\Support\Sdk instance wrapping a custom PSR-18 HTTP client and PSR-17 request/response factories. When null, the package constructs a default HTTP client. Primarily useful in tests for injecting a mock HTTP client.Static Factory: fromArray()
GoogleOptions instance. Accepts a plain associative array of configuration values and resolves each setting through a prioritised fallback chain before calling the constructor.
Associative configuration array. All keys are optional.
self — a new GoogleOptions instance with all settings resolved.
API key resolution order
TheapiKey is resolved in the following priority order, stopping at the first non-empty value found:
$config['apiKey']— explicit value passed tofromArray()GEMINI_API_KEY— checked in$_ENV,$_SERVER, thengetenv()GOOGLE_GENERATIVE_AI_API_KEY— resolved viaEnv::loadApiKey()
authHeaders()
x-goog-api-key) is always present as the first entry; any additional headers supplied via the headers constructor property are merged in afterwards using array_merge(), so custom headers can override the auth header if needed.
Returns array<string, string> — merged authentication and custom headers.
Complete Example
The following example showsGoogleOptions::fromArray() being called with every supported config key, followed by inspecting the resolved authHeaders().