Ignora e passa al contenuto principale

Questo browser non è più supportato.

Esegui l'aggiornamento a Microsoft Edge per sfruttare i vantaggi di funzionalità più recenti, aggiornamenti della sicurezza e supporto tecnico.

Scarica Microsoft Edge Scopri di più su Internet Explorer e Microsoft Edge
microsoft-foundry.rest.security.o-auth2-auth

Images

Create an image variation

POST /openai/v1/images/variations Deprecato

Creates an image variation from the supplied request.

Corpo della richiesta

The multipart request body.

Content-Type: multipart/form-data
image OpenAI.CreateImageVariationRequest necessario Deprecato

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 Deprecato

The legacy model used by the retired image variations endpoint. This endpoint no longer accepts requests.

Uno qualsiasi dei seguenti:
string Deprecato
enum Deprecato
dall-e-2
n integer | null Deprecato

The number of images to generate. Must be between 1 and 10.

response_format enum Deprecato

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.

urlb64_json
size enum Deprecato

The size of the generated images. Must be one of 256x256, 512x512, or 1024x1024.

256x256512x5121024x1024
user string Deprecato

A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. Learn more.

Risposte

The request has succeeded.

Corpo

Content-Type: application/json
safety_identifier string | null Deprecato

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 necessario Deprecato

The Unix timestamp (in seconds) of when the image was created.

data OpenAI.Image[] Deprecato

The list of generated images.

background enum Deprecato

The background parameter used for the image generation. Either transparent or opaque.

transparentopaque
output_format enum Deprecato

The output format of the image generation. Either png, webp, or jpeg.

pngwebpjpeg
size string | enum Deprecato

The image dimensions as a WIDTHxHEIGHT string, for example 1536x864.

Uno qualsiasi dei seguenti:
string Deprecato
enum Deprecato
1024x10241024x15361536x1024
quality enum Deprecato

The quality of the image generated. One of low, medium, high, xhigh, or max.

lowmediumhighxhighmax
usage OpenAI.ImageGenUsage Deprecato

For gpt-image-1 only, the token usage information for the image generation.

input_tokens integer necessario Deprecato
total_tokens integer necessario Deprecato
output_tokens integer necessario Deprecato
output_tokens_details OpenAI.ImageGenOutputTokensDetails Deprecato

The output token details for the image generation.

image_tokens integer necessario Deprecato
text_tokens integer necessario Deprecato
input_tokens_details OpenAI.ImageGenInputUsageDetails necessario Deprecato

The input tokens detailed information for the image generation.

text_tokens integer necessario Deprecato
image_tokens integer necessario Deprecato

Client error

Corpo

Content-Type: application/json
error OpenAI.Error necessario Deprecato
code string | null necessario Deprecato
message string necessario Deprecato
param string | null Deprecato
type string Deprecato
misalignment OpenAI.MisalignmentErrorDetailsResource Deprecato
review_target string | null Deprecato
error_type string | enum Deprecato
Uno qualsiasi dei seguenti:
string Deprecato
enum Deprecato
potentially_unintended_data_transferpotentially_unintended_data_accesspotentially_unintended_destructive_activityother
detailed_explanation string Deprecato

The public explanation for this block.

steer OpenAI._MisalignmentSteer Deprecato
message string necessario Deprecato

The public continuation instruction.

details OpenAI.Error[] Deprecato
additionalInfo object Deprecato
debugInfo object Deprecato

Server error

Corpo

Content-Type: application/json
error OpenAI.Error necessario Deprecato
code string | null necessario Deprecato
message string necessario Deprecato
param string | null Deprecato
type string Deprecato
misalignment OpenAI.MisalignmentErrorDetailsResource Deprecato
review_target string | null Deprecato
error_type string | enum Deprecato
Uno qualsiasi dei seguenti:
string Deprecato
enum Deprecato
potentially_unintended_data_transferpotentially_unintended_data_accesspotentially_unintended_destructive_activityother
detailed_explanation string Deprecato

The public explanation for this block.

steer OpenAI._MisalignmentSteer Deprecato
message string necessario Deprecato

The public continuation instruction.

details OpenAI.Error[] Deprecato
additionalInfo object Deprecato
debugInfo object Deprecato

Richiedi

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)

Response

{
  "created": 1589478378,
  "data": [
    {
      "url": "https://..."
    },
    {
      "url": "https://..."
    }
  ]
}
it-it
Scelte sulla privacy
  • Dichiarazione di non responsabilità relativa all'intelligenza artificiale
  • Versioni precedenti
  • Blog
  • Collabora
  • Riservatezza
  • Privacy dei dati sanitari dei consumatori
  • Condizioni per l'utilizzo
  • Accessibilità
  • Marchi
  • © Microsoft 2026