Generate visual content programmatically
Automated asset pipelines
AI Tools · Function
experimental_generateImage creates images from a text prompt through a selected image model. Optional arguments can request multiple outputs and a specific size.
Call the function with an image model and a text prompt, then optionally control the number and dimensions of generated images. The result exposes generated image data through the returned image collection, with provider-specific metadata available when supported.
experimental_generateImage(options)| Name | Type | Description |
|---|---|---|
model | LanguageModelV1 | The image model used to generate the output. |
prompt | string | The text instruction for image generation. |
n | number | undefined | Number of images to generate when supported by the provider. |
size | string | undefined | Requested image dimensions when supported by the provider. |
A promise resolving to a result containing generated image data, including images and, when supported, provider metadata.
import { experimental_generateImage as generateImage } from 'ai';
import { openai } from '@ai-sdk/openai';
const { images } = await generateImage({
model: openai.image('dall-e-3'),
prompt: 'A futuristic cityscape at sunset',
n: 3,
size: '1024x1024',
});
console.log(images);Generates three 1024×1024 images from a text prompt using an OpenAI image model.
Automated asset pipelines
Machine-learning preprocessing
Interactive creative tools
It accepts an image model and prompt, with optional generation controls such as n and size. The returned result includes generated images that can be inspected or persisted.
Follow-up: How would you handle provider differences? Verify the chosen provider's supported parameters and avoid sending unsupported options.
The prompt is the textual instruction used to create the image. The model argument selects the image-generation provider and model implementation.
Follow-up: What should be validated before calling it? Confirm that the selected model implements image generation and that the prompt meets provider requirements.
The example requests three images at 1024×1024 resolution and reads them from the images result property. Other providers may return a singular image property when only one image is produced.
Follow-up: How could the output be delivered in a production application? Convert or store the returned image data and expose an application-appropriate URL or response.
generateImageimageModelproviderMetadata