DOC 10接口与能力
Seedream 5.5 生图接入教程
用 Seedream 5.5 出图:一条命令跑通,再看尺寸与比例、参考图、透明背景、图层拆分和计费。
Seedream 5.5 是字节跳动的生图模型,在本站走「Seedream 生图」分组,按张计费。先用一条命令出第一张图,再看尺寸、参考图、透明背景和图层拆分怎么写。
准备
- 打开密钥页创建密钥,分组选「Seedream 生图」。其他分组的密钥调不了这个模型。
- 模型名写
seedream-5-5,每个请求都要带上。 - 接口地址是
https://api.spiderai.fun,请求头带Authorization: Bearer 你的密钥。
| 入口 | 路径 | 什么时候用 |
|---|---|---|
| 通用入口 | POST /v1/images/generations | 大多数情况用它:尺寸可以按比例写,参考图用链接传,现成的生图工具也填这个地址。 |
| 上传本地图片 | POST /v1/images/edits | 参考图在自己电脑上时,用表单直接上传。 |
| 异步提交 | POST /v1/images/generations/async | 慢的请求用它:马上返回任务号,稍后再取结果。 |
| 火山方舟原生 | POST /api/v3/images/generations | 参数和返回与火山方舟官方文档一致,已有官方代码时只改地址和密钥。 |
第一张图
把 YOUR_API_KEY 换成你的密钥。出一张图一般要 10 秒左右,客户端超时建议设到 180 秒。
curl https://api.spiderai.fun/v1/images/generations \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "seedream-5-5",
"prompt": "一只橘猫趴在窗台上晒太阳,胶片质感,暖色调",
"size": "1920x1080"
}'import json, urllib.request
API_KEY = "YOUR_API_KEY"
body = {
"model": "seedream-5-5",
"prompt": "一只橘猫趴在窗台上晒太阳,胶片质感,暖色调",
"size": "1920x1080",
}
req = urllib.request.Request(
"https://api.spiderai.fun/v1/images/generations",
data=json.dumps(body).encode("utf-8"),
headers={"Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json"},
)
with urllib.request.urlopen(req, timeout=180) as resp:
result = json.load(resp)
image = result["data"][0]
print(image["size"], result["usage"])
urllib.request.urlretrieve(image["url"], "seedream.png") # 链接是临时的,拿到就存下来
print("saved seedream.png")import { writeFile } from "node:fs/promises";
const API_KEY = "YOUR_API_KEY";
const res = await fetch("https://api.spiderai.fun/v1/images/generations", {
method: "POST",
headers: { Authorization: `Bearer ${API_KEY}`, "Content-Type": "application/json" },
body: JSON.stringify({
model: "seedream-5-5",
prompt: "一只橘猫趴在窗台上晒太阳,胶片质感,暖色调",
size: "1920x1080",
}),
signal: AbortSignal.timeout(180_000),
});
const result = await res.json();
if (!res.ok) throw new Error(JSON.stringify(result));
const image = result.data[0];
console.log(image.size, result.usage);
// 链接是临时的,拿到就存下来
await writeFile("seedream.png", Buffer.from(await (await fetch(image.url)).arrayBuffer()));
console.log("saved seedream.png");返回里 data[0].url 是图片地址,data[0].size 是实际出图的宽 × 高,usage 是这次计费用到的张数:
{
"model": "doubao-seedream-5-5-261028",
"created": 1796042673,
"data": [
{ "url": "https://…/….png?…", "size": "1920x1080", "output_format": "png", "background": "opaque" }
],
"usage": { "input_images": 0, "generated_images": 1, "output_tokens": 8100, "total_tokens": 8100 }
}尺寸怎么写
- 写精确像素:
"size": "1920x1080"。宽 × 高要在 921,600 到 8,294,400 像素之间,长宽比不超过 16:1。 - 写比例加档位(通用入口):
"size": "16:9"加"resolution": "1.5K",会按下表换成像素;不写resolution时按 2K。 - 不写
size:出 2048×2048 的图。
| 比例 | 1K | 1.5K | 2K | 3K |
|---|---|---|---|---|
| 1:1 | 1024x1024 | 1536x1536 | 2048x2048 | 2880x2880 |
| 16:9 | 1280x720 | 1920x1080 | 2560x1440 | 3840x2160 |
| 9:16 | 720x1280 | 1080x1920 | 1440x2560 | 2160x3840 |
| 4:3 | 1152x864 | 1728x1296 | 2304x1728 | 3200x2400 |
| 3:4 | 864x1152 | 1296x1728 | 1728x2304 | 2400x3200 |
| 3:2 | 1248x832 | 1920x1280 | 2496x1664 | 3456x2304 |
| 2:3 | 832x1248 | 1280x1920 | 1664x2496 | 2304x3456 |
| 21:9 | 1512x648 | 2268x972 | 3024x1296 | 4200x1800 |
| 2:1 | 1440x720 | 2048x1024 | 2880x1440 | 4000x2000 |
| 1:2 | 720x1440 | 1024x2048 | 1440x2880 | 2000x4000 |
价格只看出图的实际像素落在哪一档,和怎么写尺寸无关。模型价格的「图片模型」里可以选比例和档位,直接看要传的 size 和这一张的价格。
带参考图
一次最多带 10 张参考图,可以改图,也可以把几张图融合成一张。参考图按张另外计费。
import json, urllib.request
API_KEY = "YOUR_API_KEY"
body = {
"model": "seedream-5-5",
"prompt": "把图 1 的背景换成图 2 的图案,主体保持不变",
"image": ["https://spiderai.fun/og.png", "https://spiderai.fun/logo.png"], # 1 到 10 张,按顺序就是图 1、图 2 …
"size": "16:9",
"resolution": "1.5K",
}
req = urllib.request.Request(
"https://api.spiderai.fun/v1/images/generations",
data=json.dumps(body).encode("utf-8"),
headers={"Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json"},
)
with urllib.request.urlopen(req, timeout=180) as resp:
result = json.load(resp)
print(result["data"][0]["url"])
print(result["usage"]) # input_images = 这次计费的参考图张数const API_KEY = "YOUR_API_KEY";
const res = await fetch("https://api.spiderai.fun/v1/images/generations", {
method: "POST",
headers: { Authorization: `Bearer ${API_KEY}`, "Content-Type": "application/json" },
body: JSON.stringify({
model: "seedream-5-5",
prompt: "把图 1 的背景换成图 2 的图案,主体保持不变",
image: ["https://spiderai.fun/og.png", "https://spiderai.fun/logo.png"], // 1 到 10 张,按顺序就是图 1、图 2 …
size: "16:9",
resolution: "1.5K",
}),
signal: AbortSignal.timeout(180_000),
});
const result = await res.json();
if (!res.ok) throw new Error(JSON.stringify(result));
console.log(result.data[0].url);
console.log(result.usage); // input_images = 这次计费的参考图张数curl https://api.spiderai.fun/v1/images/edits \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "model=seedream-5-5" \
-F "prompt=把背景改成浅蓝色,主体和文字保持不变" \
-F "size=1K" \
-F "image=@photo.png"import { readFile } from "node:fs/promises";
const API_KEY = "YOUR_API_KEY";
const form = new FormData();
form.append("model", "seedream-5-5");
form.append("prompt", "把背景改成浅蓝色,主体和文字保持不变");
form.append("size", "1K");
form.append("image", new Blob([await readFile("photo.png")], { type: "image/png" }), "photo.png");
const res = await fetch("https://api.spiderai.fun/v1/images/edits", {
method: "POST",
headers: { Authorization: `Bearer ${API_KEY}` },
body: form,
signal: AbortSignal.timeout(180_000),
});
const result = await res.json();
if (!res.ok) throw new Error(JSON.stringify(result));
console.log(result.data[0].url);多张图就重复写 image 字段。图片用 PNG 或 JPEG。
透明背景
加上 "background": "transparent" 和 "output_format": "png",直接得到带透明通道的 PNG,不用再抠图。
curl https://api.spiderai.fun/v1/images/generations \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "seedream-5-5",
"prompt": "一枚玻璃质感的蓝色小狐狸徽章,白色细描边,独立主体",
"size": "1024x1024",
"background": "transparent",
"output_format": "png"
}'图层拆分
传 1 张海报或设计稿,打开 layer_decomposition,返回一张补全了空缺的底图和若干张透明图层,每个图层带名称、说明和位置。
curl https://api.spiderai.fun/v1/images/generations \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "seedream-5-5",
"image": "https://spiderai.fun/og.png",
"layer_decomposition": true,
"layer_decomposition_options": { "max_images": 4 }
}'- 按返回的图片张数计费:底图和每个图层各算一张,再加 1 张参考图。用
max_images(2 到 100,默认 30)限制最多返回几张,费用也就封了顶。 - 只能传 1 张图;
size只能不写或写1K、1.5K、2K;不能同时写background。 - 图层位置在
bounding_box.absolute里,四个数是左、上、右、下的像素坐标,贴回底图时直接用。
异步提交
图层拆分这类耗时长的请求可以改成异步:提交后马上拿到任务号,过一会儿凭任务号取结果,不用一直保持连接。请求体和同步接口完全一样,只是地址后面多一个 /async。
curl https://api.spiderai.fun/v1/images/generations/async \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "seedream-5-5",
"image": "https://spiderai.fun/og.png",
"layer_decomposition": true,
"layer_decomposition_options": { "max_images": 4 }
}'马上返回 HTTP 202 和一个 task_id:
{
"object": "image.generation.task",
"task_id": "imgtask_d0049e2bb7364a4baa70d0e71ac42fcb",
"status": "processing",
"poll_url": "/v1/images/tasks/imgtask_d0049e2bb7364a4baa70d0e71ac42fcb",
"created_at": 1796046134,
"expires_at": 1796132534
}然后用同一把密钥查询结果(下面的返回只列出了前两张图):
curl https://api.spiderai.fun/v1/images/tasks/imgtask_d0049e2bb7364a4baa70d0e71ac42fcb \
-H "Authorization: Bearer YOUR_API_KEY"{
"object": "image.generation.task",
"task_id": "imgtask_d0049e2bb7364a4baa70d0e71ac42fcb",
"status": "completed",
"http_status": 200,
"image_url": "https://…/….png?…",
"result": {
"model": "doubao-seedream-5-5-261028",
"data": [
{ "url": "https://…/….png?…", "size": "1413x742", "z_index": 0, "background": "opaque" },
{ "url": "https://…/….png?…", "size": "1033x1015", "z_index": 1, "background": "transparent", "name": "…",
"bounding_box": { "absolute": [101, 165, 513, 570], "normalized": [71, 222, 363, 768] } }
],
"usage": { "input_images": 1, "generated_images": 4 }
},
"created_at": 1796046134,
"completed_at": 1796046152,
"expires_at": 1796132552
}status是processing时,每隔 3 秒左右再查一次;变成completed后,result里就是和同步接口一样的返回。failed表示请求失败,失败的任务不扣费。- 查询要用提交任务的那把密钥,别的密钥查不到。
- 任务结果保留 24 小时。
- 要异步上传本地图片,用
POST /v1/images/edits/async。 - 异步和同步价格相同。GPT 和 Grok 的图片模型也可以这样提交。
已经有火山方舟的代码
原生入口不改写参数:请求体照官方文档写,地址换成本站的,密钥换成本站的。这个入口的 size 写精确像素,或 1K、1.5K、2K。
curl https://api.spiderai.fun/api/v3/images/generations \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "seedream-5-5",
"prompt": "一只橘猫趴在窗台上晒太阳,胶片质感,暖色调",
"size": "2K"
}'怎么计费
- 出图按张收费,价格看这张图的宽 × 高落在哪一档(1K、1.5K、2K、3K)。
- 参考图按张收费,带几张收几张。
- 提示词不另外收费。
- 各档单价见模型价格的「图片模型」。
常见报错
| 返回信息 | 原因和处理 |
|---|---|
No available Seedream accounts | 没写 model,或模型名不是 seedream-5-5。 |
… only supported for seedream groups | 用了别的分组的密钥调原生入口。换成「Seedream 生图」分组的密钥。 |
… requires total pixels within [921600, 8294400] | 尺寸太小或太大,按上面的表选一个。 |
… does not support n > 1 … | 一次请求出一张图,要多张就多发几次请求。 |
… cannot combine background=transparent with output_format=jpeg | 透明背景只能配 PNG。 |
… layer_decomposition=true requires exactly 1 input image | 图层拆分只能传 1 张图。 |
image task not found | 任务号不对、已超过 24 小时,或查询用的不是提交时的那把密钥。 |
余额不足、密钥无效这类通用报错见故障手册。