图像生成 - OpenAI Images 协议
接口概述
使用 OpenAI Images 格式生成图片,适用于豆包 Seedream 系列模型,支持文本生图、图生图 / 多图融合、组图序列生成。请求体是扁平结构(参数直接放在顶层),图片地址在响应的 data[] 里取。
本页只讲这一套协议;通义千问 / 万相系模型使用另一套报文,见「文生图-DashScope 协议」页。
按张计费,每次费用可在控制台「费用中心」查看。
接口地址
POST https://test.jw-info.com/v1/images/generations
请求头
| 请求头 | 是否必填 | 说明 |
|---|---|---|
| Content-Type | 是 | 固定为 application/json |
| Authorization | 是 | Bearer {API_KEY},也支持 x-api-key |
请求参数
| 参数名 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| model | string | 是 | 模型名称,见「可用模型」或模型广场 |
| prompt | string | 是 | 文本提示词,描述期望生成的图像内容、风格和构图。建议不超过 600 英文单词或 300 汉字 |
| size | string | 否 | 输出尺寸,格式 <宽>x<高>(如 2048x2048)或预设档位 1K / 2K / 3K / 4K,默认 2048x2048。详见下方「分辨率说明」 |
| response_format | string | 否 | 返回格式:url(默认,返回图片下载链接)或 b64_json(返回 Base64 编码) |
| output_format | string | 否 | 输出图片格式:jpeg(默认)或 png。部分模型不支持自定义 |
| image | string / array | 否 | 参考图片,支持 URL 或 Base64。用于图生图 / 多图融合,最多 14 张 |
| sequential_image_generation | string | 否 | 组图生成开关:disabled(默认)或 auto |
| sequential_image_generation_options | object | 否 | 组图配置,含 max_images(1–15,默认 15)。仅 sequential_image_generation="auto" 时生效 |
| optimize_prompt_options | object | 否 | 提示词优化配置,如 {"mode": "standard"}(默认)或 {"mode": "fast"} |
| stream | bool | 否 | 流式输出暂未开放,请传 false 或省略 |
本协议下无需传 watermark(默认不加水印)。
模型差异
| 特性 | doubao-seedream-4.0 | doubao-seedream-4.5 | doubao-seedream-5.0-lite |
|---|---|---|---|
| 支持分辨率 | 1K / 2K / 4K | 2K / 4K | 2K / 3K / 4K |
| 输出图片格式 | jpeg(不可配置) | jpeg(不可配置) | jpeg / png(可配置) |
| 提示词优化模式 | standard / fast | standard | standard |
| 图生图 / 多图融合 | ✅ 最多 14 张 | ✅ 最多 14 张 | ✅ 最多 14 张 |
| 组图序列生成 | ✅ | ✅ | ✅ |
doubao-seedream-5.0-pro、doubao-seedream-5.0-pro-0724 同属这一协议,参数写法一致。
分辨率说明
- 像素格式为
<宽>x<高>(使用小写字母 x),总像素范围 [3,686,400, 16,777,216]、宽高比范围 [1/16, 16];传得过小会被拒绝(错误正文会说明要求) - 默认分辨率为
2048x2048,也支持预设档位:1K、2K、3K、4K - 推荐分辨率:
| 宽高比 | 推荐分辨率 |
|---|---|
| 1:1 | 2048x2048 |
| 4:3 | 2304x1728 / 1728x2304 |
| 3:2 | 2496x1664 / 1664x2496 |
| 16:9 | 2848x1600 / 1600x2848 |
| 21:9 | 3136x1344 |
请求示例
最简请求:
{
"model": "doubao-seedream-4.5",
"prompt": "一只白色猫咪坐在书桌上,阳光从窗户照进来"
}
完整请求(含尺寸、返回格式与提示词优化模式):
{
"model": "doubao-seedream-5.0-lite",
"prompt": "一张科技感十足的海报,标题为「AI未来」,蓝色渐变背景",
"size": "2048x2048",
"response_format": "url",
"output_format": "png",
"stream": false,
"optimize_prompt_options": { "mode": "standard" }
}
图生图请求:
{
"model": "doubao-seedream-4.5",
"prompt": "将背景改为星空,保持主体不变",
"size": "2048x2048",
"response_format": "url",
"image": ["https://example.com/photo.jpg"]
}
组图序列生成请求:
{
"model": "doubao-seedream-4.5",
"prompt": "一组四张的咖啡店菜单插画,风格统一",
"sequential_image_generation": "auto",
"sequential_image_generation_options": { "max_images": 4 }
}
响应参数
| 字段 | 类型 | 说明 |
|---|---|---|
| model | string | 实际使用的模型 |
| created | int | 请求创建的 Unix 时间戳(秒) |
| data | array | 输出图片信息数组 |
| data[].url | string | 图片下载链接(response_format="url" 时返回,24 小时内有效) |
| data[].b64_json | string | Base64 编码的图片数据(response_format="b64_json" 时返回) |
| data[].size | string | 图片尺寸,如 2048x2048 |
| data[].error | object | 单张失败时的错误信息(含 code 与 message) |
| usage | object | 用量信息 |
| usage.image_count | int | 成功生成的图片数量 |
| usage.generated_images | int | 成功生成的图片数量 |
| usage.output_tokens | int | 消耗的 token 数 |
| usage.total_tokens | int | 总 token 数 |
响应示例
url 模式:
{
"model": "doubao-seedream-4.5",
"created": 1719820800,
"data": [
{ "url": "https://example.com/generated_image.jpg", "b64_json": null, "size": "2048x2048" }
],
"usage": {
"generated_images": 1,
"output_tokens": 16384,
"total_tokens": 16384,
"image_count": 1
}
}
b64_json 模式:
{
"model": "doubao-seedream-4.5",
"created": 1719820800,
"data": [
{ "url": null, "b64_json": "/9j/4AAQSkZJRgABAQEASABIAAD/2wBD...", "size": "2048x2048" }
],
"usage": {
"generated_images": 1,
"output_tokens": 16384,
"total_tokens": 16384,
"image_count": 1
}
}
组图序列生成会一次返回多张,data[] 每张一个元素,usage.image_count 为实际张数。
错误响应
请求参数或鉴权有问题时返回 400 / 401 / 402,正文为 {"detail": "说明文字"};模型侧报错时返回 502 并保留模型返回的原始错误正文,便于定位。尺寸不合法(原始正文含说明):
{
"detail": "模型服务返回错误 400:{\"error\":{\"message\":\"The parameter `size` specified in the request is not valid: image size must be at least 3686400 pixels.\"}}"
}
模型名写错(原始正文含 code):
{
"detail": "模型服务返回错误 400:{\"error\":{\"message\":\"Model not found: doubao-seedream-xxx\",\"type\":\"invalid_request_error\",\"code\":\"model_not_found\"}}"
}
完整状态码见「错误码」页。
代码示例
cURL:
curl -X POST https://test.jw-info.com/v1/images/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-你的密钥" \
-d '{
"model": "doubao-seedream-4.5",
"prompt": "一只白色猫咪坐在书桌上,阳光从窗户照进来",
"size": "2048x2048",
"response_format": "url"
}'
Python:
import requests
BASE = "https://test.jw-info.com"
API_KEY = "sk-你的密钥"
payload = {
"model": "doubao-seedream-4.5",
"prompt": "一只白色猫咪坐在书桌上,阳光从窗户照进来",
"size": "2048x2048",
"response_format": "url",
}
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {API_KEY}",
}
response = requests.post(f"{BASE}/v1/images/generations", json=payload, headers=headers)
result = response.json()
if response.status_code == 200:
for item in result["data"]:
print("图片 URL:", item["url"])
print("用量:", result["usage"])
else:
print("请求失败:", result.get("detail", result))
可用模型
| 模型 | 分辨率 | 输出格式 | 特色 |
|---|---|---|---|
| doubao-seedream-4.0 | 1K / 2K / 4K | jpeg | 支持 fast 优化模式 |
| doubao-seedream-4.5 | 2K / 4K | jpeg | 画质提升 |
| doubao-seedream-5.0-lite | 2K / 3K / 4K | jpeg / png | 支持 png 输出 |
| doubao-seedream-5.0-pro | 见模型广场 | jpeg | 按输出像素分档计费 |
| doubao-seedream-5.0-pro-0724 | 见模型广场 | jpeg | 高精度版本 |
模型清单与单价以模型广场为准(含上架状态)。
计费
- 按张计费:单价 × 实际出图张数(组图序列生成一次回多张时按多张计),单价见模型广场
- 按输出像素分档:
doubao-seedream-5.0-pro一类模型按size判档(如 ≤ 261 万像素一档、超出按更高档,以模型广场展示为准);size无法判断时按高档计 - 调用报错记 0 费用;每次费用可在控制台「费用中心」查看