Skip to main content

Basic Image Generation

The simplest way to generate an image with a text prompt:
This example is from the source repository: examples/tasks/image-generation.ts:4

Saving Images to File

Generate an image and save it to the filesystem:

Landscape Images (16:9)

Generate wide, landscape-oriented images:

Portrait Images (9:16)

Generate tall, portrait-oriented images:

Reproducible Generation with Seeds

Use seed values to generate the same image consistently:

Generating Multiple Variations

Create multiple variations of the same prompt using different seeds:

Parallel Image Generation

Generate multiple images concurrently:

Handling Warnings

Check for and handle warnings from unsupported settings:

Using Custom Provider Configuration

Create a custom provider instance with specific settings:

Complete Example with Image Presentation

Based on the source repository’s presentation utilities:
The image presentation pattern is adapted from examples/lib/present-image.ts:16 in the source repository.

Base64 Encoding

Access the image as a base64-encoded data URL:

TypeScript with Type Safety

Full type safety with TypeScript:

Next Steps

Models

Learn about model capabilities

Settings

Configure generation parameters

AI SDK Docs

View AI SDK generateImage() reference

Configuration

Configure the Decart provider