Skip to main content
POST
OpenAI image edits
用于基于原图和可选 mask 做图片编辑、局部重绘和风格改写。
  • 使用 Authorization: Bearer {API_KEY} 鉴权
  • 这个接口通常使用 multipart/form-data
  • 必填输入通常是 imagepromptmask 用于限定可编辑区域
  • gpt-image-1dall-e-2 的输入限制差异较大,特别是文件大小、是否支持多图和 input_fidelity
  • 如果返回的是临时 url,建议由服务端尽快转存;如果返回 b64_json,避免前端一次性解码过多大图

授权

Authorization
string
header
必填

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

请求体

multipart/form-data
image
必填

Input image or images to edit.

prompt
string
必填

Text instruction describing the desired edit.

示例:

"在图片中添加一朵红色的玫瑰花"

background
enum<string>

Only supported by gpt-image-1.

可用选项:
transparent,
opaque,
auto
input_fidelity
enum<string>

Only supported by gpt-image-1.

可用选项:
high,
low
mask
file

Optional PNG mask file. Usually must match the image dimensions.

model
enum<string>

Image editing model.

可用选项:
gpt-image-1,
dall-e-2
n
integer
默认值:1

Number of edited images to generate.

必填范围: 1 <= x <= 10
output_compression
integer
默认值:100

Compression level for gpt-image-1 jpeg/webp output.

必填范围: 0 <= x <= 100
output_format
enum<string>

Only supported by gpt-image-1.

可用选项:
png,
jpeg,
webp
partial_images
integer
默认值:0

Number of partial images for streaming previews.

必填范围: 0 <= x <= 3
quality
enum<string>

Supported values vary by model.

可用选项:
auto,
high,
medium,
low,
standard
response_format
enum<string>

Only applies to dall-e-2.

可用选项:
url,
b64_json
size
enum<string>

Allowed values depend on the selected model.

可用选项:
1024x1024,
1536x1024,
1024x1536,
auto,
256x256,
512x512
stream
boolean
默认值:false

Streams edited image output when supported.

user
string

Unique identifier for the end user.

响应

Successful image edit response

created
integer<int64>
必填

Unix timestamp in seconds.

data
object[]
必填
background
enum<string>
可用选项:
transparent,
opaque,
auto
output_format
enum<string>
可用选项:
png,
jpeg,
webp
quality
enum<string>
可用选项:
auto,
high,
medium,
low,
hd,
standard
size
string
usage
object