OpenAI
OpenAI Image Edit
Creates an edited or extended image given one or more source images and a prompt.
POST
v1/images/editsAuthorizations
Authorizationstringheaderrequired
Use the following format for authentication: Bearer sk-pat-您的AccessToken
密钥的值使用HAI Gateway的个人访问令牌(以 sk-pat- 开头),无需在OpenAI处单独申请 API Key。
Base URL
Body 参数
Content-Type: multipart/form-data
modelstringbodyrequired
图像模型,如 gpt-image-2
imagefilebodyrequired
参考图像文件。多张时使用 image[] 重复字段;GPT image 系列单次最多 16 张
promptstringbodyrequired
修改描述
maskfilebody
遮罩图像(需 alpha 通道),指定要编辑的区域
nintegerbody
生成张数,默认 1,范围 1–10
sizestringbody
auto / 1024x1024 / 1536x1024 / 1024x1536
qualitystringbody
low / medium / high / auto
backgroundstringbody
背景模式:transparent / opaque / auto,默认 auto,仅 GPT image 系列
output_formatstringbody
图像编码格式:png / jpeg / webp,默认 png,仅 GPT image 系列
streambooleanbody
是否启用流式返回(增量图像),默认 false,仅 GPT image 系列
完整参数说明请参考 OpenAI 官方文档。
cURL
curl https://api.hai.network/openai/v1/images/edits \
-H "Authorization: Bearer sk-pat-您的Access Token" \
-F "model=gpt-image-2" \
-F "image[]=@body-lotion.png" \
-F "image[]=@bath-bomb.png" \
-F "image[]=@incense-kit.png" \
-F "image[]=@soap.png" \
-F "prompt=Create a lovely gift basket with these four items in it"200
{
"created": 1713833628,
"data": [
{
"b64_json": "..."
}
],
"usage": {
"total_tokens": 100,
"input_tokens": 50,
"output_tokens": 50,
"input_tokens_details": {
"text_tokens": 10,
"image_tokens": 40
}
}
}