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.
GoogleImageModel is the concrete class that handles image generation using Gemini’s native content-generation endpoint. It implements ImageModelInterface from the PHP AI SDK core and is the object returned by Google::image(). Unlike GoogleTextModel, image generation calls are routed to the model-specific /models/{modelId}:generateContent endpoint rather than the unified /interactions endpoint, and the response is parsed specifically for inline image data.
Namespace
Constructor
The Gemini image model identifier, for example
'gemini-2.0-flash-preview-image-generation'. This value is interpolated into the endpoint URL as /models/{modelId}:generateContent.A configured
GoogleOptions instance carrying the API key, base URL, and SDK-level settings.Optional
ModelRegistry for overriding built-in capability definitions. Consulted before the ModelCatalog in both capabilities() and capability().Methods
provider(): string
Returns the provider name string.
'google'.
modelId(): string
Returns the model identifier passed to the constructor.
capabilities(): array
Resolves the capability list for this model. Resolution order:
- If a
ModelRegistryis set and has a definition for this provider + model, use it. - Otherwise, load the built-in
ModelCatalogfromresources/models.json.
capability(Capability $capability): CapabilitySupport
Returns the support status for a single capability using the same registry → catalog resolution order as capabilities().
The
Capability enum case to query.generate(ImageRequest $request): ImageResponse
Performs an image generation request against the Gemini native content endpoint.
An
ImageRequest carrying the text prompt, aspect ratio, size, and any provider-specific options under the 'google' key. Note the constraints documented in the Limitations section below.ImageResponse containing the generated images as ImageData objects, token usage, the raw response array, and providerMetadata['google'].
Request / response flow:
GoogleImageRequestBuilder::build('google', $request)validates the request and converts it into a GeminigenerateContentbody.- The body is POST-ed to
{baseUrl}/models/{modelId}:generateContentwith auth headers. - The raw JSON response is passed to
GoogleImageResponseParser::parse($payload, 'google'). - The parser iterates
candidates[].content.parts[]and extracts anyinlineDataentries asImageDataobjects. - An
ImageResponseis returned.
Limitations
ImageResponse Structure
generate() returns an ImageResponse object. The primary contents are:
An ordered list of
ImageData objects, one per generated image. For Google, this list will contain exactly one item unless multiple candidates are returned by the API.The raw base64-encoded binary content of the image. This is the
data field from the Gemini inlineData response part — it does not include a data URI prefix.The MIME type of the image, for example
'image/png' or 'image/jpeg'. Sourced from the mimeType or mime_type field inside the Gemini inlineData part. Defaults to 'image/png' if the field is absent.A convenience shortcut for
images[0]. Provides the same base64 and mimeType properties plus a .save(string $path) helper method that writes the decoded image bytes directly to a file path.Token usage for the request, populated from
usageMetadata / usage_metadata in the response. Includes inputTokens and outputTokens.The full, unmodified JSON-decoded response array from the Gemini API.
An array keyed by provider name (
'google'). The nested array contains: model, promptFeedback / prompt_feedback, usageMetadata / usage_metadata — whatever fields are present in the raw response.