generateImage()
generateImage
is an experimental feature.Generates images based on a given prompt using an image model.
It is ideal for use cases where you need to generate images programmatically, such as creating visual content or generating images for data augmentation.
import { experimental_generateImage as generateImage } from 'ai';
const { images } = await generateImage({ model: openai.image('dall-e-3'), prompt: 'A futuristic cityscape at sunset', n: 3, size: '1024x1024',});
console.log(images);
Import
import { experimental_generateImage as generateImage } from "ai"
API Signature
Parameters
model:
ImageModelV1
The image model to use.
prompt:
string
The input prompt to generate the image from.
n?:
number
Number of images to generate.
size?:
string
Size of the images to generate. Format: `{width}x{height}`.
providerOptions?:
Record<string, Record<string, JSONValue>>
Additional provider-specific options.
maxRetries?:
number
Maximum number of retries. Default: 2.
abortSignal?:
AbortSignal
An optional abort signal to cancel the call.
headers?:
Record<string, string>
Additional HTTP headers for the request.
Returns
image:
GeneratedImage
The first image that was generated.
GeneratedImage
base64:
string
Image as a base64 encoded string.
uint8Array:
Uint8Array
Image as a Uint8Array.
images:
Array<GeneratedImage>
All images that were generated.
GeneratedImage
base64:
string
Image as a base64 encoded string.
uint8Array:
Uint8Array
Image as a Uint8Array.