Skip to content

编辑图片 ​

使用本接口基于一张或多张源图像和文本提示,创建编辑或扩展后的图像。此端点支持 GPT 图像模型。

接口地址 ​

http
POST /v1/images/edits

认证 ​

方式说明
Bearer Token在请求头中携带 Authorization: Bearer <API_key> 用于验证账户信息。

请求头 ​

参数名类型必填说明
Content-Typestring是请求体的媒介类型,请设置为 application/json(JSON 请求)或 multipart/form-data(表单上传图像)
Authorizationstring是Bearer API_key,用于验证账户信息

请求体 ​

参数名类型必填默认值说明
imagesarray<object>是-要编辑的输入图像引用,最少 1 张、最多 16 张,详细参数见下
promptstring是-所需图像编辑的文本描述,长度 1–32000 字符
backgroundstring否auto生成图像的背景:transparent(透明)/ opaque(不透明)/ auto(自动),分模型支持见下方说明
input_fidelitystring否low输入图像保真度:high / low,分模型支持见下方说明
markupobject否-覆盖在首张输入图像上的透明 PNG,仅支持 GPT Image 2.5 系列模型,不能与 mask 同时使用,详细参数见下
maskobject否-遮罩图像引用,image_url 与 file_id 二选一,不能与 markup 同时使用,详细参数见下
modelstring否gp-im-2.5-su用于图像编辑的 GPT 图像模型,枚举值见下
moderationstring否auto内容审核级别:low / auto
nnumber否1生成的编辑图像数量,取值范围 1–10
output_compressionnumber否-jpeg 或 webp 输出格式的压缩级别,取值范围 0–100
output_formatstring否png输出图像格式:png / jpeg / webp
partial_imagesnumber否0流式返回的中间过程图像数量,取值 0–3;设为 0 时响应将在一次流事件中返回单张完整图像。若完整图像生成较快,最终图像可能在达到指定数量前发送
qualitystring否auto输出质量:low / medium / high / xhigh / max / auto,分模型支持见下方说明
safety_identifierstring否-组织内最终用户的稳定标识符,用于安全监控和滥用检测,最大长度 128 字符;非空值优先于已废弃的 user 参数
sizestring否auto输出图像尺寸,支持标准尺寸与任意分辨率,详见下方说明
streamboolean否false是否以流式事件返回中间图像结果
userstring否-已废弃:请改用 safety_identifier。为保持向后兼容仍接受此参数,当 safety_identifier 省略、为 null 或为空时使用

images 详细参数 ​

参数名类型必填默认值说明
file_idstring否-已上传图像的 File API ID,用作输入;与 image_url 二选一
image_urlstring否-完整的 URL 或 base64 编码的 data URL,最大长度 20971520

markup 详细参数 ​

覆盖在首张输入图像上的透明 PNG,方向调整后必须与该图像尺寸一致,且包含透明像素。

参数名类型必填默认值说明
file_idstring否-已上传图像的 File API ID;与 image_url 二选一
image_urlstring否-HTTPS URL 或 base64 编码的 data URL,最大长度 20971520

mask 详细参数 ​

参数名类型必填默认值说明
file_idstring否-已上传遮罩图像的 File API ID;与 image_url 二选一
image_urlstring否-完整的 URL 或 base64 编码的 data URL,最大长度 20971520

model 枚举值 ​

  • gp-im-1.5
  • gp-im-2
  • gp-im-2-2026-04-21
  • gp-im-2.5-su
  • gp-im-2.5-su-2026-09-08
  • gp-im-2.5-fl
  • gp-im-2.5-fl-2026-09-08
  • gp-im-1
  • gp-im-1-mini

gp-im-1 已于 2026 年 10 月 23 日下线,请改用 gp-im-2.5-su 或 gp-im-2.5-fl。

参数补充说明 ​

  • background:gp-im-2.5-su 和 gp-im-2.5-fl(含 2026-09-08 快照)支持 opaque 和 transparent 背景。透明背景适用于受支持的 GPT 图像模型;对于 gp-im-2 和 gp-im-2-2026-04-21,该支持处于预览阶段。使用 transparent 时,输出格式需设为 png 或 webp。
  • input_fidelity:控制模型在匹配输入图像的风格和特征(尤其是面部特征)上所付出的努力程度。gp-im-1.5 支持 high 和 low;gp-im-1-mini 仅支持 low;对于 gp-im-2,请省略此参数。受支持的模型上默认为 low。
  • quality:GPT 图像模型支持 low、medium 和 high;gp-im-2.5-su 和 gp-im-2.5-fl(含 2026-09-08 快照)还支持 xhigh 和 max。
  • size:对于 gp-im-2、gp-im-2-2026-04-21、gp-im-2.5-su、gp-im-2.5-su-2026-09-08、gp-im-2.5-fl 和 gp-im-2.5-fl-2026-09-08,支持 WIDTHxHEIGHT 格式的任意分辨率,例如 1536x864。宽和高都必须能被 16 整除,且宽高比需在 1:3 到 3:1 之间。分辨率超过 2560x1440 为实验性支持,最大分辨率为 3840x2160。请求的尺寸还须满足模型当前的像素和边长限制。GPT 图像模型支持标准尺寸 1024x1024、1536x1024 和 1024x1536;auto 适用于允许自动尺寸的模型。
  • safety_identifier:请对用户名或邮箱地址进行哈希处理,避免发送可识别信息。如果省略、为 null 或为空,API 将在 user 可用时使用它。

