跳转到主要内容
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=flux-2-pro \
  --form 'prompt=Place the person from image 1 into the scene from image 2' \
  --form image=https://your-oss.example.com/image1.jpg
{
  "created": 1776832476,
  "data": [
    {
      "url": "https://delivery-eu.bfl.ai/results/xxx/sample.jpeg?signature=..."
    }
  ]
}
右侧的交互式 Playground:在 Authorization 中填入 API Key(格式:Bearer sk-xxx),所有参考图都填公网 URL 字符串:第 1 张填 image,第 2–8 张填 input_image_2input_image_8,然后填 promptmodel 一键发送即可。本地图片需先上传到图床/OSS 拿到公网 URL。
场景说明:本页用于「基于一张或多张参考图改图 / 多图融合」。apiyi 代理强制 multipart/form-data 传输,但所有参考图字段都是 URL 字符串而非二进制文件 —— 实测 apiyi 对 FLUX 的二进制 image 翻译不生效,URL 字段才能可靠地传给 BFL。如需纯文本生成图片,请使用 文生图接口
⚠️ 关键差异 / 注意事项
  • 所有参考图都是 URL 字符串(不接受本地文件直传 —— 请先上传到图床/OSS)
  • 第 1 张填 image,第 2–8 张填 input_image_2input_image_8
  • 多图上限因模型而异:FLUX.2 [pro/max/flex] 最多 8 张,FLUX.2 [klein] 最多 4 张,FLUX.1 Kontext 系列原生只支持 1 张
  • 单张参考图 ≤ 20MB 或 20MP,格式 png / jpg / webp
  • 输入分辨率:最小 64×64,最大 4MP;dimensions 必须是 16 的倍数
  • 结果 URL 仅 10 分钟有效data[0].url 必须立即下载
  • 不传 aspect_ratio 时,输出尺寸自动匹配第一张输入图
📎 多图融合顺序有意义input_image / input_image_2 / input_image_3 … 的编号 就是 prompt 中「image 1 / image 2 / image 3」的引用依据。建议在 prompt 中显式指代,例如:
Place the person from image 1 into the scene from image 2, applying the color palette of image 3.
每张图必须为可公网访问的 URL(推荐 ≤ 20MB),或 data:image/png;base64,xxx 格式 base64 data URL。

代码示例

cURL(多图融合 · 全 URL)

curl -X POST "https://api.apiyi.com/v1/images/edits" \
  -H "Authorization: Bearer sk-your-api-key" \
  -F "model=flux-2-pro" \
  -F "prompt=Place the person from image 1 into the scene from image 2, color palette from image 3" \
  -F "image=https://your-oss.example.com/person.png" \
  -F "input_image_2=https://your-oss.example.com/scene.png" \
  -F "input_image_3=https://your-oss.example.com/style.png" \
  -F "aspect_ratio=3:2"

cURL(单图编辑 · Kontext)

curl -X POST "https://api.apiyi.com/v1/images/edits" \
  -H "Authorization: Bearer sk-your-api-key" \
  -F "model=flux-kontext-pro" \
  -F "prompt=Convert this architectural photo into a pencil sketch style, preserve all structural details" \
  -F "image=https://your-oss.example.com/architecture.jpg"

Python(requests · 多图融合)

import requests

resp = requests.post(
    "https://api.apiyi.com/v1/images/edits",
    headers={"Authorization": "Bearer sk-your-api-key"},
    files={  # 用 files 触发 requests 自动设置 multipart/form-data
        "model": (None, "flux-2-pro"),
        "prompt": (None, "Place the person from image 1 into the scene from image 2, color palette from image 3"),
        "image": (None, "https://your-oss.example.com/person.png"),
        "input_image_2": (None, "https://your-oss.example.com/scene.png"),
        "input_image_3": (None, "https://your-oss.example.com/style.png"),
        "aspect_ratio": (None, "3:2"),
    },
    timeout=120,
)
image_url = resp.json()["data"][0]["url"]

# data[0].url 仅 10 分钟有效,立即下载
with open("fused.jpg", "wb") as f:
    f.write(requests.get(image_url, timeout=30).content)

Node.js(原生 fetch + FormData · 多图融合)

const form = new FormData();
form.append('model', 'flux-2-pro');
form.append('prompt', 'Replace the top of the person from image 1 with the one from image 2');
form.append('image', 'https://your-oss.example.com/person.png');
form.append('input_image_2', 'https://your-oss.example.com/outfit.png');
form.append('aspect_ratio', '1:1');

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();
const img = await fetch(data[0].url);
const fs = await import('node:fs');
fs.writeFileSync('fused.jpg', Buffer.from(await img.arrayBuffer()));

参数说明速查

