# Seedream-5.0-Pro 圖像生成 > 使用 Seedream 5.0 Pro 模型生成高質量圖像與圖層拆分,支持 1K/2K 分辨率 **API:** POST https://toapis.com/v1/images/generations **Note:** **中國大陸用戶請注意:** 中國大陸用戶請使用 `https://toapis.cn` 作為接口地址(Base URL)。文檔示例中的 `https://toapis.com` 請替換為 `https://toapis.cn`。 - Seedream 5.0 Pro 高質量圖像生成與圖層拆分模型,由字節跳動 Seed 團隊研發 - 通過 `model` 參數選擇 `doubao-seedream-5-0-pro` 或 `doubao-seedream-5-0-pro-global` - 支持 **1K** 和 **2K** 分辨率(普通生圖單次返回 1 張圖像;開啓 `layer_decomposition` 可拆分爲底圖與最多 16 個獨立透明 PNG 圖層) - 支持文生圖、圖生圖、多圖參考編輯與單圖圖層拆分 - **計費規則**:`doubao-seedream-5-0-pro` 首張參考圖免費(無參考圖按基礎檔計費),從第 2 張參考圖開始按規則計費;`doubao-seedream-5-0-pro-global` 按分辨率檔位計費 - 異步任務管理,通過任務 ID 查詢結果 **Warning:** **重要變更**:爲了更好的性能和成本控制,我們不再支持在 `image_urls` 中直接傳入 base64 圖片數據。請先使用 [上傳圖片接口](/docs/zh-Hant/api-reference/uploads/images) 上傳圖片,獲取 URL 後再調用本接口。 ## 驗證 **Authorization (string, required)** 所有接口均需要使用 Bearer Token 進行認證 獲取 API Key:訪問 [API Key 管理頁面](https://toapis.com/console/token) 獲取您的 API Key 使用時在請求頭中添加: ``` Authorization: Bearer YOUR_API_KEY ``` ## 請求參數 **model (string, required)** Default: "doubao-seedream-5-0-pro" 圖像生成模型名稱,支持 `doubao-seedream-5-0-pro` 與 `doubao-seedream-5-0-pro-global` 示例:`"doubao-seedream-5-0-pro"` **disable_nsfw (boolean)** Default: true 控制是否禁止生成 NSFW 內容(平台參數)。 - `true`(預設)或省略:禁止生成 NSFW 內容 - `false`:允許生成 NSFW 內容(需帳號與所在地區支援) 僅顯式傳入 JSON 布林值 `false` 時生效;傳入 `null` 視為省略,傳入非布林值返回 `400`。部分地區與帳號類型始終禁止生成 NSFW 內容。 **prompt (string, required)** 圖像生成的文本描述(當前版本即使啟用 `layer_decomposition` 也需傳入) 建議中文不超過 300 字、英文不超過 600 詞以獲得更佳效果 **size (string)** Default: "1:1" 圖像寬高比、分辨率檔位或顯式像素尺寸 啟用 `layer_decomposition` 時,該欄位請直接傳入分辨率預設 `1K` 或 `2K`(不要傳 `WIDTHxHEIGHT` 像素尺寸)。 普通生圖/編輯支持的寬高比: - `1:1`:正方形(默認) - `4:3`:橫向 4:3 - `3:4`:豎向 3:4 - `16:9`:橫向寬屏 - `9:16`:豎向長圖 - `3:2`:橫向 3:2 - `2:3`:豎向 2:3 - `21:9`:超寬屏 - `9:21`:超窄屏 普通生圖/編輯也可直接傳入 `1K`、`2K` 或顯式像素 `WIDTHxHEIGHT`(總像素 `921600-4624220`,寬高比 `[1/16, 16]`)。不支持 `3K`、`4K` 與 `size="auto"`。 **n (integer)** Default: 1 生成圖像的數量。Seedream 5.0 Pro 僅支持 `1` 或省略(不支持順序組圖)。 啟用 `layer_decomposition` 時同樣請省略或設為 `1`(該參數不代表拆分圖層數)。 **必須輸入純數字(如 `1`),不要加引號,否則會報錯** **layer_decomposition (boolean)** Default: false 是否啟用 Seedream 5.0 Pro 的圖層拆分能力。 - `false`:返回一般的扁平圖像(預設) - `true`:拆分**唯一一張**參考圖,返回底圖(`z_index: 0`)和最多 16 個帶透明通道的獨立 PNG 圖層(總計最多 17 張) 啟用時需傳入恰好 1 張參考圖(JPEG 或 PNG),並將 `size` 設為 `1K` 或 `2K`。啟用後,每個 `result.data[]` 項目會返回 `z_index`;獨立圖層還會返回 `bounding_box`、`name` 和 `description`。 **image_urls (string[])** 參考圖像 URL 列表,用於圖生圖、多圖參考編輯或圖層拆分(也可使用 `reference_images`、`images` 數組或單圖 `image` 字段) **⚠️ 僅支持 URL 格式(不再支持 base64)** - 公開可訪問的圖像 URL(http:// 或 https://) - 可使用 [上傳圖片接口](/docs/zh-Hant/api-reference/uploads/images) 上傳本地圖片獲取 URL **限制:** - 圖片數量:普通生圖/編輯 0-10 張(無參考圖可做文生圖);圖層拆分需恰好 1 張 - 圖像格式:普通生圖支持 JPEG、PNG、WebP;圖層拆分僅支持 JPEG、PNG - 寬高比(寬/高)範圍:[1/16, 16] - 寬度和高度(px)> 14 - 大小:不超過 30 MB - 總像素:不超過 6000×6000 px **計費說明:** - `doubao-seedream-5-0-pro`:首張參考圖免費,從第 2 張參考圖開始按規則計費 - `doubao-seedream-5-0-pro-global`:按分辨率檔位計費 **metadata (object)** 模型專屬擴展參數,用於配置 Seedream 5.0 Pro 的進階選項 **metadata 屬性** **metadata.resolution (string)** 圖像分辨率,支持 `1K` 與 `2K`(**建議每次請求都顯式傳入 `"1K"` 或 `"2K"`**,以確保計費檔位與生成尺寸一致)。 支持的分辨率: - `1K`:基礎分辨率 - `2K`:標準分辨率 > **注意:** Seedream 5.0 Pro 不支持 `3K` 和 `4K` 分辨率;如需 `3K` 分辨率請使用 `doubao-seedream-5-0` 或 `doubao-seedream-5-5` **metadata.output_format (string)** Default: "png" 輸出圖像檔案格式,支持 `png`(預設)或 `jpeg`。 啟用 `layer_decomposition` 時僅控制底圖格式,獨立透明圖層始終為 `png`。 **metadata.optimize_prompt_options (object)** 提示詞優化選項 **屬性:** - `mode`(字符串):優化模式,支持 `standard` **示例:** ```json "optimize_prompt_options": { "mode": "standard" } ``` **metadata.watermark (boolean)** Default: false 是否爲生成的圖像添加可見水印 - `true`:添加水印 - `false`:不添加水印(默認) ## 參數限制 不支持普通多圖組圖生成(`sequential_image_generation`、`sequential_image_generation_options`)、不支持流式輸出(`stream=true`),也不支持 `tools` 聯網搜索參數。 ## 查詢結果 提交成功不代表生成完成。請使用提交任務時的 API Key 查詢任務狀態(`status` 為 `completed` 後讀取 `result.data`): ```bash curl "https://toapis.com/v1/images/generations/TASK_ID" \ -H "Authorization: Bearer $TOAPIS_API_KEY" ``` ## 回應欄位 **id (string)** 任務唯一標識符,用於查詢任務狀態 **object (string)** 對象類型,固定爲 `generation.task` **model (string)** 使用的模型名稱 **status (string)** 任務狀態 - `pending`、`queued`:排隊等待處理 - `in_progress`:處理中 - `completed`:成功完成 - `failed`:失敗 **progress (integer)** 任務進度百分比(0-100) **created_at (integer)** 任務創建時間戳(Unix 時間戳) **metadata (object)** 任務元數據 **completed_at (integer)** 任務完成時間戳(Unix 時間戳)。僅在任務完成後返回。 **expires_at (integer)** 結果檔案的過期時間戳(Unix 時間戳,自完成起保留 30 天)。請在過期前下載或轉存結果檔案。 **result (object)** 任務成功後的生成結果。僅當 `status` 為 `completed` 時返回。 **result.type (string)** 結果類型,圖片任務固定為 `image`。 **result.data (array)** 圖片結果列表。啟用圖層拆分時,第一個元素通常為底圖,其餘元素為帶透明通道的獨立 PNG 圖層。 **result.data[].url (string)** 底圖或獨立圖層的公開存取網址。 **result.data[].z_index (integer)** 圖層疊放順序。啟用圖層拆分時,底圖通常為 `0`,獨立圖層依次遞增。 **result.data[].size (string)** 當前底圖或獨立圖層的像素尺寸,例如 `2048x2048`。 **result.data[].output_format (string)** 當前結果項目的檔案格式。底圖可使用請求的格式,透明獨立圖層則為 `png`。 **result.data[].bounding_box (object)** 獨立圖層在底圖中的位置,包含 `absolute` 絕對座標和 `normalized` 正規化座標。 **result.data[].bounding_box.absolute (array)** 圖層在底圖中的絕對像素座標,格式為 `[x1, y1, x2, y2]`,分別表示左上角和右下角座標。 **result.data[].bounding_box.normalized (array)** 圖層的正規化座標,格式為 `[x1, y1, x2, y2]`,座標範圍為 `0-1000`。 **result.data[].name (string)** 圖層名稱。 **result.data[].description (string)** 圖層內容描述。 ## Request Examples ```bash cURL curl --request POST \ --url https://toapis.com/v1/images/generations \ --header 'Authorization: Bearer ' \ --header 'Content-Type: application/json' \ --data '{ "model": "doubao-seedream-5-0-pro", "prompt": "可愛的熊貓在竹林中玩耍", "size": "1:1", "n": 1, "metadata": { "resolution": "2K", "output_format": "png" } }' ``` ```bash cURL (圖生圖) curl --request POST \ --url https://toapis.com/v1/images/generations \ --header 'Authorization: Bearer ' \ --header 'Content-Type: application/json' \ --data '{ "model": "doubao-seedream-5-0-pro", "prompt": "可愛的熊貓在竹林中玩耍", "size": "1:1", "n": 1, "image_urls": [ "https://example.com/panda.jpg" ], "metadata": { "resolution": "1K" } }' ``` ```bash cURL (圖層拆分) curl --request POST \ --url https://toapis.com/v1/images/generations \ --header 'Authorization: Bearer ' \ --header 'Content-Type: application/json' \ --data '{ "model": "doubao-seedream-5-0-pro", "prompt": "將圖片進行精確圖層分離,返回底圖和多個獨立透明 PNG 圖層。", "image_urls": [ "https://example.com/office-desk.png" ], "size": "2K", "n": 1, "layer_decomposition": true, "metadata": { "resolution": "2K" } }' ``` ```python Python import requests response = requests.post( "https://toapis.com/v1/images/generations", headers={ "Authorization": "Bearer your-ToAPIs-key", "Content-Type": "application/json" }, json={ "model": "doubao-seedream-5-0-pro", "prompt": "可愛的熊貓在竹林中玩耍", "size": "1:1", "n": 1, "metadata": { "resolution": "2K", "output_format": "png" } } ) task = response.json() print(f"任務 ID: {task['id']}") print(f"狀態: {task['status']}") ``` ```python Python (圖生圖) import requests response = requests.post( "https://toapis.com/v1/images/generations", headers={ "Authorization": "Bearer your-ToAPIs-key", "Content-Type": "application/json" }, json={ "model": "doubao-seedream-5-0-pro", "prompt": "可愛的熊貓在竹林中玩耍", "size": "1:1", "n": 1, "image_urls": ["https://example.com/panda.jpg"], "metadata": { "resolution": "1K" } } ) task = response.json() print(f"任務 ID: {task['id']}") print(f"狀態: {task['status']}") ``` ```javascript JavaScript const response = await fetch('https://toapis.com/v1/images/generations', { method: 'POST', headers: { 'Authorization': 'Bearer your-ToAPIs-key', 'Content-Type': 'application/json' }, body: JSON.stringify({ model: 'doubao-seedream-5-0-pro', prompt: '可愛的熊貓在竹林中玩耍', size: '1:1', n: 1, metadata: { resolution: '2K', output_format: 'png' } }) }); const task = await response.json(); console.log(`任務 ID: ${task.id}`); console.log(`狀態: ${task.status}`); ``` ```javascript JavaScript (圖生圖) const response = await fetch('https://toapis.com/v1/images/generations', { method: 'POST', headers: { 'Authorization': 'Bearer your-ToAPIs-key', 'Content-Type': 'application/json' }, body: JSON.stringify({ model: 'doubao-seedream-5-0-pro', prompt: '可愛的熊貓在竹林中玩耍', size: '1:1', n: 1, image_urls: ['https://example.com/panda.jpg'], metadata: { resolution: '1K' } }) }); const task = await response.json(); console.log(`任務 ID: ${task.id}`); console.log(`狀態: ${task.status}`); ``` ## Response Examples ```json 200 提交成功 { "id": "tsk_img_abc123def456", "object": "generation.task", "model": "doubao-seedream-5-0-pro", "status": "pending", "progress": 0, "created_at": 1703884800, "metadata": {} } ``` ```json 200 圖層拆分完成 { "completed_at": 1787128810, "created_at": 1787128650, "expires_at": 1789720810, "id": "tsk_img_example_layer_decomposition", "model": "doubao-seedream-5-0-pro", "object": "generation.task", "progress": 100, "result": { "type": "image", "data": [ { "url": "https://files.toapis.com/images/example/base.jpg", "size": "1600x2848", "output_format": "jpeg", "z_index": 0 }, { "url": "https://files.toapis.com/images/example/layer-1.png", "size": "3040x955", "output_format": "png", "z_index": 1, "bounding_box": { "absolute": [0, 0, 1600, 503], "normalized": [0, 0, 999, 176] }, "name": "背景辦公設備組", "description": "提取畫面背景的顯示器邊緣和文件收納架,無多餘內容" }, { "url": "https://files.toapis.com/images/example/layer-2.png", "size": "1982x1162", "output_format": "png", "z_index": 2, "bounding_box": { "absolute": [800, 589, 1599, 1058], "normalized": [500, 207, 999, 371] }, "name": "堆疊白色紙張", "description": "提取桌面上堆疊的數張白色辦公紙張,無多餘內容" } ] }, "status": "completed" } ```