Skip to main content

Overview

The generateImage() function generates images from text prompts using image generation models. It supports generating multiple images, different sizes, and both base64 and URL outputs.

Function signature

Parameters

ImageModel
required
The image generation model instance to use.
string
required
The text description of the image to generate. Must not be empty.
number
Number of images to generate. Defaults to 1.
string
Image dimensions. Format and available sizes depend on the provider.Common sizes:
  • '1024x1024' (square)
  • '1792x1024' (landscape)
  • '1024x1792' (portrait)
ImageProviderOptions
Provider-specific options, namespaced by provider name (e.g. { openai: { quality: 'hd' } }).

Return value

Returns a Promise<ImageGenerateResult> with the following properties:
GeneratedImage[]
Array of generated images. Length matches the n parameter.

Examples

Basic image generation

Generate multiple images

Custom size

Get base64 image data

Check revised prompt

Save image to file

Generate with style instructions

Error handling

Generate portrait and landscape variants

Model Support

Different providers expose image generation models through imageModel():

Important notes

Check revisedPrompt when you want to inspect how the provider expanded or filtered your original prompt.
For best results, be specific and descriptive in your prompts. Include details about style, composition, lighting, colors, and mood.

Provider-specific options

OpenAI

Common use cases

  1. Content Creation: Generate illustrations for articles and blog posts
  2. Marketing: Create social media graphics and ad visuals
  3. Product Design: Visualize product concepts and variations
  4. Game Development: Generate concept art and textures
  5. Education: Create visual aids and diagrams
  6. Personal Projects: Generate artwork for presentations or creative projects

Best practices

  1. Be Specific: Detailed prompts produce better results
  2. Iterate: Generate multiple variations to find the best result
  3. Use Style Keywords: Include art style, medium, and technique terms
  4. Check Revised Prompts: Inspect provider prompt rewrites when outputs differ from your original request
  5. Handle Errors: Prompts may be rejected for safety reasons

Errors

Throws ValidationError if:
  • Prompt is empty
May also throw:
  • ProviderError if the provider returns an error during image generation
  • Model encounters an error during generation
  • Prompt violates content policy