跳至主要内容

此浏览器不再受支持。

请升级到 Microsoft Edge 以使用最新的功能、安全更新和技术支持。

下载 Microsoft Edge 有关 Internet Explorer 和 Microsoft Edge 的详细信息
microsoft-foundry.rest.security.o-auth2-auth

Images

Create an image variation

POST /openai/v1/images/variations 已放弃

Creates an image variation from the supplied request.

请求正文

The multipart request body.

Content-Type: multipart/form-data
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.

以下任何项:
string 已放弃
enum 已放弃
dall-e-2
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.

urlb64_json
size enum 已放弃

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

256x256512x5121024x1024
user string 已放弃

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

响应

The request has succeeded.

正文

Content-Type: application/json
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.

transparentopaque
output_format enum 已放弃
pngwebpjpeggifsvg
size string | enum 已放弃

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

以下任何项:
string 已放弃
enum 已放弃
1024x10241024x15361536x1024
quality enum 已放弃

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

lowmediumhighxhighmax
usage OpenAI.ImageGenUsage 已放弃

Token usage information for image generation with GPT Image models.

input_tokens integer 必需 已放弃
total_tokens integer 必需 已放弃
output_tokens integer 必需 已放弃
output_tokens_details OpenAI.ImageGenOutputTokensDetails 已放弃

The output token details for the image generation.

image_tokens integer 必需 已放弃
text_tokens integer 必需 已放弃
input_tokens_details OpenAI.ImageGenInputUsageDetails 必需 已放弃

The input tokens detailed information for the image generation.

text_tokens integer 必需 已放弃
image_tokens integer 必需 已放弃
svg_usage OpenAI.SvgUsage 已放弃
model string 必需 已放弃
input_tokens integer 必需 已放弃
output_tokens integer 必需 已放弃
total_tokens integer 必需 已放弃
reasoning_tokens integer 必需 已放弃

Client error

正文

Content-Type: application/json
error OpenAI.Error 必需 已放弃
code string | null 必需 已放弃
message string 必需 已放弃
param string | null 已放弃
type string 已放弃
misalignment OpenAI.MisalignmentErrorDetailsResource 已放弃
review_target string | null 已放弃
error_type string | enum 已放弃
以下任何项:
string 已放弃
enum 已放弃
potentially_unintended_data_transferpotentially_unintended_data_accesspotentially_unintended_destructive_activityother
detailed_explanation string 已放弃

The public explanation for this block.

steer OpenAI._MisalignmentSteer 已放弃
message string 必需 已放弃

The public continuation instruction.

details OpenAI.Error[] 已放弃

Additional errors that contributed to this failure.

additionalInfo object 已放弃

Additional structured information about the failure.

debugInfo object 已放弃

Diagnostic information supplied by the service for troubleshooting.

Server error

正文

Content-Type: application/json
error OpenAI.Error 必需 已放弃
code string | null 必需 已放弃
message string 必需 已放弃
param string | null 已放弃
type string 已放弃
misalignment OpenAI.MisalignmentErrorDetailsResource 已放弃
review_target string | null 已放弃
error_type string | enum 已放弃
以下任何项:
string 已放弃
enum 已放弃
potentially_unintended_data_transferpotentially_unintended_data_accesspotentially_unintended_destructive_activityother
detailed_explanation string 已放弃

The public explanation for this block.

steer OpenAI._MisalignmentSteer 已放弃
message string 必需 已放弃

The public continuation instruction.

details OpenAI.Error[] 已放弃

Additional errors that contributed to this failure.

additionalInfo object 已放弃

Additional structured information about the failure.

debugInfo object 已放弃

Diagnostic information supplied by the service for troubleshooting.

请求

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://..."
    }
  ]
}
zh-cn
你的隐私选择
  • AI 免责声明
  • 早期版本
  • 博客
  • 参与
  • 隐私
  • 消费者健康隐私
  • 使用条款
  • 商标
  • © Microsoft 2026