跳转到主要内容
POST
/
v1
/
images
/
edits
图片编辑:根据指令编辑或融合参考图
curl --request POST \
  --url https://api.apiyi.com/v1/images/edits \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: multipart/form-data' \
  --form model=gpt-image-2-all \
  --form 'prompt=把图1的人物放进图2的场景,参考图3的画风' \
  --form 'image[]=<string>' \
  --form response_format=url \
  --form image[].items='@example-file'
{
  "data": [
    {
      "url": "https://r2cdn.copilotbase.com/r2cdn2/00aaa9fb-756c-4119-a4a0-4a44fc75152b.png",
      "b64_json": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."
    }
  ]
}
右侧的交互式 Playground 支持直接上传本地图片。请在 Authorization 中填入你的 API Key(格式:Bearer sk-xxx),选择图片与填入 promptmodel 后一键发送即可。
场景说明:本页用于「基于一张或多张参考图改图 / 融合生成」。请求为 multipart/form-data 格式。如需纯文本生成图片,请使用 文生图接口
📎 多图融合顺序有意义image[] 字段可重复传入多张参考图,顺序将作为 prompt 中「图1/图2/图3」的引用依据。建议在 prompt 中显式指代,例如:
把图1的人物放进图2的场景,参考图3的画风
推荐单张 ≤ 10MB,格式 png / jpg / webp,过大的图可能触发网关限制。

代码示例

Python

单图编辑
import requests

API_KEY = "sk-your-api-key"

with open("photo.png", "rb") as f:
    response = requests.post(
        "https://api.apiyi.com/v1/images/edits",
        headers={"Authorization": f"Bearer {API_KEY}"},
        data={
            "model": "gpt-image-2-all",
            "prompt": "把背景换成海边黄昏",
            "response_format": "url"
        },
        files=[
            ("image[]", ("photo.png", f, "image/png"))
        ],
        timeout=120
    ).json()

print(response["data"][0]["url"])
多图融合
import requests

with open("ref1.png", "rb") as f1, \
     open("ref2.png", "rb") as f2, \
     open("ref3.png", "rb") as f3:
    response = requests.post(
        "https://api.apiyi.com/v1/images/edits",
        headers={"Authorization": "Bearer sk-your-api-key"},
        data={
            "model": "gpt-image-2-all",
            "prompt": "把图1的人物放进图2的场景,参考图3的画风",
            "response_format": "b64_json"
        },
        files=[
            ("image[]", ("ref1.png", f1, "image/png")),
            ("image[]", ("ref2.png", f2, "image/png")),
            ("image[]", ("ref3.png", f3, "image/png"))
        ],
        timeout=120
    ).json()

# b64_json 已含 "data:image/png;base64," 前缀,可直接用于 <img src>
data_url = response["data"][0]["b64_json"]

cURL

单图编辑
curl -X POST "https://api.apiyi.com/v1/images/edits" \
  -H "Authorization: Bearer sk-your-api-key" \
  -F "model=gpt-image-2-all" \
  -F "prompt=把背景换成海边黄昏" \
  -F "response_format=url" \
  -F "image[]=@./photo.png"
多图融合
curl -X POST "https://api.apiyi.com/v1/images/edits" \
  -H "Authorization: Bearer sk-your-api-key" \
  -F "model=gpt-image-2-all" \
  -F "prompt=把图1的人物放进图2的场景,参考图3的画风" \
  -F "response_format=b64_json" \
  -F "image[]=@./ref1.png" \
  -F "image[]=@./ref2.png" \
  -F "image[]=@./ref3.png"

Node.js(原生 fetch + FormData)

import fs from 'node:fs';

const form = new FormData();
form.append('model', 'gpt-image-2-all');
form.append('prompt', '把背景换成太空');
form.append('response_format', 'url');
form.append(
  'image[]',
  new Blob([fs.readFileSync('./photo.png')]),
  'photo.png'
);

const resp = await fetch('https://api.apiyi.com/v1/images/edits', {
    method: 'POST',
    headers: { 'Authorization': 'Bearer sk-your-api-key' },
    body: form
});
const data = await resp.json();
console.log(data.data[0].url);

浏览器 JavaScript(File 对象)

// <input type="file" id="fileInput" multiple>
const files = document.getElementById('fileInput').files;
const form = new FormData();
form.append('model', 'gpt-image-2-all');
form.append('prompt', '把这几张图融合成一张海报');
form.append('response_format', 'url');
for (const f of files) form.append('image[]', f);

const resp = await fetch('https://api.apiyi.com/v1/images/edits', {
    method: 'POST',
    headers: { 'Authorization': 'Bearer sk-your-api-key' },
    body: form
});
const { data } = await resp.json();
document.getElementById('result').src = data[0].url;

参数说明速查

字段类型必填说明
modeltext固定填 gpt-image-2-all
prompttext改图/融合的自然语言描述
image[]file参考图,可重复多次(数组字段)
response_formattexturl(默认)或 b64_json
多轮迭代:把上一次的输出图片作为下一次的 image[] 输入,配合新的编辑指令,可逐步精调画面效果。

响应格式

与文生图接口一致: url 模式
{
    "data": [
        {
            "url": "https://r2cdn.copilotbase.com/r2cdn2/xxxxx.png"
        }
    ]
}
b64_json 模式
{
    "data": [
        {
            "b64_json": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."
        }
    ]
}
b64_json 字段已经包含 data:image/png;base64, 前缀,可直接使用。无需再手动拼接前缀

授权

Authorization
string
header
必填

在 API易控制台获取的 API Key

请求体

multipart/form-data
model
enum<string>
默认值:gpt-image-2-all
必填

模型名称,固定为 gpt-image-2-all

可用选项:
gpt-image-2-all
prompt
string
必填

编辑/融合指令。多图场景可用「图1/图2/图3」指代 image[] 的上传顺序

示例:

"把图1的人物放进图2的场景,参考图3的画风"

image[]
file[]
必填

参考图,可重复多次。推荐单张 ≤ 10MB,格式 png/jpg/webp

response_format
enum<string>
默认值:url

响应格式。url 返回 R2 CDN 链接(默认);b64_json 返回已含 data URL 前缀的 base64 字符串

可用选项:
url,
b64_json

响应

成功生成图片

data
object[]

生成结果数组(本模型单次返回 1 张)