请求示例 ​

bash
curl --request POST 'https://neolink.com/api/v1/images/edits' \
     --header 'Authorization: Bearer <API Key>' \
     --form 'model=gp-im-1.5' \
     --form 'image[]=@body-lotion.png' \
     --form 'image[]=@bath-bomb.png' \
     --form 'image[]=@incense-kit.png' \
     --form 'image[]=@soap.png' \
     --form 'prompt=将这四个物品组合成一个精美的礼品篮'
bash
curl --request POST 'https://neolink.com/api/v1/images/edits' \
     --header 'Authorization: Bearer <API Key>' \
     --form 'model=gp-im-1.5' \
     --form 'image[]=@body-lotion.png' \
     --form 'image[]=@bath-bomb.png' \
     --form 'image[]=@incense-kit.png' \
     --form 'image[]=@soap.png' \
     --form 'prompt=将这四个物品组合成一个精美的礼品篮' \
     --form 'stream=true' \
     --no-buffer
bash
curl --request POST 'https://neolink.com/api/v1/images/edits' \
     --header 'Content-Type: application/json' \
     --header 'Authorization: Bearer <API Key>' \
     --data-raw '{
         "images": [
             {
                 "image_url": "https://example.com/source-image.png"
             }
         ],
         "prompt": "为这张图片添加水彩效果",
         "model": "gp-im-1.5",
         "quality": "high",
         "size": "1024x1024"
     }'
bash
curl --request POST 'https://neolink.com/api/v1/images/edits' \
     --header 'Content-Type: application/json' \
     --header 'Authorization: Bearer <API Key>' \
     --data-raw '{
         "images": [
             {
                 "file_id": "file-abc123"
             }
         ],
         "prompt": "将背景替换为雪山场景",
         "mask": {
             "file_id": "file-mask123"
         },
         "model": "gp-im-1.5",
         "output_compression": 100,
         "output_format": "png"
     }'

响应体 ​

参数名类型说明
creatednumber图像创建时的 Unix 时间戳(秒)
backgroundstring图像生成所使用的背景参数:transparent 或 opaque
dataarray<object>生成的图像列表,详细参数见下
output_formatstring图像生成的输出格式:png / webp / jpeg
qualitystring生成图像的质量:low / medium / high / xhigh / max
safety_identifierstring实际生效的安全标识符,用于安全监控和滥用检测。为请求中非空的 safety_identifier;当其省略、为 null 或为空时,为已废弃的 user 值
sizestring图像尺寸,为 WIDTHxHEIGHT 格式字符串,例如 1536x864
usageobject仅 gp-im-1 支持,图像生成的令牌用量信息,详细参数见下

data 详细参数 ​

参数名类型说明
b64_jsonstring生成图像的 base64 编码 JSON。GPT 图像模型默认返回此字段;支持 response_format 参数的模型在设为 b64_json 时返回
revised_promptstring用于生成图像的修订后提示词,适用于支持提示词修订的模型。GPT 图像模型不返回此字段
urlstring支持 response_format 参数的模型在设为 url 时返回的图像 URL。GPT 图像模型不支持此字段

usage 详细参数 ​

参数名类型说明
input_tokensnumber输入提示中的令牌数(图像和文本)
input_tokens_details.image_tokensnumber输入提示中的图像令牌数
input_tokens_details.text_tokensnumber输入提示中的文本令牌数
output_tokensnumber模型生成的输出令牌数
output_tokens_details.image_tokensnumber模型生成的图像输出令牌数
output_tokens_details.text_tokensnumber模型生成的文本输出令牌数
total_tokensnumber图像生成所使用的总令牌数(图像和文本)

响应示例 ​

非流式响应:

json
{
  "created": 0,
  "background": "transparent",
  "data": [
    {
      "b64_json": "b64_json",
      "revised_prompt": "revised_prompt",
      "url": "https://example.com"
    }
  ],
  "output_format": "png",
  "quality": "low",
  "safety_identifier": "safety_identifier",
  "size": "1024x1024",
  "usage": {
    "input_tokens": 0,
    "input_tokens_details": {
      "image_tokens": 0,
      "text_tokens": 0
    },
    "output_tokens": 0,
    "total_tokens": 0,
    "output_tokens_details": {
      "image_tokens": 0,
      "text_tokens": 0
    }
  }
}

流式响应:当 stream 为 true 时,响应以 SSE 事件流返回。中间图像通过 image_edit.partial_image 事件推送(partial_image_index 为中间图像序号),最终结果通过 image_edit.completed 事件返回:

json
event: image_edit.partial_image
data: {"type":"image_edit.partial_image","b64_json":"...","partial_image_index":0}

event: image_edit.completed
data: {"type":"image_edit.completed","b64_json":"...","usage":{"total_tokens":100,"input_tokens":50,"output_tokens":50,"input_tokens_details":{"text_tokens":10,"image_tokens":40}}}