Skip to main content
Generate images from text prompts or transform existing images with the responses API. The API returns generated images as base64-encoded data. For information about all request and response fields, see the responses API reference. For available image generation models, see Supported models.
The responses API follows the provider-agnostic Open Responses specification.

Generate an image

To generate an image, set input to a text description of the image and set generation parameters in provider_options.image. The following example generates an image from a text prompt and saves it as output-text-to-image.png.
Send a prompt, decode the returned image data, and save the image:
generate-image.py
The generated image should look similar to the following: Text-to-image output: a serene mountain landscape at sunset.

Transform an image

To transform an image, set input to a user message containing:
  • An input_image block with an image URL or base64-encoded data URI.
  • An input_text block describing the transformation.
The following example reads a local image named input.png, encodes it as a data URI, and saves the transformed image.
Encode the input image, send it with a prompt, and save the transformed image:
transform-image.py
The transformed image should look similar to the following: Image-to-image output: the mountain landscape transformed into a watercolor painting.