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.
GoogleTextModel is the concrete class that handles all text generation and streaming interactions for a specific Gemini model. It implements TextModelInterface from the PHP AI SDK core and is the object you receive when you call Google::model(). You rarely construct it directly — the Google facade or GoogleProvider does that for you — but understanding its contract is useful when you need to call generate() or stream() directly, inspect capabilities, or integrate with the model registry.
Namespace
Constructor
The Gemini model identifier string, for example
'gemini-2.5-pro' or 'gemini-2.0-flash'. This value is passed verbatim to the API request and used for catalog lookups.A configured
GoogleOptions instance carrying the API key, base URL, and any SDK-level settings. The authHeaders() method on this object is called for every request.An optional
ModelRegistry that can override built-in capability definitions. When provided, capabilities() and capability() consult the registry before falling back to the built-in ModelCatalog.Methods
provider(): string
Returns the provider name string used throughout the SDK.
'google' — the constant defined on GoogleOptions::PROVIDER_NAME.
modelId(): string
Returns the model identifier that was passed to the constructor.
$modelId string, for example 'gemini-2.5-pro'.
capabilities(): array
Resolves the full list of capabilities for this model. The resolution order is:
- If a
ModelRegistrywas injected and has a definition for this provider + model ID, capabilities are sourced from that definition. - Otherwise, the built-in
ModelCatalogis loaded fromresources/models.jsonand queried by model ID.
array<int, Capability> of Capability enum values such as Capability::TextGeneration, Capability::Vision, Capability::Reasoning, etc.
capability(Capability $capability): CapabilitySupport
Returns the support status for a single capability. The resolution order mirrors capabilities() but adds a special fallback: if the model is completely unknown to both the registry and catalog, and the queried capability is Capability::TextGeneration, the method returns CapabilitySupport::supported($capability, 'unknown-model-fallback') rather than a “not supported” result. This prevents unknown model IDs (for example, newly released models not yet in the catalog) from being incorrectly rejected.
The
Capability enum case to query, for example Capability::TextGeneration or Capability::Vision.CapabilitySupport value object describing whether the capability is supported and, if so, under what constraints.
generate(TextModelRequest $request): TextModelResponse
Performs a synchronous, non-streaming text generation request against the Gemini API.
A fully constructed
TextModelRequest carrying messages, system prompt, generation parameters, tools, and any provider-specific options under the 'google' key.TextModelResponse containing response parts, finish reason, token usage, and raw provider metadata.
Request / response flow:
GoogleRequestBuilder::build($modelId, 'google', $request, stream: false)converts the SDK request into a Gemini-compatible JSON body.- The body is POST-ed to
{baseUrl}/interactionswith the API key auth headers. - The raw JSON response array is passed to
GoogleResponseParser::parse(). - A typed
TextModelResponseis returned to the caller.
stream(TextModelRequest $request): Generator
Performs a streaming text generation request using Server-Sent Events (SSE). The method returns a Generator that yields StreamPart objects as each SSE event arrives, allowing you to process partial output incrementally.
A
TextModelRequest — identical to generate(). The stream: true flag is added internally; you do not need to set it yourself.Generator<int, StreamPart> that yields:
TextDeltaPart— incremental text chunksReasoningDeltaPart— incremental reasoning/thought chunks (when thinking is enabled)ToolCallStartPart/ToolCallDeltaPart— streaming tool call assemblyProviderMetadataPart— metadata emitted after all contentFinishPart— final part carrying the finish reason and accumulated token usage
GoogleRequestBuilder::build($modelId, 'google', $request, stream: true)builds the body withstream: true.- The body is POST-ed to
{baseUrl}/interactions?alt=sse. - The SSE event stream is handed to
GoogleStreamParser::parse(). - The generator yields
StreamPartobjects as events are processed.
Request / Response Flow Summary
The following describes the full lifecycle of agenerate() call:
- Build —
GoogleRequestBuilder::build()mapsTextModelRequestfields (messages, system prompt, max tokens, temperature, top-p, reasoning effort, output format) into a Gemini API JSON body. - Dispatch — The body is POST-ed to
{baseUrl}/interactionsusing the SDK HTTP runner with Google auth headers (x-api-keyorAuthorization: Bearer). - Parse — The JSON response is decoded and handed to
GoogleResponseParser::parse(), which extracts text parts, reasoning parts, and tool calls, resolves the finish reason, and tallies token usage. - Return — A
TextModelResponsecarrying typed parts, aFinishReasonenum value, aUsageobject, the raw response array, andproviderMetadata['google']is returned.
stream(), step 2 targets /interactions?alt=sse and step 3 is handled incrementally by GoogleStreamParser::parse(), which yields StreamPart objects rather than constructing a single response.