Create image variation
images.create_variation(ImageCreateVariationParams**kwargs) -> ImagesResponse
POST/images/variations
Creates a variation of a given image. This endpoint only supports dall-e-2.
Parameters
The image to use as the basis for the variation(s). Must be a valid PNG file, less than 4MB, and square.
n: Optional[int]
The number of images to generate. Must be between 1 and 10.
minimum1
maximum10
user: Optional[str]
A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. Learn more.
Returns
Create image variation
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ.get("OPENAI_API_KEY"), # This is the default and can be omitted
)
images_response = client.images.create_variation(
image=b"raw file contents",
)
print(images_response.created){
"created": 0,
"background": "transparent",
"data": [
{
"b64_json": "b64_json",
"revised_prompt": "revised_prompt",
"url": "url"
}
],
"output_format": "png",
"quality": "low",
"size": "1024x1024",
"usage": {
"input_tokens": 0,
"input_tokens_details": {
"image_tokens": 0,
"text_tokens": 0
},
"output_tokens": 0,
"total_tokens": 0,
"output_tokens_details": {
"image_tokens": 0,
"text_tokens": 0
}
}
}Returns Examples
{
"created": 0,
"background": "transparent",
"data": [
{
"b64_json": "b64_json",
"revised_prompt": "revised_prompt",
"url": "url"
}
],
"output_format": "png",
"quality": "low",
"size": "1024x1024",
"usage": {
"input_tokens": 0,
"input_tokens_details": {
"image_tokens": 0,
"text_tokens": 0
},
"output_tokens": 0,
"total_tokens": 0,
"output_tokens_details": {
"image_tokens": 0,
"text_tokens": 0
}
}
}