Images
Create an image variation
Creates an image variation from the supplied request.
요청 본문
The multipart request body.
image
OpenAI.CreateImageVariationRequest
필수
사용되지 않음
The image to use as the basis for the variation(s). Must be a valid PNG file, less than 4MB, and square.
model
string | enum | null
사용되지 않음
The legacy model used by the retired image variations endpoint. This endpoint no longer accepts requests.
enum
사용되지 않음
n
integer | null
사용되지 않음
The number of images to generate. Must be between 1 and 10.
response_format
enum
사용되지 않음
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
enum
사용되지 않음
The size of the generated images. Must be one of 256x256, 512x512, or 1024x1024.
user
string
사용되지 않음
A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. Learn more.
응답
The request has succeeded.
본문
safety_identifier
string | null
사용되지 않음
The effective safety identifier used for safety monitoring and abuse detection. This is the non-empty safety_identifier from the request, or the deprecated user value when safety_identifier is omitted, null, or empty.
created
integer
필수
사용되지 않음
The Unix timestamp (in seconds) of when the image was created.
data
OpenAI.Image[]
사용되지 않음
The list of generated images.
background
enum
사용되지 않음
The background parameter used for the image generation. Either transparent or opaque.
output_format
enum
사용되지 않음
The output format of the image generation. Either png, webp, or jpeg.
size
string | enum
사용되지 않음
The image dimensions as a WIDTHxHEIGHT string, for example 1536x864.
enum
사용되지 않음
quality
enum
사용되지 않음
The quality of the image generated. One of low, medium, high, xhigh, or max.
usage
OpenAI.ImageGenUsage
사용되지 않음
For gpt-image-1 only, the token usage information for the image generation.
output_tokens_details
OpenAI.ImageGenOutputTokensDetails
사용되지 않음
The output token details for the image generation.
input_tokens_details
OpenAI.ImageGenInputUsageDetails
필수
사용되지 않음
The input tokens detailed information for the image generation.
요청
curl https://api.openai.com/v1/images/variations \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-F image="@otter.png" \
-F n=2 \
-F size="1024x1024"
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"Example data",
)
print(images_response.created)
import fs from "fs";
import OpenAI from "openai";
const openai = new OpenAI();
async function main() {
const image = await openai.images.createVariation({
image: fs.createReadStream("otter.png"),
});
console.log(image.data);
}
main();
using System;
using OpenAI.Images;
ImageClient client = new(
model: "dall-e-2",
apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY")
);
GeneratedImage image = client.GenerateImageVariation(imageFilePath: "otter.png");
Console.WriteLine(image.ImageUri);
import fs from 'fs';
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: process.env['OPENAI_API_KEY'], // This is the default and can be omitted
});
const imagesResponse = await client.images.createVariation({
image: fs.createReadStream('otter.png'),
});
console.log(imagesResponse.created);
package main
import (
"bytes"
"context"
"fmt"
"io"
"github.com/openai/openai-go"
"github.com/openai/openai-go/option"
)
func main() {
client := openai.NewClient(
option.WithAPIKey("My API Key"),
)
imagesResponse, err := client.Images.NewVariation(context.TODO(), openai.ImageNewVariationParams{
Image: io.Reader(bytes.NewBuffer([]byte("Example data"))),
})
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v
", imagesResponse.Created)
}
package com.openai.example;
import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.images.ImageCreateVariationParams;
import com.openai.models.images.ImagesResponse;
import java.io.ByteArrayInputStream;
public final class Main {
private Main() {}
public static void main(String[] args) {
OpenAIClient client = OpenAIOkHttpClient.fromEnv();
ImageCreateVariationParams params = ImageCreateVariationParams.builder()
.image(new ByteArrayInputStream("Example data".getBytes()))
.build();
ImagesResponse imagesResponse = client.images().createVariation(params);
}
}
require "openai"
openai = OpenAI::Client.new(api_key: "My API Key")
images_response = openai.images.create_variation(image: StringIO.new("Example data"))
puts(images_response)
응답
{
"created": 1589478378,
"data": [
{
"url": "https://..."
},
{
"url": "https://..."
}
]
}