Documentation Index
Fetch the complete documentation index at: https://mintlify.com/phpaisdk/core/llms.txt
Use this file to discover all available pages before exploring further.
aisdk/core provides a clean, fluent API for image generation through Generate::image(). You attach a model that advertises Capability::ImageGeneration, describe what you want with a prompt, optionally tune dimensions and count, then call ->run() to get an ImageResult back.
Basic Example
Fluent Methods
Every method onPendingImageRequest returns $this, so calls can be chained in any order before ->run().
->model(ImageModelInterface $model)
Set the image model to use for this request. The model must implement ImageModelInterface and advertise Capability::ImageGeneration. You can also register a default model globally with Generate::model() and omit this call entirely.
->prompt(string $prompt)
The text description of the image you want to generate. This is the only required field — ->run() throws an InvalidArgumentException if the prompt is empty or whitespace-only. You can also pass the prompt directly to Generate::image() as a shorthand:
->count(int $count)
How many images to generate in a single request. Defaults to 1. Must be at least 1. All generated images are available on $result->images; $result->output is always the first image.
->size(string $size)
Request a specific pixel resolution in {width}x{height} format. The value must match the pattern \d+x\d+ — for example '1024x1024', '1792x1024', or '512x512'. The provider will reject unsupported resolutions.
->aspectRatio(string $aspectRatio)
Request a proportional aspect ratio in {width}:{height} format, such as '16:9' or '1:1'. The value must match the pattern \d+:\d+. Use this when you want a portable constraint that the provider translates to its closest native resolution.
->size() and ->aspectRatio() are distinct options that you can set independently or together — the provider decides how to interpret them. Use ->size() when you need an exact pixel dimension, and ->aspectRatio() when you want a portable ratio that works across providers without knowing their supported resolutions.->seed(int $seed)
Pass an integer seed to the provider for reproducible outputs. Using the same prompt, model, and seed should produce the same image across calls (provider support varies).
->providerOptions(string $provider, array $options)
Forward provider-specific options that have no first-class equivalent in the SDK. The options are keyed by provider name and deep-merged on repeated calls.
Working with ImageResult
->run() returns an ImageResult value object with the following properties:
| Property | Type | Description |
|---|---|---|
$output | ImageData | Convenience accessor — always the first image in the response. |
$images | ImageData[] | All generated images, indexed from zero. |
$usage | Usage | Token / credit usage reported by the provider. |
$rawResponse | array | The unmodified provider response payload. |
$providerMetadata | array | Extra metadata attached by the provider driver. |
Working with ImageData
Each item in $result->images (and $result->output) is an ImageData instance:
| Property | Type | Description |
|---|---|---|
$base64 | ?string | Base64-encoded image content, or null if the provider returned a URL instead. |
$mimeType | string | MIME type of the image, e.g. 'image/png'. Defaults to 'image/png'. |
$width | ?int | Width in pixels, if reported by the provider. |
$height | ?int | Height in pixels, if reported by the provider. |
$url | ?string | Hosted URL returned by the provider, if available. |
ImageData::save(string $path): string
Decodes the base64 content and writes the raw bytes to $path. Returns the path on success. Throws AiSdkException if the base64 content is missing or the file cannot be written.
ImageData::bytes(): ?string
Decodes and returns the raw binary bytes from $base64, or null if $base64 is not set. Useful when you need to store or stream the bytes yourself without touching the filesystem.
Generating Multiple Images
Use->count() to request several images at once and iterate $result->images:
Provider Options Passthrough
When a provider supports settings that have no first-class SDK equivalent, use->providerOptions():
Required Capability
The SDK validates that the model advertisesCapability::ImageGeneration before sending the request. If the capability is missing, a CapabilityNotSupportedException is thrown before any network call is made.