TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/phpaisdk/openai/llms.txt
Use this file to discover all available pages before exploring further.
aisdk/openai package supports image generation through OpenAI’s /images/generations endpoint. Use OpenAI::image() to select a model, then chain the portable builder methods to describe your request. The SDK always requests responses in b64_json format and makes the raw bytes available on the result object, so you can save, stream, or process images without handling base64 yourself.
Basic Example
The following example generates a single 1024×1024 image and saves it to disk:Request Options
The image model to use. Pass an
OpenAI::image(string $modelId) handle — for example OpenAI::image('gpt-image-1'), OpenAI::image('dall-e-3'), or OpenAI::image('dall-e-2').A text description of the image you want to generate. Detailed, descriptive prompts generally yield better results.
An explicit pixel size string such as
1024x1024, 1536x1024, or 1024x1536. When set, the SDK sends it directly as the size field in the API request. Mutually exclusive with aspectRatio — if both are set, size takes precedence.A portable aspect ratio shorthand. When no explicit
Ratios not listed above throw an
size is provided the SDK maps the ratio to the closest supported pixel size automatically. Supported mappings:| Aspect Ratio | Mapped Size |
|---|---|
1:1 | 1024x1024 |
3:2 | 1536x1024 |
16:9 | 1536x1024 |
2:3 | 1024x1536 |
9:16 | 1024x1536 |
InvalidArgumentException.The number of images to generate. Maps to the
n parameter in the OpenAI API. Defaults to 1 when omitted.Limitations
Saving and Using the Output
The$result->output object wraps the first returned image. Use bytes() to get the raw binary data, or save() to write directly to a file path.
->count(int $n), iterate $result->images to access each ImageData object individually:
Supported Image Models
All three OpenAI image models are registered in the provider with theimage_generation capability.
| Model ID | Status | Notes |
|---|---|---|
gpt-image-1 | Stable | Latest generation model, supports transparency |
dall-e-3 | Stable | High-quality single-image generation |
dall-e-2 | Stable | Faster, supports multiple images per request |
Provider-Specific Options
Some OpenAI image parameters — such asbackground, quality, and output_format — have no portable SDK equivalent. Pass them directly as top-level keys inside ->providerOptions('openai', [...]). The SDK merges your array over the built request body via array_replace, so provider options can add new fields or override SDK defaults.
Unlike text generation (which uses a
raw sub-key), image provider options are merged at the top level of the request body. See the Provider Options guide for a full comparison.