Skip to main content

Overview

Generate images from text prompts using OpenAI GPT image models (default gpt-image-2.5-flare) and other LiteLLM image models.

Python Usage

Basic Image Generation

Variations (dall-e-2)

OpenAI retired dall-e-2/dall-e-3 on 2026-05-12 and gpt-image-1 on 2026-10-23. dall-e-2 is kept only as the variation() default, because it is the only model with a variations endpoint. Use ImageAgent.variation() for that.

Save Image to File

save() writes base64 images locally and downloads URL images through a guarded fetch.
Image URLs are treated as untrusted. save() raises an error instead of downloading when a rule below is broken.

Async Usage

GPT Image Models

Images 2.5/2.6 params — frame_count, frame_duration_ms, complexity, output_format (e.g. "gif") — pass through **kwargs unchanged:

Editing with markup=

image_edit and aimage_edit accept mask= but reject markup= with a ValueError — LiteLLM does not upload markup as a file, so it would be silently ignored.
Need markup? Call the OpenAI SDK’s images.edit directly. Reference: PR #6262, fixes #6259.

Opt Out of Auto-Dropping

Parameters

Model-specific parameter handling

The capability wrapper drops parameters a model rejects before calling LiteLLM, so calls succeed without special-casing.
drop_params=True is injected per call — the global litellm.drop_params is left untouched. The same handling applies to aimage_generate, image_edit, and aimage_edit.

Result Object

The ImageResult object contains:
  • url: Image URL
  • b64_json: Base64 encoded image (always for GPT image models)
  • revised_prompt: Revised prompt, if the provider returns one
  • model: Model used
  • save(path): Method to save image to file