图片编辑 / 多图融合 / RGBA / 图层拆分
curl --request POST \
--url https://api.apiyi.com/v1/images/generations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "seedream-5-5-261028"
}
'import requests
url = "https://api.apiyi.com/v1/images/generations"
payload = { "model": "seedream-5-5-261028" }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({model: 'seedream-5-5-261028'})
};
fetch('https://api.apiyi.com/v1/images/generations', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.apiyi.com/v1/images/generations",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => 'seedream-5-5-261028'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.apiyi.com/v1/images/generations"
payload := strings.NewReader("{\n \"model\": \"seedream-5-5-261028\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.apiyi.com/v1/images/generations")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"seedream-5-5-261028\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.apiyi.com/v1/images/generations")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"seedream-5-5-261028\"\n}"
response = http.request(request)
puts response.read_body{
"model": "dola-seedream-5-5-261028",
"created": 1784696685,
"data": [
{
"url": "https://ark-content-generation-v2-ap-southeast-1.tos-ap-southeast-1.bytepluses.com/.../image.png",
"b64_json": "<string>",
"size": "1024x1024",
"output_format": "png",
"z_index": 1,
"name": "Young woman in white cheongsam",
"description": "<string>",
"bounding_box": {
"absolute": [
0,
0,
1024,
1024
],
"normalized": [
0,
0,
1000,
1000
]
},
"text_recognition": {
"text": "<string>",
"lines": [
{
"bounding_box": {
"absolute": [
0,
0,
1024,
1024
],
"normalized": [
0,
0,
1000,
1000
]
},
"runs": [
{
"text": "<string>",
"style": {
"similar_font_family": "<string>",
"foreground_color": "#193366",
"bold": true,
"italic": true,
"underline": true,
"strikethrough": true,
"shadow": true,
"translucent": true
}
}
]
}
]
}
}
],
"usage": {
"input_images": 1,
"generated_images": 2,
"output_tokens": 8192,
"total_tokens": 8192
}
}Seedream 5.5 / 5.0 等系列
图片编辑 API 参考
Seedream 5.5 图片编辑、多图融合、原生 RGBA、图层拆分与文字 OCR Playground;同时支持早期版本的批量序列生成。
POST
/
v1
/
images
/
generations
图片编辑 / 多图融合 / RGBA / 图层拆分
curl --request POST \
--url https://api.apiyi.com/v1/images/generations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "seedream-5-5-261028"
}
'import requests
url = "https://api.apiyi.com/v1/images/generations"
payload = { "model": "seedream-5-5-261028" }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({model: 'seedream-5-5-261028'})
};
fetch('https://api.apiyi.com/v1/images/generations', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.apiyi.com/v1/images/generations",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => 'seedream-5-5-261028'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.apiyi.com/v1/images/generations"
payload := strings.NewReader("{\n \"model\": \"seedream-5-5-261028\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.apiyi.com/v1/images/generations")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"seedream-5-5-261028\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.apiyi.com/v1/images/generations")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"seedream-5-5-261028\"\n}"
response = http.request(request)
puts response.read_body{
"model": "dola-seedream-5-5-261028",
"created": 1784696685,
"data": [
{
"url": "https://ark-content-generation-v2-ap-southeast-1.tos-ap-southeast-1.bytepluses.com/.../image.png",
"b64_json": "<string>",
"size": "1024x1024",
"output_format": "png",
"z_index": 1,
"name": "Young woman in white cheongsam",
"description": "<string>",
"bounding_box": {
"absolute": [
0,
0,
1024,
1024
],
"normalized": [
0,
0,
1000,
1000
]
},
"text_recognition": {
"text": "<string>",
"lines": [
{
"bounding_box": {
"absolute": [
0,
0,
1024,
1024
],
"normalized": [
0,
0,
1000,
1000
]
},
"runs": [
{
"text": "<string>",
"style": {
"similar_font_family": "<string>",
"foreground_color": "#193366",
"bold": true,
"italic": true,
"underline": true,
"strikethrough": true,
"shadow": true,
"translucent": true
}
}
]
}
]
}
}
],
"usage": {
"input_images": 1,
"generated_images": 2,
"output_tokens": 8192,
"total_tokens": 8192
}
}同端点,不同模式:Seedream 没有独立的
/v1/images/edits 端点,编辑 / 多图融合 / 图层拆分都走 POST /v1/images/generations。本页默认模型为 seedream-5-5-261028,与 文生图页 使用同一端点。场景说明:
- 5.5 单图编辑 / 多图融合 —— 传
image,不要传sequential_image_generation - 5.5 透明图编辑 ——
background: "transparent"+output_format: "png",最多 10 张参考图,输入不要求自带 alpha 通道 - 5.5 图层拆分与 OCR —— 1 张参考图 +
layer_decomposition: true+layer_decomposition_options - 早期版本批量序列 ——
sequential_image_generation: "auto"+sequential_image_generation_options.max_images: N
🖥️ 浏览器 Playground 限制(仅 b64_json 模式)默认
response_format: "url" 模式下 Playground 工作正常(响应只是一个 BytePlus TOS 临时链接)。如果你切换成 response_format: "b64_json",响应会包含数 MB 的 base64 字符串,浏览器 Playground 可能弹出 请求时发生错误: unable to complete request ——实际请求已经成功,只是浏览器无法显示这么长的 base64。推荐做法:- 只想看图:保持默认
url模式,Playground 会直接返回链接(注意 24 小时内下载到自己的存储)。 - 真的需要 b64_json:复制下方”代码示例”到本地运行,代码会自动解码并把图片保存为本地文件。
⚠️ 关键差异(与 OpenAI gpt-image-2 的图编辑不同)
- 不接受 multipart/form-data 上传文件 —— 请把图片传到 OSS / 公网图床拿到 URL,再放进
image image可传 URL 数组;5.5 也接受单张图片的 URL / data URI 字符串,不是重复的image[]字段- 没有
mask字段 —— Seedream 不支持 alpha 通道掩码局部重绘,整图 prompt 改写 - 总张数规则分场景:早期版本批量序列的输入参考图 + 输出图 ≤ 15 张;5.5 图层拆分独立按 2–100 张(含底图)计算
📎 多图融合顺序有意义
image 数组的顺序会作为 prompt 中「图1/图2/图3」的引用依据。建议在 prompt 中显式指代:Replace the clothing in image 1 with the outfit from image 2, keeping the lighting from image 3.推荐 prompt 用英文(官方训练以英文为主),中文也可用但表达不要含糊。
代码示例
关于
extra_body(重要,别被「套一层」误导)image、sequential_image_generation、watermark 不是 OpenAI SDK images.generate() 的标准参数,所以在 Python SDK 里必须放进 extra_body 才能传出去。但 extra_body 只是 SDK 的传参容器——里面的字段会被平铺合并到请求体顶层,和 model、prompt 同一层级。最终发出去的 JSON 跟下方 cURL 示例完全一致(image 就在顶层),并不会真的多出一层 "extra_body": {...} 嵌套。如果你不用 OpenAI SDK、而是直接拼 JSON(requests / fetch 等),就不要写 extra_body,直接把 image 等字段放到与 model 同级即可。Python(OpenAI SDK · 单图编辑)
from openai import OpenAI
client = OpenAI(
api_key="sk-your-api-key",
base_url="https://api.apiyi.com/v1"
)
resp = client.images.generate(
model="seedream-5-5-261028",
prompt="Keep the dog, pose, grass, and lighting unchanged. Add a red frisbee beside the dog.",
size="2K",
response_format="url",
# extra_body 里的字段会被 SDK 平铺到请求体顶层(与 model 同级),不是真的多嵌套一层
extra_body={
"image": ["https://your-oss.example.com/source-photo.png"],
"output_format": "png",
"background": "opaque",
"watermark": False,
}
)
print(resp.data[0].url)
Python(OpenAI SDK · 多图融合)
resp = client.images.generate(
model="seedream-4-5-251128",
prompt="Replace the clothing in image 1 with the outfit from image 2, keeping the lighting style of image 3.",
size="4K",
response_format="url",
extra_body={
"image": [
"https://your-oss.example.com/person.png",
"https://your-oss.example.com/outfit.png",
"https://your-oss.example.com/lighting-ref.png",
],
"sequential_image_generation": "disabled",
"watermark": False,
}
)
print(resp.data[0].url)
Python(OpenAI SDK · 批量序列生成)
resp = client.images.generate(
model="seedream-5-0-260128",
prompt=(
"Generate four cinematic sci-fi storyboard scenes:"
"Scene 1 — astronaut repairing a spacecraft;"
"Scene 2 — meteor strike in deep space;"
"Scene 3 — emergency dodge in zero gravity;"
"Scene 4 — astronaut returning to ship."
),
size="2K",
response_format="url",
extra_body={
"sequential_image_generation": "auto",
"sequential_image_generation_options": {"max_images": 4},
"watermark": False,
}
)
for item in resp.data:
print(item.url)
cURL(多图融合)
curl -X POST "https://api.apiyi.com/v1/images/generations" \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "seedream-5-5-261028",
"prompt": "Replace the clothing in image 1 with the outfit from image 2. Preserve the person, pose, lighting, and background.",
"image": [
"https://your-oss.example.com/person.png",
"https://your-oss.example.com/outfit.png"
],
"size": "2K",
"response_format": "url",
"output_format": "png",
"background": "opaque",
"watermark": false
}'
Node.js(原生 fetch · 批量序列)
const resp = await fetch('https://api.apiyi.com/v1/images/generations', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer sk-your-api-key'
},
body: JSON.stringify({
model: 'seedream-5-0-260128',
prompt: 'A four-panel comic about a cat astronaut: launch, space walk, alien encounter, return home.',
size: '2K',
sequential_image_generation: 'auto',
sequential_image_generation_options: { max_images: 4 },
response_format: 'url',
watermark: false
})
});
const { data } = await resp.json();
data.forEach((item, i) => console.log(`#${i + 1}:`, item.url));
参考图请传公网 URL,不要传 base64(2026-09-11 起重点提醒)
image 数组的元素是 URL 时,请求体只有几 KB,BytePlus 会直接从新加坡机房去下载你的图片(实测下载方 IP 属于 BytePlus,不经过 API易 网关)。
元素是 data:image/...;base64,... 时,几张高清参考图的请求体动辄 20 到 30 MB,要先整体上传到 API易 网关再转发到新加坡,跨境上传慢的时候会超过原厂入口 600 秒的请求体超时,返回 400 Error when parsing request,
此时整条请求失败且不会自动切换成 URL 方式,因为网关不会替你把 base64 转成可下载的链接。- ✅ 把图片放到自己的 OSS / 图床,传公网可直接 GET、无鉴权的 URL,单张建议不超过 10 MB
- ⚠️ 确实只能传 base64 时,先压缩:长边缩到 2048px 以内、质量 0.9 重编码,多张合计控制在 6 MB 以内
- ❌ 不要传 20 MB 以上的 base64 请求体,也不要传内网地址或需要登录的链接(BytePlus 下载失败会返回
InvalidParameter: Error while downloading)
参数说明速查
| 字段 | 类型 | 必填 | 默认 | 说明 |
|---|---|---|---|---|
model | string | 是 | seedream-5-5-261028 | 默认 5.5,也可选择 5.0 / 4.x 活跃版本 |
prompt | string | 普通编辑必填;拆图可省略 | — | 编辑 / 融合 / 拆分指令,多图时明确「图1/图2」 |
image | string 或 array | 编辑 / 拆图必填 | — | URL 或 base64 data URI。普通编辑最多 10 张;5.5 图层拆分仅 1 张 PNG/JPEG |
background | string | 否 | auto(5.5) | transparent 输出 RGBA,需搭配 output_format: "png";多轮编辑建议 opaque;拆图不要传 |
layer_decomposition | boolean | 否 | false | 5.5 / 5.0-flash 图层拆分开关,仅传 1 张参考图 |
layer_decomposition_options.max_images | integer | 否 | 30 | 5.5 底图与图层的最大总张数,范围 2–100;是上限,不保证实际数量 |
layer_decomposition_options.text_recognition | boolean | 否 | false | 5.5 常规文字图层 OCR,返回文本、位置与近似样式 |
sequential_image_generation | string | 否 | disabled | 早期版本批量序列开关。5.5 / 5.0-pro / 5.0-flash 不支持,传任何值都返回 400 |
sequential_image_generation_options.max_images | integer | 否 | — | 仅早期版本 auto 模式生效,受输入+输出 ≤ 15 约束;5.5 不要传 |
size | string | 否 | 2K;拆图默认 auto | 5.5 普通编辑为 1K / 1.5K / 2K 或精确像素;拆图还可选 auto |
response_format | string | 否 | url | url / b64_json |
output_format | string | 否 | png(5.5) | 5.0 支持 png / jpeg;4.5 / 4.0 仅 jpeg。拆图时只控制底图,独立图层始终 PNG |
watermark | boolean | 否 | 见版本默认 | 5.5 默认 true,商用建议显式 false |
stream | boolean | 否 | false | 流式输出。5.0-pro / 5.0-flash 不支持,传入即 400 |
多图与批量场景的张数约束
| 场景 | 输入 image 张数 | max_images | 实际输出 | 总和约束 |
|---|---|---|---|---|
| 单图编辑 | 1 | — | 1 | 2 ≤ 15 ✅ |
| 多图融合 | 3 | — | 1 | 4 ≤ 15 ✅ |
| 多图融合 + 序列 | 3 | 4 | 4 | 7 ≤ 15 ✅ |
| 多图融合 + 序列 | 10 | 6 | 6 | 16 > 15 ❌ 报错 |
多轮迭代:把上一次的输出 URL 作为下一次的
image 输入,配合新的编辑指令逐步精调。每一轮都按张计费,预算时留意累计成本。5.5 图层拆分与文字 OCR
seedream-5-5-261028 可把一张 PNG/JPEG 成品图拆成 1 张底图 + 最多 99 个独立图层。max_images 控制底图与图层的总上限(2–100,默认 30),实际数量由画面复杂度和拆分指令决定。
curl -X POST "https://api.apiyi.com/v1/images/generations" \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "seedream-5-5-261028",
"prompt": "把每个独立主体拆成完整图层,其余内容留在底图中",
"image": "https://your-oss.example.com/poster.jpg",
"layer_decomposition": true,
"layer_decomposition_options": {
"max_images": 3,
"text_recognition": true
},
"size": "1K",
"output_format": "png",
"response_format": "url",
"watermark": false
}'
- 上述上限设置为 3 时,实际返回 2 张:
z_index=0底图和z_index=1人物图层,均为1024×1024PNG - 图层带有
name、description和bounding_box;常规文字图层还可带text_recognition usage.input_images = 1、usage.generated_images = 2,约 13.5 秒返回- 实际扣费 $0.048:2 张输出 × $0.020 + 1 张输入 × $0.008
图层拆分时不要传
background。output_format 只控制底图,独立图层始终为 PNG。OCR 仅覆盖常规文字图层,字体与样式是近似识别;艺术字、手写文字、底图和非文字图层不保证返回 OCR 字段。5.0 Flash 分层(透明图层)
seedream-5-0-flash-260915 支持把一张成品图拆成背景底图 + 多个独立元素的透明图层,适合二次排版、换背景、素材复用。直接在提示词里要求透明背景是拿不到 alpha 通道的,透明素材要走这个方式。
curl -X POST "https://api.apiyi.com/v1/images/generations" \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "seedream-5-0-flash-260915",
"prompt": "把图片拆分为背景和各个独立元素的图层",
"image": ["https://your-oss.example.com/poster.jpg"],
"layer_decomposition": true,
"size": "1K",
"output_format": "png",
"response_format": "url",
"watermark": false
}'
- 传 1 张参考图,返回
data数组共 12 张:第 1 张是抠掉元素后补全的背景底图(文件名以_base.png结尾,RGB),其余 11 张是 RGBA 透明图层(_layer_1.png起),每层只含一个元素、尺寸按元素裁切 - 1K 一次约 78 秒;同样的请求用 2K 实测 15 分钟都没拿到结果,但账单照常扣了 12 张的 $0.216。请用
1K,并把客户端超时设到 300 秒以上 - 分层可能失败:同一张图有一次在约 60 秒后返回 400(
the image content could not be processed for layer decomposition),失败不扣费,重试即可 - 底图里被移走的区域是模型补画的内容,用于商用前请人工检查
分层按输出张数计费:返回几张就计几次 $0.018。实测一次返回 12 张,扣费 $0.216(
usage.generated_images 为 12)。图层数量由画面内容决定,无法事先指定,同一张图两次分层也可能不同(实测同一张图先后拆出 12 张和 14 张,分别扣 $0.216 和 $0.252),预算时按十几张估算。响应格式
以下是 5.5 图层拆分返回 2 张图片时的结构示例:{
"model": "dola-seedream-5-5-261028",
"created": 1784696685,
"data": [
{
"url": "https://.../base.png",
"size": "1024x1024",
"output_format": "png",
"z_index": 0
},
{
"url": "https://.../layer-1.png",
"size": "1024x1024",
"output_format": "png",
"z_index": 1,
"name": "Young woman in white cheongsam",
"description": "A young woman wearing a white cheongsam.",
"bounding_box": {
"absolute": [0, 0, 1024, 1024],
"normalized": [0, 0, 1000, 1000]
}
}
],
"usage": {
"input_images": 1,
"generated_images": 2,
"output_tokens": 8192,
"total_tokens": 8192
}
}
⚠️
data 数组长度反映实际输出张数- 普通编辑返回 1 个元素;早期版本的批量序列与 5.5 图层拆分可返回多个元素
- 计费按
usage.generated_images实际张数算,不是按max_images - 常规文字图层的
text_recognition还包括完整文本、lines[].bounding_box、runs[].text与近似样式
Seedream 5.5 的输出图片按尺寸档位计费,输入参考图另收 $0.008/张;其他版本是否收输入图费用以 总览定价 为准。
请求体
application/json
此页面对您有帮助吗?