# Seedream 5.5 图片生成 API 对接文档

> 本文档为 **V3 原生协议**（snake_case 请求体 + 扁平响应，同步返回图片）。本模型同时提供 V2 风格接口 `POST /api/v2/open/aigc/seedream-5.5`（camelCase + 轮询查询），两者共享同一套任务与计费体系，可按客户端习惯任选其一；新接入建议直接用本文档的 V3 协议。

## 概述

Seedream 5.5 是 Seedream 系列的最新档，支持文生图（text-to-image）和图生图（image-to-image）。相比 5.0 档新增三项能力：**原生透明通道**（直接出 RGBA 图）、**图层拆分最多 99 个图层**、**富文本 OCR**（识别规整文字的内容与样式）。请求与响应字段均为 snake_case。

**特性**：
- ⚡ **同步返回**：请求阻塞至出图完成，直接返回图片，无需轮询
- 🖼️ **多种生成方式**：文生图、单图生图、多图参考生图（最多 10 张参考图）
- 🫥 **原生透明通道**：文生图与图生图都能直接输出带透明通道的 RGBA 图
- 🧩 **图层拆分**：把一张图拆成底图 + 最多 99 个可独立编辑的透明图层，可控制输出总数
- 🔤 **富文本 OCR**：图层拆分时返回规整文字的文本内容与样式（字体、颜色、加粗、斜体等）
- 🇨🇳 **国内专线**：专为国内用户优化的访问速度

**Base URL**: `https://mm-internal-cn.leonecloud.com`（国内专线）

---

## 认证方式

所有接口均需要在请求头中携带 Token 进行认证：

```
Authorization: Bearer {YOUR_AUTH_TOKEN}
```

认证失败时返回 HTTP 401：

```json
{
  "error": {
    "code": "AuthenticationError",
    "message": "API Key 无效",
    "type": "Unauthorized"
  }
}
```

---

## model 取值

`model` 为**必填**字段，本文档对应的取值为：

| model | 说明 | 参考图上限 | size 分辨率档 | size 默认值 | 图层拆分 | 透明通道 | 流式输出 |
|-------|------|-----------|--------------|------------|---------|---------|---------|
| `seedream-5-5` | 最新档，支持透明通道与富文本 OCR | 10 张 | `1K` / `1.5K` / `2K` | `2K` | ✅ 最多 99 层 | ✅ | ❌ |

传入不在上表中的 `model` 会返回 HTTP 400 `InvalidParameter`。其余 Seedream 模型见 [Seedream 5.0 Pro](/docs/seedream-5-0-pro)、[Seedream 5.0 Flash](/docs/seedream-5-0-flash)、[Seedream 5.0 Lite](/docs/seedream-5-0-lite)、[Seedream 4.5](/docs/seedream-4-5)，用法相同，只需更换 `model`。

---

## 接口：图片生成

**POST** `/api/v3/images/generations`

### 请求参数

