跳转到主要内容
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-vip \
  --form 'prompt=把图1的人物放进图2的场景,参考图3的画风' \
  --form 'image[]=<string>' \
  --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..."
    }
  ]
}

Documentation Index

Fetch the complete documentation index at: https://docs.apiyi.com/llms.txt

Use this file to discover all available pages before exploring further.

右侧的交互式 Playground 支持直接上传本地图片。请在 Authorization 中填入你的 API Key(格式:Bearer sk-xxx),选择图片与填入 promptmodelsize 后一键发送即可。
场景说明:本页用于「基于一张或多张参考图改图 / 融合生成」。请求为 multipart/form-data 格式。如需纯文本生成图片,请使用 文生图接口gpt-image-2-all 的区别:调用结构完全一致,只多一个 size 字段;不需要锁尺寸、追求出图速度时改用 gpt-image-2-all
🖥️ 浏览器 Playground 限制(仅 b64_json 模式)默认 response_format: "url" 模式下 Playground 工作正常(响应只是一个 R2 链接)。如果你切换成 response_format: "b64_json",响应会包含数 MB 的 base64 字符串,浏览器 Playground 可能弹出 请求时发生错误: unable to complete request ——实际请求已经成功,只是浏览器无法显示这么长的 base64。推荐做法
  • 只想看图:保持默认 url 模式,Playground 会直接返回链接。
  • 真的需要 b64_json 或要传超大参考图:复制下方”代码示例”到本地运行,代码会自动处理上传与解码。
📎 多图融合顺序有意义image[] 字段可重复传入多张参考图,顺序将作为 prompt 中「图1/图2/图3」的引用依据。建议在 prompt 中显式指代,例如:
把图1的人物放进图2的场景,参考图3的画风
推荐单张 ≤ 10MB,格式 png / jpg / webp,过大的图可能触发网关限制。
⚠️ 关键参数说明
  • size:必须从 30 档常见尺寸里选;写法用半角小写 x,如 2048x13603840x2160。完整表见 概览页
  • quality:❌ 不接受,不要传
  • n:❌ 不接受,单次仅返回 1 张图。

代码示例

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-vip",
            "prompt": "把背景换成海边黄昏",
            "size": "2048x1360",          # 3:2 2K Recommended
            "response_format": "url"
        },
        files=[
            ("image[]", ("photo.png", f, "image/png"))
        ],
        timeout=300  # 保守值,吸收长尾 + 图片上传/下载耗时
    ).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-vip",
            "prompt": "把图1的人物放进图2的场景,参考图3的画风",
            "size": "2048x2048",          # 1:1 2K Recommended
            "response_format": "b64_json"
        },
        files=[
            ("image[]", ("ref1.png", f1, "image/png")),
            ("image[]", ("ref2.png", f2, "image/png")),
            ("image[]", ("ref3.png", f3, "image/png"))
        ],
        timeout=300  # 保守值,吸收长尾 + 图片上传/下载耗时
    ).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-vip" \
  -F "prompt=把背景换成海边黄昏" \
  -F "size=2048x1360" \
  -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-vip" \
  -F "prompt=把图1的人物放进图2的场景,参考图3的画风" \
  -F "size=2048x2048" \
  -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-vip');
form.append('prompt', '把背景换成太空');
form.append('size', '2048x1360');
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-vip');
form.append('prompt', '把这几张图融合成一张海报');
form.append('size', '2048x2048');
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-vip
prompttext改图/融合的自然语言描述
image[]file参考图,可重复多次(数组字段)
sizetext强烈建议输出尺寸,从 30 档里选;写法 宽x高(半角小写 x
response_formattexturl(默认)或 b64_json
多轮迭代:把上一次的输出图片作为下一次的 image[] 输入,配合新的编辑指令,可逐步精调画面效果。每一轮都可以独立指定 size

响应格式

与文生图接口一致: 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, 前缀,可直接使用。无需再手动拼接前缀

相关资源

模型概览(含完整 size 表)

30 档 size 完整对照表、定价、技术规格

对话式 API

Chat Completions 格式,方便传入在线 URL 改图

文生图 API

/v1/images/generations 兼容端点

姐妹模型 gpt-image-2-all

不需要锁尺寸时调用方式一致,出图更快

授权

Authorization
string
header
必填

在 API易控制台获取的 API Key

请求体

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

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

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

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

示例:

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

image[]
file[]
必填

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

size
enum<string>

输出尺寸,从 30 档常见尺寸里选。写法:宽x高(半角小写 x),如 2048x13603840x2160。所有档位统一价 $0.03/张。

可用选项:
1280x1280,
848x1280,
1280x848,
960x1280,
1280x960,
1024x1280,
1280x1024,
720x1280,
1280x720,
1280x544,
2048x2048,
1360x2048,
2048x1360,
1536x2048,
2048x1536,
1632x2048,
2048x1632,
1152x2048,
2048x1152,
2048x864,
2880x2880,
2336x3520,
3520x2336,
2480x3312,
3312x2480,
2560x3216,
3216x2560,
2160x3840,
3840x2160,
3840x1632
示例:

"2048x1360"

response_format
enum<string>
默认值:url

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

可用选项:
url,
b64_json

响应

成功生成图片

data
object[]

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