Skip to main content
In this tutorial, you’ll learn how to generate multiple variations of an existing image using the OpenAI DALL·E API. By the end, you’ll be able to:
  • Load and preview a source image
  • Call the DALL·E variations endpoint
  • Render the generated images

Prerequisites

  • Python 3.6+
  • Install the OpenAI Python library:
  • Set your API key as an environment variable:

1. Import Modules and Configure the API Key

Begin by importing the necessary modules and loading your API key:

2. Load and Display the Source Image

Use IPython’s display utilities to preview the original asset:
This shows a lion and its cub.

3. Generate Three Variations

Call the DALL·E variation endpoint, specifying the image file, output size, and number of results:
You can modify the size or the n parameter to control the resolution and the number of variations returned.

4. Render the Generated Variations

Display each variation using the URLs returned in the response:
Each variation offers a unique composition or style. Experiment with different source images or parameters to explore new creative directions.

Summary of Steps

Next Steps

Now that you’ve created image variations, consider exploring other OpenAI offerings:

References

Watch Video

Practice Lab