字段类型必填默认说明
modelstringFLUX 模型 ID,多图融合推荐 flux-2-pro / flux-2-max,单图改图也可用 flux-kontext-max / flux-kontext-pro
promptstring编辑 / 融合指令,最长 32K tokens;多图场景用「image 1 / image 2 / image 3」指代 image / input_image_2 / input_image_3 顺序
imagestring参考图 1 的公网 URL(apiyi 网关检查需此字段存在,apiyi 映射为 BFL 的 input_image
input_image_2 ~ input_image_8string第 2–8 张参考图的公网 URL。FLUX.2 [pro/max/flex] 最多 8 张,[klein] 4 张,Kontext 不支持
aspect_ratiostring跟随首图例如 1:1 / 16:9 / 9:16 / 4:3 / 3:2
seedinteger随机固定可复现
safety_toleranceinteger20(最严)– 6(最宽松)
output_formatstringjpegjpeg / png
prompt_upsamplingbooleanfalse是否自动扩写 prompt
stepsinteger50flux-2-flex,最大 50
guidancenumber4.5flux-2-flex,1.5–10

多图融合策略

上传同一角色的多张照片作参考,模型会自动维持身份特征。适合广告系列、漫画分镜、时尚编辑。
Eight consistent characters from the reference images,
in a fashion editorial set on a Tokyo rooftop at golden hour
一张内容图 + 一张风格图,prompt 显式指代:
Using the style of image 2, render the subject from image 1
把多张图里的不同物体组合到一个新场景:
The person from image 1 is petting the cat from image 2,
the bird from image 3 is next to them
把图1人物的上衣换成图2 的款式:
Replace the top of the person in image 1 with the one from image 2,
keep the pose and background unchanged
多轮迭代:把上一次的 data[0].url 重新下载后作为下一次 image[] 输入,配合新指令逐步精调画面。每轮按张数计费。

响应格式

{
    "created": 1776832476,
    "data": [
        {
            "url": "https://delivery-eu.bfl.ai/results/xxx/sample.jpeg?signature=..."
        }
    ]
}
⚠️ data[0].url 仅 10 分钟有效
  • URL 托管在 delivery-eu.bfl.ai / delivery-us.bfl.ai,签名 10 分钟过期
  • 不开启 CORS,浏览器 fetch 会被拦
  • 生产服务必须服务端代下载到自有 OSS / CDN
  • FLUX 编辑端点不返回 b64_json,仅返回 url
编辑请求与文生图同价,按张数计费而非按 token。多图融合不会因图片数量加价(与 OpenAI gpt-image-2 编辑不同)。

授权

Authorization
string
header
必填

在 API易控制台获取的 API Key

请求体

multipart/form-data
model
enum<string>
默认值:flux-2-pro
必填

FLUX 模型 ID。多图融合推荐 flux-2-pro / flux-2-max;单图改图也可用 flux-kontext-max / flux-kontext-pro

可用选项:
flux-2-pro,
flux-2-max,
flux-2-flex,
flux-2-klein-9b,
flux-2-klein-4b,
flux-kontext-max,
flux-kontext-pro
prompt
string
必填

编辑/融合指令。多图场景用「image 1 / image 2 / image 3」指代 image / input_image_2 / input_image_3 顺序

示例:

"Place the person from image 1 into the scene from image 2"

image
string
必填

参考图 1 的公网 URL(必填)。本地图片需先上传到任意图床/OSS 拿到 URL 再填入

示例:

"https://your-oss.example.com/image1.jpg"

input_image_2
string

参考图 2 的公网 URL(可选)。apiyi 直通给 BFL

input_image_3
string

参考图 3 的公网 URL(可选)

input_image_4
string

参考图 4 的公网 URL(可选)

input_image_5
string

参考图 5 的公网 URL(可选)

input_image_6
string

参考图 6 的公网 URL(可选)

input_image_7
string

参考图 7 的公网 URL(可选)

input_image_8
string

参考图 8 的公网 URL(可选,仅 FLUX.2 [pro/max/flex] 支持到 8 张)

aspect_ratio
string

宽高比,例如 1:1 / 16:9 / 9:16 / 4:3 / 3:4。不传则跟随首张输入图

seed
integer

固定可复现

safety_tolerance
integer

审核档位。0 最严格,6 最宽松,默认 2

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

输出格式,默认 jpeg

可用选项:
jpeg,
png
prompt_upsampling
boolean

是否自动扩写 prompt,默认 false

steps
integer

仅 flux-2-flex。推理步数,默认 50

必填范围: 1 <= x <= 50
guidance
number

仅 flux-2-flex。引导强度,默认 4.5

必填范围: 1.5 <= x <= 10

响应

成功生成图片

created
integer
示例:

1776832476

data
object[]

生成结果数组(本接口单次返回 1 张)