| 参数 | 类型 | 必填 | 说明 |
|-----|------|-----|------|
| model | string | 是 | 固定取值 `seedream-5-5` |
| prompt | string | 是* | 提示词。支持中英文，另支持俄语、阿拉伯语、菲律宾语、泰语、土耳其语、韩语、马来语、西班牙语、葡萄牙语、印尼语、法语、德语、越南语、日语。建议中文不超过 300 字、英文不超过 600 词；过长模型可能忽略细节。*图层拆分模式下可选 |
| image | string / string[] | 否 | 参考图。单张传字符串、多张传数组，最多 10 张；支持图片 URL 或 Base64（格式 `data:image/png;base64,<数据>`，图片格式需小写）。单张不超过 30MB |
| size | string | 否 | 输出尺寸，见 [size 说明](#size-说明) |
| layer_decomposition | boolean | 否 | 图层拆分开关，默认 `false`，见 [图层拆分](#图层拆分) |
| layer_decomposition_options | object | 否 | 图层拆分配置，仅 `layer_decomposition=true` 时生效，见 [图层拆分](#图层拆分) |
| background | string | 否 | 透明通道模式：`auto`（默认）/ `transparent` / `opaque`，见 [透明通道](#透明通道) |
| output_format | string | 否 | `png`（默认）/ `jpeg`。与 `background=transparent` 互斥，同传返回 400 |
| response_format | string | 否 | 返回格式：`url`（默认）/ `b64_json` |
| optimize_prompt_options | object | 否 | 提示词优化配置。`mode` 仅支持 `standard`（默认行为），传其他值不生效 |
| safety_identifier | string | 否 | 终端用户标识，英文字符串、不超过 64 字符。接口会在响应中原样回显。建议传用户名/ID/邮箱的哈希值，避免泄露用户隐私 |
| watermark | boolean | 否 | 可传，但本平台的输出图**恒不添加水印** |

> **本模型不支持的参数**（传入会返回 400，不会静默忽略）：
> - `sequential_image_generation: auto`（组图生成）：仅 [Seedream 5.0 Lite](/docs/seedream-5-0-lite)、[Seedream 4.5](/docs/seedream-4-5) 支持；
> - `stream: true`（流式输出）：仅 Seedream 5.0 Lite、Seedream 4.5 支持。
>
> `tools`（联网搜索，仅 [Seedream 5.0 Lite](/docs/seedream-5-0-lite) 支持）与 `seed` 可原样传入，不会报错，但不会下发、不影响出图。

### size 说明

支持两种写法，二选一：

**方式 1：分辨率档**（`1K` / `1.5K` / `2K`，默认 `2K`，大小写不敏感）

- 宽高比由模型按提示词判断：在 `prompt` 里用自然语言说明（如「16:9 宽幅横版」）即可，实测 `size: "2K"` + 该提示词输出 `2816x1584`。
- 需要精确控制宽高时请用方式 2。
- `1K` 与 `1.5K` **同一计费档**，`2K` 单独一档，见 [计费说明](#计费说明)。

**方式 2：宽高像素值**（`宽x高`，如 `2880x1440`）

| 总像素范围 | 宽高比范围 |
|-----------|-----------|
| [921600, 4624220] | [1/16, 16] |

两项限制需**同时**满足。总像素是宽高相乘的结果，不是对宽或高的单独限制：

- 有效示例 `2880x1440`：总像素 4147200 在区间内，宽高比 2 在区间内。
- 无效示例 `512x512`：总像素 262144 未达下限 921600，返回 400。

像素值按传入值原样出图（如传 `2880x1440` 则输出 `2880x1440`），实际尺寸以响应中的 `size` 为准。计费按该尺寸的总像素落档，见 [计费说明](#计费说明)。

方式 1 的分辨率档对应的常用像素值如下，可作为选档参考（模型实际映射不限于这些标准值）：

| 宽高比 | 1K | 1.5K | 2K |
|-------|----|------|----|
| 1:1 | 1024x1024 | 1536x1536 | 2048x2048 |
| 4:3 | 1152x864 | 1792x1344 | 2368x1776 |
| 3:4 | 864x1152 | 1344x1792 | 1776x2368 |
| 16:9 | 1424x800 | 2048x1152 | 2816x1584 |
| 9:16 | 800x1424 | 1152x2048 | 1584x2816 |
| 3:2 | 1248x832 | 1872x1248 | 2496x1664 |
| 2:3 | 832x1248 | 1248x1872 | 1664x2496 |
| 21:9 | 1568x672 | 2352x1008 | 3136x1344 |

### 透明通道

`background` 控制输出图是否带 Alpha 通道：

| 取值 | 说明 |
|-----|------|
| `auto`（默认） | 由模型根据提示词与 `output_format` 自行判断 |
| `transparent` | 输出带透明通道的 RGBA 图 |
| `opaque` | 输出不带透明通道的 RGB 图 |

- 文生图与图生图**都支持** `transparent`，图生图时参考图无需自带透明通道。
- `output_format=jpeg` 与 `background=transparent` 不能同时使用（JPEG 没有 Alpha 通道），同传返回 400。
- 图层拆分模式下不支持本参数，传入返回 400（各图层本身就是透明 PNG）。
- 响应 `data[].background` 回显实际的透明度类型，可能与请求值不同（如 `auto` 下模型判定为不透明则返回 `opaque`）。

### 图层拆分

把一张图拆解为 1 张底图 + 多个可独立编辑的透明图层（PNG）。

- `layer_decomposition` 传 `true`；
- `image` **必须且仅支持 1 张**，且要求比普通场景更严：格式仅 `png` / `jpeg`，总像素需在 [`512×512`（262144）, `6000×6000`（36M）] 之间，宽高比 [1/16, 16]，大小不超过 30MB；
- `prompt` 可选：不传时自动识别图中主要元素逐个拆分，也可用自然语言说明要拆分哪些元素；
- `size` 仅支持 `1K` / `1.5K` / `2K` / `auto`（默认 `auto`：底图与各图层按原图尺寸输出，夹在 1K ~ 2K 之间），不支持宽高像素值；
- 不支持 `background`，传入返回 400；
- `output_format` 只控制**底图**格式，各图层恒为透明 PNG；
- 任一图层生成失败则整个请求失败，不支持部分成功。

**`layer_decomposition_options`**：

| 参数 | 类型 | 默认 | 说明 |
|-----|------|-----|------|
| max_images | integer | 30 | 本次最多输出的图片总数（含底图），取值 `[2, 100]` |
| text_recognition | boolean | false | 是否对规整文字图层返回富文本 OCR 结果 |

> `max_images` 传得越大，拆分结果通常越细。创建时按 `max_images` 预冻结额度，完成后按实际输出张数退差，见 [计费说明](#计费说明)。

响应 `data` 中每一项为一个图层：底图 `z_index` 为 `0`，图层从 `1` 递增（越大越靠上）；除底图外还会返回 `bounding_box`、`name`、`description`。开启 `text_recognition` 后，被判定为**规整文字**的图层额外返回 `text_recognition`（艺术字、手写体不返回），见 [响应参数](#响应参数)。

---

## 计费说明

本模型按**输出图张数 + 输入图张数**计费，输出图单价取决于**该张图自身的总像素**：

| 计费项 | 判据 | 说明 |
|-------|------|------|
| 输出图（标准档） | 单张总像素 ≤ 2601123 | `1K` 与 `1.5K` 的常用尺寸都落在本档 |
| 输出图（高清档） | 2601123 < 单张总像素 ≤ 4624220 | `2K` 的常用尺寸落在本档 |
| 输入图 | 每张参考图 | 按张计费，**无免费额度** |

- 普通文生图/图生图各产出 1 张输出图，总费用 = 输出图单价 + 输入图单价 × 参考图张数。
- 图层拆分产出多张（底图 + 各图层），**逐张**按各自像素判档后求和，再加输入图费用。创建时按 `max_images` 预冻结，完成后按实际张数退差。
- 计费张数以响应 `usage.generated_images`（输出图）与 `usage.input_images`（输入图）为准。

具体单价见定价页。

---

## 支持的使用场景

### 场景1：文生图

```bash
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-5",
    "prompt": "一只橘猫坐在窗台上看雨，暖色调，电影感",
    "size": "2K"
  }'
```

指定宽高比（16:9）：

```bash
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-5",
    "prompt": "充满活力的特写编辑肖像，色彩拼接丰富，杂志封面风格，工作室灯光",
    "size": "2880x1440"
  }'
```

### 场景2：文生透明图（RGBA）

```bash
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-5",
    "prompt": "一只卡通小狐狸，扁平矢量风格",
    "size": "1K",
    "background": "transparent",
    "output_format": "png",
    "safety_identifier": "a3f1c9e2b7d4"
  }'
```

### 场景3：图生图

```bash
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-5",
    "prompt": "把这张图改成夜景，霓虹灯反射在地面",
    "image": "https://example.com/input.png",
    "size": "2K"
  }'
```

### 场景4：多图参考生图

```bash
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-5",
    "prompt": "将图1的服装换为图2的服装",
    "image": [
      "https://example.com/person.png",
      "https://example.com/clothes.png"
    ],
    "size": "2K"
  }'
```

### 场景5：图层拆分 + 富文本 OCR

```bash
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-5",
    "prompt": "将图片进行图层分离",
    "image": "https://example.com/poster.png",
    "layer_decomposition": true,
    "layer_decomposition_options": {
      "max_images": 10,
      "text_recognition": true
    },
    "size": "2K"
  }'
```

### 场景6：Python（OpenAI SDK）

V3 协议与 OpenAI SDK 的图片接口兼容，`base_url` 填 `https://mm-internal-cn.leonecloud.com/api/v3` 即可，非标准字段放 `extra_body`：

```python
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-5",
    prompt="一只卡通小狐狸，扁平矢量风格",
    size="1K",
    response_format="url",
    extra_body={
        "background": "transparent",
        "output_format": "png",
    },
)
print(resp.data[0].url)
```

---

## 响应参数

### 成功响应（HTTP 200）

```json
{
  "model": "seedream-5-5",
  "created": 1794814254,
  "data": [
    {
      "url": "https://.../task_20261116153049_at02duyc_0.png",
      "size": "1024x1024",
      "output_format": "png",
      "background": "transparent"
    }
  ],
  "usage": {
    "generated_images": 1,
    "input_images": 0,
    "output_tokens": 4096,
    "total_tokens": 4096
  },
  "safety_identifier": "a3f1c9e2b7d4"
}
```

图层拆分响应（开启 `text_recognition`）：

```json
{
  "model": "seedream-5-5",
  "created": 1794813692,
  "data": [
    {
      "url": "https://.../layer_0.png",
      "size": "2048x2048",
      "output_format": "png",
      "background": "opaque",
      "z_index": 0
    },
    {
      "url": "https://.../layer_1.png",
      "size": "3455x1214",
      "output_format": "png",
      "background": "transparent",
      "z_index": 1,
      "bounding_box": {
        "absolute": [140, 0, 1900, 618],
        "normalized": [68, 0, 928, 302]
      },
      "name": "顶部黄色衬线艺术字",
      "description": "位于画面顶部的黄色衬线艺术字"
    },
    {
      "url": "https://.../layer_2.png",
      "size": "2442x1718",
      "output_format": "png",
      "background": "transparent",
      "z_index": 2,
      "bounding_box": {
        "absolute": [44, 258, 734, 743],
        "normalized": [21, 126, 358, 363]
      },
      "name": "左上白色两行衬线文字",
      "description": "左上区域的两行白色衬线文字",
      "text_recognition": {
        "text": "EXPLORE THE WILD,\nINSPIRE THE SOUL.",
        "lines": [
          {
            "bounding_box": {
              "absolute": [44, 258, 734, 500],
              "normalized": [21, 126, 358, 244]
            },
            "runs": [
              {
                "text": "EXPLORE THE WILD,",
                "style": {
                  "similar_font_family": "Palatino Linotype",
                  "foreground_color": "#F5F5F0",
                  "bold": true,
                  "italic": false,
                  "underline": false,
                  "strikethrough": false,
                  "shadow": false,
                  "translucent": false
                }
              }
            ]
          }
        ]
      }
    }
  ],
  "usage": {
    "generated_images": 9,
    "input_images": 1,
    "output_tokens": 131061,
    "total_tokens": 131061
  }
}
```

| 参数 | 类型 | 说明 |
|-----|------|------|
| 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 | 图片格式：`png` / `jpeg`。图层拆分时该字段只反映**底图**格式，各图层恒为 `png` |
| data[].background | string | 实际透明度类型：`transparent`（含透明或半透明像素）/ `opaque`（整体不透明） |
| 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 | 图层描述（仅图层） |
| data[].text_recognition | object | 富文本 OCR 结果，见下表（仅规整文字图层且开启 `text_recognition`） |
| safety_identifier | string | 请求里设了 `safety_identifier` 时原样回显 |
| usage.generated_images | integer | 生成的图片张数（图层拆分时为底图 + 图层总数，即输出图计费张数） |
| usage.input_images | integer | 本次传入的参考图张数（计费项） |
| usage.output_tokens | integer | `sum(宽 × 高) / 256` 取整 |
| usage.total_tokens | integer | 与 `output_tokens` 相同 |

**`text_recognition` 结构**：

| 参数 | 类型 | 说明 |
|-----|------|------|
| text | string | 当前图层的完整纯文本，按从上到下、从左到右排列，行间以 `\n` 分隔 |
| lines[].bounding_box | object | 该文字行在底图坐标系中的边界框，结构同 `data[].bounding_box` |
| lines[].runs[].text | string | 样式片段的文本，不含换行符；整行样式一致时只有 1 个片段 |
| lines[].runs[].style.similar_font_family | string | 最相似的字体名；无法识别或置信度不足时返回 `unknown` |
| lines[].runs[].style.foreground_color | string | 文字颜色，大写十六进制 `#RRGGBB`，不含 Alpha |
| lines[].runs[].style.bold / italic / underline | boolean | 是否识别到粗体 / 斜体 / 下划线 |
| lines[].runs[].style.strikethrough / shadow / translucent | boolean | 是否识别到删除线 / 阴影 / 半透明 |

> 样式信息由模型自动识别，可能与原图的精确属性有偏差。

> 图片 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（统一入口）](/docs/images-generations) 的查询任务接口：

```json
{
  "error": {
    "code": "RequestTimeout",
    "message": "图片生成超时，任务仍在处理中，请用 GET /v1/images/generations/task_xxx 查询结果",
    "type": "GatewayTimeout"
  }
}
```

> 图层拆分（尤其 `max_images` 较大时）耗时明显长于单图，建议客户端读超时设到 10 分钟以上。

---

## 错误码

失败时返回真实 HTTP 状态码 + 扁平 `error` 对象：

```json
{
  "error": {
    "code": "InvalidParameter",
    "message": "size 总像素需在 [921600, 4624220] 之间，当前 512x512",
    "type": "BadRequest"
  }
}
```

| HTTP 状态码 | error.code | 说明 |
|------------|-----------|------|
| 400 | InvalidParameter | 参数错误（缺少 prompt、size 取值无效、`jpeg` 与 `transparent` 同传、`max_images` 越界、模型不支持的参数等） |
| 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.5`，路径即模型 | 统一 `POST /api/v3/images/generations`，模型由 `model` 指定 |
| 调用方式 | 创建任务后轮询查询 | 同步阻塞，直接返回图片 |
| 字段命名 | camelCase（`imageUrls`、`aspectRatio`、`outputFormat`） | snake_case（`image`、`size`、`output_format`） |
| 生成类型 | `genType`（`t2i` / `i2i` / `t2i-layer` / `i2i-layer`） | 由是否传 `image` 决定；图层拆分传 `layer_decomposition: true` |
| 尺寸参数 | `aspectRatio` + `resolution`（`1K` / `1.5K` / `2K`） | 合并为 `size`，见 [size 说明](#size-说明) |
| 图层配置 | `layerMaxImages` + `layerTextRecognition` | `layer_decomposition_options.max_images` + `.text_recognition` |
| 图层元数据 | 查询响应的 `seedreamLayerOutput.layers[]` | 直接在 `data[]` 上（`z_index` / `bounding_box` / `text_recognition`） |
| 创建响应 | `{code, msg, data}` 信封 | 扁平对象，直接带 `data[].url` |
| 错误响应 | 信封内错误码（`code: 10002`） | 真实 HTTP 状态码 + `{"error": {...}}` |
| 回调通知 | `callbackUrl` | 同步返回，无需回调 |

V2 接口继续可用，两者共享同一套任务与计费体系。V2 的 `resolution` 取值与本文的分辨率档一致（`1K` / `1.5K` / `2K`，默认 `2K`）。

---

## 最佳实践

1. **设置足够的超时**：单图出图通常 15 ~ 60 秒，图层拆分可达数分钟，客户端读超时建议不低于 10 分钟。
2. **`1K` 与 `1.5K` 同档计费**：需要更精细的出图时直接选 `1.5K`，不额外加价；只在需要更小产物（如列表缩略图）时降到 `1K`。
3. **宽高比两种给法**：分辨率档模式下在 `prompt` 里描述宽高比（如「16:9 宽幅横版」）由模型判断；需要精确尺寸则直接传像素值，见 [size 说明](#size-说明)。
4. **透明图直接出，不必再抠图**：需要 RGBA 素材时传 `background: transparent`，比先出实底图再抠更省一次调用。
5. **`max_images` 按需给**：它同时决定拆分粒度与预冻结额度；只要前景元素不多就不必给到 100，否则创建时冻结额偏大（完成后会退差）。
6. **只需要整图时不要开 `layer_decomposition`**：图层拆分按底图 + 图层总张数计费，比单图贵数倍。
7. **参考图每张都计费**：与 5.0 Pro 不同，本模型第 1 张参考图也计费，多图参考前请确认费用。
8. **及时转存结果**：返回的图片 URL 请及时下载保存，避免长期依赖临时链接。
9. **参考图优先用 URL**：Base64 会显著增大请求体，多张大图时更容易超出请求体上限。
