Skip to main content
POST
/
images
/
variations
Image Variations
curl --request POST \
  --url https://api.example.com/images/variations
{
  "created": 123,
  "data": [
    {
      "url": "<string>",
      "b64_json": "<string>"
    }
  ]
}
Creates a variation of a given image. This endpoint only supports dall-e-2.

Method Signature

client.images.create_variation(
    image=open("image.png", "rb"),
    n=2,
    size="1024x1024"
)

Parameters

image
file
required
The image to use as the basis for the variation(s). Must be a valid PNG file, less than 4MB, and square.
model
string
The model to use for image generation. Only dall-e-2 is supported at this time.
n
integer
The number of images to generate. Must be between 1 and 10.
response_format
string
The format in which the generated images are returned. Must be one of url or b64_json. URLs are only valid for 60 minutes after the image has been generated.
size
string
The size of the generated images. Must be one of:
  • 256x256
  • 512x512
  • 1024x1024
user
string
A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. Learn more.

Returns

Returns an ImagesResponse object containing the image variations.
created
integer
The Unix timestamp (in seconds) of when the image was created.
data
array
The list of generated images.

Examples

Create variations with URL response

from openai import OpenAI
client = OpenAI()

response = client.images.create_variation(
    image=open("image.png", "rb"),
    n=3,
    size="1024x1024"
)

for i, image in enumerate(response.data):
    print(f"Variation {i + 1}: {image.url}")

Create variations with base64 response

import base64
from openai import OpenAI

client = OpenAI()

response = client.images.create_variation(
    image=open("original.png", "rb"),
    n=2,
    size="512x512",
    response_format="b64_json"
)

for i, image in enumerate(response.data):
    image_data = base64.b64decode(image.b64_json)
    with open(f"variation_{i}.png", "wb") as f:
        f.write(image_data)
    print(f"Saved variation_{i}.png")

Multiple smaller variations

from openai import OpenAI
client = OpenAI()

# Generate 10 small variations for quick preview
response = client.images.create_variation(
    image=open("source.png", "rb"),
    n=10,
    size="256x256"
)

print(f"Generated {len(response.data)} variations")
for i, image in enumerate(response.data):
    print(f"Variation {i + 1}: {image.url}")

Build docs developers (and LLMs) love