本文档为 V3 原生协议(snake_case 请求体 + 扁平响应,同步返回图片)。本模型同时提供 V2 风格接口 POST /api/v2/open/aigc/seedream-5.0-flash(camelCase + 轮询查询),两者共享同一套任务与计费体系,可按客户端习惯任选其一;新接入建议直接用本文档的 V3 协议。概述
Seedream 5.0 Flash 是 Seedream 系列的高速档,支持文生图(text-to-image)和图生图(image-to-image),并支持把一张图拆成底图 + 多个透明图层。请求与响应字段均为 snake_case。
特性:
- ⚡ 同步返回:请求阻塞至出图完成,直接返回图片,无需轮询
- 🖼️ 多种生成方式:文生图、单图生图、多图参考生图(最多 10 张参考图)
- 🧩 图层拆分:把一张图拆成底图 + 多个可独立编辑的透明图层
- 🎯 三档分辨率同价:1K / 1.5K / 2K 统一单价,按需选档不影响计费
- 🇨🇳 国内专线:专为国内用户优化的访问速度
Base URL: https://mm-internal-cn.leonecloud.com(国内专线)
认证方式
所有接口均需要在请求头中携带 Token 进行认证:
Authorization: Bearer {YOUR_AUTH_TOKEN}认证失败时返回 HTTP 401:
{
"error": {
"code": "AuthenticationError",
"message": "API Key 无效",
"type": "Unauthorized"
}
}model 取值
model 为必填字段,本文档对应的取值为:
| model | 说明 | 参考图上限 | size 分辨率档 | size 默认值 | 图层拆分 | 流式输出 |
|---|---|---|---|---|---|---|
seedream-5-0-flash | 高速、三档同价 | 10 张 | 1K / 1.5K / 2K | 2K | ✅ | ❌ |
传入不在上表中的 model 会返回 HTTP 400 InvalidParameter。其余 Seedream 模型见 Seedream 5.0 Pro、Seedream 5.0 Lite、Seedream 4.5,用法相同,只需更换 model。
接口:图片生成
POST /api/v3/images/generations
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| model | string | 是 | 固定取值 seedream-5-0-flash |
| prompt | string | 是* | 提示词。建议中文不超过 300 字、英文不超过 600 词。*图层拆分模式下可选 |
| image | string / string[] | 否 | 参考图。单张传字符串、多张传数组,最多 10 张;支持图片 URL 或 Base64(格式 data:image/png;base64,<数据>,图片格式需小写)。单张不超过 30MB |
| size | string | 否 | 输出尺寸,见 size 说明 |
| layer_decomposition | boolean | 否 | 图层拆分开关,默认 false,见 图层拆分 |
| response_format | string | 否 | 返回格式:url(默认)/ b64_json |
| output_format | string | 否 | png / jpeg。可传,当前不影响输出格式,实际格式以响应为准 |
| watermark | boolean | 否 | 可传,当前不影响输出 |
| background | string | 否 | 仅支持 opaque(默认);transparent 暂不支持,传入返回 400 |
本模型不支持的参数(传入会返回 400,不会静默忽略):
-sequential_image_generation: auto(组图生成):仅 Seedream 5.0 Lite、Seedream 4.5 支持;
-stream: true(流式输出):仅 Seedream 5.0 Lite、Seedream 4.5 支持。optimize_prompt_options、tools、seed等字段可原样传入,不会报错,也不影响出图。
size 说明
支持两种写法,二选一:
方式 1:分辨率档(1K / 1.5K / 2K,默认 2K,大小写不敏感)
- 输出宽高比固定为 1:1。
- 需要指定宽高比时,请使用方式 2。
- 三档统一单价,选高档不额外计费。
方式 2:宽高像素值(宽x高,如 2560x1440)
| 总像素范围 | 宽高比范围 |
|---|---|
| [921600, 4624220] | [1/16, 16] |
像素值会归到最接近的分辨率档,并取最接近的标准宽高比(1:1 / 4:3 / 3:4 / 16:9 / 9:16 / 3:2 / 2:3 / 21:9)出图,不保证逐像素一致,实际尺寸以响应中的 size 为准。各档常用像素值:
| 宽高比 | 1K | 1.5K | 2K |
|---|---|---|---|
| 1:1 | 1024x1024 | 1536x1536 | 2048x2048 |
| 4:3 | 1152x864 | 1728x1296 | 2304x1728 |
| 3:4 | 864x1152 | 1296x1728 | 1728x2304 |
| 16:9 | 1280x720 | 1920x1080 | 2560x1440 |
| 9:16 | 720x1280 | 1080x1920 | 1440x2560 |
| 3:2 | 1248x832 | 1872x1248 | 2496x1664 |
| 2:3 | 832x1248 | 1248x1872 | 1664x2496 |
| 21:9 | 1512x648 | 2268x972 | 3024x1296 |
图层拆分
把一张图拆解为 1 张底图 + 多个可独立编辑的透明图层(PNG)。
layer_decomposition传true;image必须且仅支持 1 张;prompt可选:不传时自动识别图中主要元素逐个拆分,也可用自然语言说明要拆分哪些元素;size仅支持1K/1.5K/2K/auto(默认auto,按2K输出),不支持宽高像素值;- 按实际输出的图片张数计费(底图 + 图层总数):创建时预冻结额度,完成后按实际用量多退少补。
响应 data 中每一项为一个图层:底图 z_index 为 0,图层从 1 递增(越大越靠上);除底图外还会返回 bounding_box、name、description,见 响应参数。
支持的使用场景
场景1:文生图
curl -X POST "https://mm-internal-cn.leonecloud.com/api/v3/images/generations" \
-H "Authorization: Bearer your_auth_token_here" \
-H "Content-Type: application/json" \
-d '{
"model": "seedream-5-0-flash",
"prompt": "一只橘猫坐在窗台上看雨,水彩风格",
"size": "2K"
}'指定宽高比(16:9):
curl -X POST "https://mm-internal-cn.leonecloud.com/api/v3/images/generations" \
-H "Authorization: Bearer your_auth_token_here" \
-H "Content-Type: application/json" \
-d '{
"model": "seedream-5-0-flash",
"prompt": "充满活力的特写编辑肖像,色彩拼接丰富,杂志封面风格,工作室灯光",
"size": "2560x1440"
}'场景2:图生图
curl -X POST "https://mm-internal-cn.leonecloud.com/api/v3/images/generations" \
-H "Authorization: Bearer your_auth_token_here" \
-H "Content-Type: application/json" \
-d '{
"model": "seedream-5-0-flash",
"prompt": "保持人物姿势不变,把服装材质改为透明的玻璃",
"image": "https://example.com/input.png",
"size": "2K"
}'场景3:多图参考生图
curl -X POST "https://mm-internal-cn.leonecloud.com/api/v3/images/generations" \
-H "Authorization: Bearer your_auth_token_here" \
-H "Content-Type: application/json" \
-d '{
"model": "seedream-5-0-flash",
"prompt": "将图1的服装换为图2的服装",
"image": [
"https://example.com/person.png",
"https://example.com/clothes.png"
],
"size": "2K"
}'场景4:图层拆分
curl -X POST "https://mm-internal-cn.leonecloud.com/api/v3/images/generations" \
-H "Authorization: Bearer your_auth_token_here" \
-H "Content-Type: application/json" \
-d '{
"model": "seedream-5-0-flash",
"prompt": "把桌面上的物品拆分成独立图层",
"image": "https://example.com/poster.png",
"layer_decomposition": true,
"size": "2K"
}'场景5:Python(OpenAI SDK)
V3 协议与 OpenAI SDK 的图片接口兼容,base_url 填 https://mm-internal-cn.leonecloud.com/api/v3 即可,非标准字段放 extra_body:
from openai import OpenAI
client = OpenAI(
base_url="https://mm-internal-cn.leonecloud.com/api/v3",
api_key="your_auth_token_here",
)
resp = client.images.generate(
model="seedream-5-0-flash",
prompt="一只橘猫坐在窗台上看雨,水彩风格",
size="2K",
response_format="url",
extra_body={
"image": "https://example.com/input.png",
},
)
print(resp.data[0].url)响应参数
成功响应(HTTP 200)
{
"model": "seedream-5-0-flash",
"created": 1792235741,
"data": [
{
"url": "https://.../task_20261111191541_lwqp1vgb_0.jpeg",
"size": "2048x2048",
"output_format": "jpeg"
}
],
"usage": {
"generated_images": 1,
"input_images": 0,
"output_tokens": 16384,
"total_tokens": 16384
}
}图层拆分响应:
{
"model": "seedream-5-0-flash",
"created": 1792235741,
"data": [
{
"url": "https://.../layer_0.jpeg",
"size": "2048x2048",
"output_format": "jpeg",
"z_index": 0
},
{
"url": "https://.../layer_1.png",
"size": "1981x924",
"output_format": "png",
"z_index": 1,
"bounding_box": {
"absolute": [33, 561, 2014, 1485],
"normalized": [16, 274, 983, 725]
},
"name": "红色精装笔记本",
"description": "摊放在木桌上的红色硬壳笔记本"
}
],
"usage": {
"generated_images": 5,
"input_images": 1,
"output_tokens": 79476,
"total_tokens": 79476
}
}| 参数 | 类型 | 说明 |
|---|---|---|
| model | string | 回显请求中的 model |
| created | integer | 任务创建时间(Unix 秒) |
| data[].url | string | 图片 URL(response_format=url 时返回),请及时下载保存 |
| data[].b64_json | string | 图片 Base64(response_format=b64_json 时返回) |
| data[].size | string | 图片宽高,如 2048x2048 |
| data[].output_format | string | 图片格式,如 jpeg;图层拆分时底图为 jpeg、各图层为 png |
| data[].z_index | integer | 图层叠放顺序(仅图层拆分):底图为 0,越大越靠上 |
| data[].bounding_box.absolute | int[] | 图层在底图中的像素坐标 [left, top, right, bottom](仅图层,底图不返回) |
| data[].bounding_box.normalized | int[] | 归一化坐标 [left, top, right, bottom],取值 0 ~ 1000 |
| data[].name | string | 图层名称(仅图层) |
| data[].description | string | 图层描述(仅图层) |
| usage.generated_images | integer | 生成的图片张数(图层拆分时为底图 + 图层总数,即计费张数) |
| usage.input_images | integer | 本次传入的参考图张数 |
| usage.output_tokens | integer | sum(宽 × 高) / 256 取整 |
| usage.total_tokens | integer | 与 output_tokens 相同 |
图片 URL 的域名可能随调度变化,请以响应中的实际地址为准,不要在代码里硬编码域名。
响应头 X-Task-Id 为本次请求对应的任务 ID,排查问题时请提供。
还原图层:将图层缩放至 (right - left) × (bottom - top),放到底图的 (left, top) 位置,多个图层按 z_index 从小到大依次叠放。还原到自定义画布(宽 W、高 H)时用 normalized:x = left / 1000 × W,y = top / 1000 × H。
超时
请求最长阻塞 10 分钟。超时返回 HTTP 504,任务仍会继续执行并正常计费,可凭 message 中的任务 ID(或响应头 X-Task-Id)调用 GET /v1/images/generations/{taskId} 查询结果,返回结构同 图片生成 API(统一入口) 的查询任务接口:
{
"error": {
"code": "RequestTimeout",
"message": "图片生成超时,任务仍在处理中,请用 GET /v1/images/generations/task_xxx 查询结果",
"type": "GatewayTimeout"
}
}错误码
失败时返回真实 HTTP 状态码 + 扁平 error 对象:
{
"error": {
"code": "InvalidParameter",
"message": "size 总像素需在 [921600, 4624220] 之间,当前 640x480",
"type": "BadRequest"
}
}| HTTP 状态码 | error.code | 说明 |
|---|---|---|
| 400 | InvalidParameter | 参数错误(缺少 prompt、size 取值无效、模型不支持的参数等) |
| 400 | SensitiveContentDetected 等 | 输入或输出内容审核未通过,请更换提示词或参考图 |
| 401 | AuthenticationError | API Key 无效或缺失 |
| 402 | InsufficientBalance | 余额不足 |
| 403 | PermissionDenied | 无权限 |
| 404 | ModelNotOpen | 模型暂未开放 |
| 413 | InvalidParameter | 请求体过大 |
| 500 | InternalServiceError | 图片生成失败,可重试 |
| 504 | RequestTimeout | 生成超时,任务仍在处理,见 超时 |
从 V2 迁移
| 维度 | V2 | V3(本文档) |
|---|---|---|
| 创建路径 | POST /api/v2/open/aigc/seedream-5.0-flash,路径即模型 | 统一 POST /api/v3/images/generations,模型由 model 指定 |
| 调用方式 | 创建任务后轮询查询 | 同步阻塞,直接返回图片 |
| 字段命名 | camelCase(imageUrls、aspectRatio) | snake_case(image、size) |
| 生成类型 | genType(t2i / i2i / t2i-layer / i2i-layer) | 由是否传 image 决定;图层拆分传 layer_decomposition: true |
| 尺寸参数 | aspectRatio + resolution(1K / 1.5K / 2K) | 合并为 size,见 size 说明 |
| 创建响应 | {code, msg, data} 信封 | 扁平对象,直接带 data[].url |
| 错误响应 | 信封内错误码(code: 40001) | 真实 HTTP 状态码 + {"error": {...}} |
| 回调通知 | callbackUrl | 同步返回,无需回调 |
V2 接口继续可用,两者共享同一套任务与计费体系。V2 的 resolution 取值与本文的分辨率档一致(1K / 1.5K / 2K,默认 2K)。
最佳实践
- 设置足够的超时:出图通常 10 ~ 60 秒,客户端读超时建议不低于 120 秒;高分辨率、多参考图耗时更长。
- 按需选档不加价:三档统一单价,默认
2K;只在需要更小产物(如列表缩略图)时降到1K,不必为省钱压档。 - 需要固定宽高比用像素值:分辨率档模式下输出固定 1:1,见 size 说明。
- 图层拆分按张数计费:一次请求产出底图 + 多个图层,计费张数以
usage.generated_images为准;只需要整图时不要开layer_decomposition。 - 及时转存结果:返回的图片 URL 请及时下载保存,避免长期依赖临时链接。
- 参考图优先用 URL:Base64 会显著增大请求体,多张大图时更容易超出请求体上限。