Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

AI Tools · Function

experimental_generateImage

experimental_generateImage creates images from a text prompt through a selected image model. Optional arguments can request multiple outputs and a specific size.

How it works

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.

Syntax

experimental_generateImage(options)

Parameters

NameTypeDescription
modelLanguageModelV1The image model used to generate the output.
promptstringThe text instruction for image generation.
nnumber | undefinedNumber of images to generate when supported by the provider.
sizestring | undefinedRequested image dimensions when supported by the provider.

Returns

A promise resolving to a result containing generated image data, including images and, when supported, provider metadata.

Key points

  • Use the function to create images programmatically from a text prompt and an image model.
  • It fits automated visual-content creation and other workflows that need images generated in code.
  • Documented examples include visual-content creation and data augmentation.
  • The generated collection is available by destructuring images from the awaited result.

Common mistakes

  • The image-generation capability is experimental, so its API may change.

Example: Generate multiple images

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.

When to use it

Generate visual content programmatically

Automated asset pipelines

Create synthetic images for data augmentation

Machine-learning preprocessing

Produce images from user prompts

Interactive creative tools

Interview questions

QHow does experimental_generateImage generate images?

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.

QWhat are the essential inputs?

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.

QHow do you request multiple images and a specific size?

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.

  • generateImage
  • imageModel
  • providerMetadata

Source: generate-image. Checked 2026-10-15.