跳转到主要内容
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-kontext-max \
  --form 'prompt=Place the person from image 1 into the scene from image 2, color palette from image 3' \
  --form 'image[]=<string>' \
  --form size=1024x1024 \
  --form width=1056 \
  --form height=1056 \
  --form seed=123 \
  --form safety_tolerance=2 \
  --form output_format=jpeg \
  --form steps=50 \
  --form guidance=4.5 \
  --form image[].items='@example-file'
{
  "created": 1776832476,
  "data": [
    {
      "url": "https://delivery-eu.bfl.ai/results/xxx/sample.jpeg?signature=..."
    }
  ]
}
右侧的交互式 Playground 支持直接上传本地图片。请在 Authorization 中填入你的 API Key(格式:Bearer sk-xxx),选择 image 文件并填入 promptmodel 后一键发送即可。
场景说明:本页用于「基于一张或多张参考图改图 / 多图融合」。请求为 multipart/form-data 格式。如需纯文本生成图片,请使用 文生图接口
⚠️ 关键差异 / 注意事项
  • 多图上限因模型而异: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 必须立即下载
  • 不传 width / height 时,输出尺寸自动匹配第一张输入图
📎 多图融合顺序有意义image[] 字段可重复传入多张参考图,顺序将作为 prompt 中「图1/图2/图3」的引用依据。建议在 prompt 中显式指代,例如:
把图1的人物放进图2的场景,沿用图3的色彩风格
推荐单张 ≤ 20MB,格式 png / jpg / webp

代码示例

Python(OpenAI SDK · 单图编辑)

from openai import OpenAI
import requests

client = OpenAI(
    api_key="sk-your-api-key",
    base_url="https://api.apiyi.com/v1"
)

resp = client.images.edit(
    model="flux-kontext-max",
    image=open("photo.png", "rb"),
    prompt="Replace 'joy' with 'BFL' on the sign, keep all other text and layout unchanged",
    size="1024x1024"
)

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

Python(OpenAI SDK · 多图融合)

resp = client.images.edit(
    model="flux-2-pro",
    image=[
        open("person.png", "rb"),
        open("scene.png", "rb"),
        open("style.png", "rb"),
    ],
    prompt="Place the person from image 1 into the scene from image 2, applying the color palette of image 3, keep lighting consistent",
    size="1536x1024"
)

image_url = resp.data[0].url
with open("fused.jpg", "wb") as f:
    f.write(requests.get(image_url, timeout=30).content)

cURL(多图融合)

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 "size=1536x1024" \
  -F "image[][email protected]" \
  -F "image[][email protected]" \
  -F "image[][email protected]"

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[][email protected]"

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

import fs from 'node:fs';

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('size', '1024x1024');
form.append('image[]', new Blob([fs.readFileSync('./person.png')]), 'person.png');
form.append('image[]', new Blob([fs.readFileSync('./outfit.png')]), 'outfit.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();
const img = await fetch(data[0].url);
fs.writeFileSync('fused.jpg', Buffer.from(await img.arrayBuffer()));

参数说明速查

字段类型必填默认说明
modeltextFLUX 模型 ID,编辑场景推荐 flux-kontext-max / flux-kontext-pro(单图)或 flux-2-pro / flux-2-max(多图)
prompttext编辑 / 融合指令,最长 32K tokens;多图场景用「图1/图2/图3」指代上传顺序
image[]file参考图,可重复多次。FLUX.2 [pro/max/flex] 最多 8 张,[klein] 4 张,Kontext 1 张
sizetext跟随首图OpenAI 风格尺寸字符串,如 1024x1024
widthinteger跟随首图BFL 原生写法,必须 16 倍数
heightinteger跟随首图BFL 原生写法,必须 16 倍数
seedinteger随机固定可复现
safety_toleranceinteger20(最严)– 6(最宽松)
output_formattextjpegjpeg / png
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-kontext-max
必填

FLUX 模型 ID。编辑场景推荐 flux-kontext-max / flux-kontext-pro(单图)或 flux-2-pro / flux-2-max(多图)

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

编辑/融合指令,最长 32K tokens。多图场景用「image 1 / image 2」指代 image[] 上传顺序

示例:

"Place the person from image 1 into the scene from image 2, color palette from image 3"

image[]
file[]
必填

参考图,可重复多次。上限因模型而异:

  • FLUX.2 [pro/max/flex]:最多 8 张
  • FLUX.2 [klein]:最多 4 张
  • FLUX.1 Kontext:1 张 单张 ≤ 20MB / 20MP,格式 png/jpg/webp。
Maximum array length: 8
size
string

OpenAI 风格尺寸字符串。不传则跟随第一张输入图

示例:

"1024x1024"

width
integer

BFL 原生写法。必须 16 的倍数

必填范围: 64 <= x <= 2048
height
integer

BFL 原生写法。必须 16 的倍数

必填范围: 64 <= x <= 2048
seed
integer

固定可复现

safety_tolerance
integer
默认值:2

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

必填范围: 0 <= x <= 6
output_format
enum<string>
默认值:jpeg

输出格式

可用选项:
jpeg,
png
steps
integer
默认值:50

仅 flux-2-flex。推理步数

必填范围: 1 <= x <= 50
guidance
number
默认值:4.5

仅 flux-2-flex。引导强度

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

响应

成功生成图片

created
integer
示例:

1776832476

data
object[]

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