--- ## 豆包 Seedream(字节跳动/火山引擎) 使用火山引擎 Ark API 的 Doubao Seedream 模型,支持文生图、图生图、多图融合、图片编辑。 ### 前提条件 - `curl.exe`(Windows内置) - Ark API Key: `ark-119a37ed-f123-42fc-aea6-b38d47d47fc0-f7ddf` - API端点: `https://ark.cn-beijing.volces.com/api/v3/images/generations` ### 模式一览 | 模式 | `image`参数 | 用途 | |---|---|---| | 文生图 | 省略或`[]` | 从文字描述生成图片 | | 图生图 | `["url1"]` | 基于参考图生成新图,可通过prompt控制保留原图产品外观 | | 多图融合 | `["url1","url2",...]` | 最多10张参考图融合,prompt中用"图1/图2"指代 | | 图片编辑 | `["url1"]` + 编辑提示词 | 移除/替换元素、换背景等 | 默认模型: `doubao-seedream-5-0-260128` ### 图生图说明 Seedream 的 `image` 参数传入的是**参考图**,模型会根据 prompt 重新生成图片,**不能100%像素级保留原图**。但通过精确的 prompt 可在一定程度上保持产品形态: - 好的做法:`"保留图1中U盘产品的外观和形态不变,仅更换背景为白色,添加科技光效"` - 不好的做法:`"U盘插在电脑上"`(描述太笼统,产品外观会偏离原图) ### 文生图(Windows PowerShell) ```powershell $tmpFile = "$env:TEMP\request.json" $prompt = "YOUR_PROMPT_HERE" $json = @" {"model":"doubao-seedream-5-0-260128","prompt":"$prompt","size":"2k","sequential_image_generation":"disabled","response_format":"url","stream":false,"watermark":false} "@ $sw = [System.IO.StreamWriter]::new($tmpFile, $false, (New-Object System.Text.UTF8Encoding $false)) $sw.Write($json); $sw.Close() $response = curl.exe -s -X POST https://ark.cn-beijing.volces.com/api/v3/images/generations ` -H "Content-Type: application/json" ` -H "Authorization: Bearer ark-119a37ed-f123-42fc-aea6-b38d47d47fc0-f7ddf" ` -d "@$tmpFile" | ConvertFrom-Json $imageUrl = $response.data[0].url $outputPath = Join-Path (Get-Location) "output-name.png" curl.exe -s -o $outputPath $imageUrl Write-Output $outputPath ``` ### 图生图/图片编辑(本地文件输入,Windows PowerShell) ```powershell $imgBytes = [System.IO.File]::ReadAllBytes((Resolve-Path "path\to\input.png")) $imgBase64 = [System.Convert]::ToBase64String($imgBytes) $tmpFile = "$env:TEMP\request.json" $sw = [System.IO.StreamWriter]::new($tmpFile, $false, (New-Object System.Text.UTF8Encoding $false)) $sw.WriteLine('{') $sw.WriteLine(' "model": "doubao-seedream-5-0-260128",') $sw.WriteLine(' "prompt": "保留图1中产品的外观和形态不变,更换背景为白色",') $sw.WriteLine(' "image": ["data:image/png;base64,' + $imgBase64 + '"],') $sw.WriteLine(' "size": "2048x2048",') $sw.WriteLine(' "sequential_image_generation": "disabled",') $sw.WriteLine(' "response_format": "url",') $sw.WriteLine(' "stream": false,') $sw.WriteLine(' "watermark": false') $sw.WriteLine('}') $sw.Close() $response = curl.exe -s -X POST https://ark.cn-beijing.volces.com/api/v3/images/generations ` -H "Content-Type: application/json" ` -H "Authorization: Bearer ark-119a37ed-f123-42fc-aea6-b38d47d47fc0-f7ddf" ` -d "@$tmpFile" | ConvertFrom-Json $imageUrl = $response.data[0].url $outputPath = Join-Path (Get-Location) "output-name.png" curl.exe -s -o $outputPath $imageUrl Write-Output $outputPath ``` > **注意**:当 prompt 中包含中文引号等特殊字符时,不要用 PowerShell 的 `@"..."@` here-string 拼接 JSON,应改用 `StreamWriter.WriteLine()` 逐行写入,避免解析错误。 ### 多图融合 ```json { "model": "doubao-seedream-5-0-260128", "prompt": "把图1的人物穿上图2的衣服,站在图3的场景中", "image": ["url1", "url2", "url3"], "size": "2k", "sequential_image_generation": "disabled", "response_format": "url", "stream": false, "watermark": false } ``` ### 批量生成(最多15张) ```json { "model": "doubao-seedream-5-0-260128", "prompt": "一个女孩和她的布偶牛在过山车上,分别呈现早晨、中午、傍晚的场景", "sequential_image_generation": "auto", "sequential_image_generation_options": { "max_images": 3 }, "size": "2k", "response_format": "url", "stream": false, "watermark": false } ``` ### Seedream 参数参考 | 参数 | 类型 | 必填 | 说明 | |---|---|---|---| | `model` | string | 是 | `doubao-seedream-5-0-260128`(默认,5.0)、`doubao-seedream-4-5-251128`(4.5)、`doubao-seedream-4-0-250828`(4.0) | | `prompt` | string | 是 | 文本提示词,最多~300中文字或~600英文词 | | `image` | string[] | 否 | 参考图片URL或Base64(`data:image/jpeg;base64,...`),最多10张;prompt中用"图1/图2"指代顺序 | | `size` | string | 否 | `2k`(默认)、`3k`(仅5.0)、`4k`(4.5/4.0) 或 `WIDTHxHEIGHT`(如`2048x2048`) | | `response_format` | string | 否 | `url`(下载链接,24h有效)或 `b64_json` | | `output_format` | string | 否 | `jpeg`(默认)或 `png`(仅5.0支持) | | `sequential_image_generation` | string | 否 | `disabled`(默认,单图)或 `auto`(模型决定批量数) | | `sequential_image_generation_options` | object | 否 | `{ "max_images": N }` N为1-15,仅auto模式 | | `stream` | boolean | 否 | `false`(等待全部)或 `true`(逐张返回) | | `watermark` | boolean | 否 | 添加"AI Generated"水印,默认`true`(建议设`false`) | | `tools` | array | 否 | `[{ "type": "web_search" }]` 联网搜索(仅5.0) | ### Seedream 尺寸指南 | 别名 | 近似分辨率 | 适用场景 | |---|---|---| | `2k` | ~2048px | **默认** — 质量与速度平衡 | | `3k` | ~3072px | 高质量,产品图(仅5.0) | | `4k` | ~4096px | 最终生产质量(4.5/4.0) | | `WIDTHxHEIGHT` | 自定义 | 如`2048x2048`、`2048x1024` | **像素约束**: - 方式1(别名):用`2k`/`3k`等,prompt中描述宽高比 - 方式2(精确像素):总像素范围 [3686400, 16777216],宽高比 [1/16, 16],每个维度 [1280, 4096] - 两种方式不可混用 ### Seedream 提示词技巧 - **描述场景**: 主体、动作、环境、氛围 - **指定风格**: "电影大片感"、"水彩画风"、"赛博朋克"、"oc渲染"、"超现实主义" - **质量关键词**: "光线追踪"、"景深"、"极致的光影"、"动态模糊" - **编辑指令**: "保留图1中产品外观不变,把背景换成海滩"、"移除画面中的人物" - **多图指代**: 多图输入时用"图1""图2"明确指代,如"保留图1的U盘,放到图2的笔记本上" - **中文提示词原生支持** — 无需翻译为英文 ### 文字渲染技巧(重要) Seedream 对文字渲染有特殊优化,但需要正确的提示词写法: - **必须用双引号包裹文字内容**:Seedream 对双引号内的文字有特殊渲染优先级,准确率远高于不加引号 - ✅ 正确:`标题文字"NAS U盘"`,`标签显示"自动内网穿透"` - ❌ 错误:`标题文字NAS U盘`,`标签显示自动内网穿透` - **强制清晰度约束**:加"笔画清晰醒目、无乱码无模糊"等约束条件 - **指定字体样式**:明确"黑色加粗印刷体"、"白色大号粗体"等,避免模糊描述 - **避免过多小字**:小字号文字像素占比太低,极易模糊出错;尽量只生成少量大号标题文字 - **商用场景建议**:对文字精度要求高时,采用"AI生成无文字底图 + 手动/程序叠加文字"的工作流 ### Windows注意事项 | 问题 | 解决方案 | |---|---| | PowerShell 5.1给JSON加UTF-8 BOM | **不要**用`Set-Content`或`[System.Text.Encoding]::UTF8`,用`[System.IO.StreamWriter]::new($path, $false, (New-Object System.Text.UTF8Encoding $false))` | | PowerShell破坏curl中的`"` | **始终**写JSON到临时文件,用`-d "@$tmpFile"` | | prompt含中文引号/特殊字符 | 用`StreamWriter.WriteLine()`逐行写JSON,不要用`@"..."@` here-string | | curl别名冲突 | 用`curl.exe`而非`curl` | | 续行符 | 用反引号`` ` `` | ### Seedream 错误处理 - **401**: API Key无效 — 检查Authorization头 - **400**: 请求错误 — 检查提示词长度、图片格式、尺寸值(像素不低于3686400) - **429**: 限流 — 等待后重试 - **500**: 服务器错误 — 稍后重试