生成图像
- 走 OpenAI Images 结构,SDK 只改 base_url
- 同步返回,一次响应给出全部结果
- 支持 b64_json 内联与 multipart 上传
认证
所有接口均使用 Bearer Token 进行认证。
Seedream 系列的接口需要在 ark 站 单独获取 Key,与 api 站的 Key 不通用。
请求时在请求头中添加:
Authorization: Bearer YOUR_ARK_KEYAll endpoints authenticate with a Bearer token.
Seedream series endpoints require a key obtained separately from the ark site; it isn't shared with the api site's key.
Add it to the request header:
Authorization: Bearer YOUR_ARK_KEY请求结构
请求体与 POST /doubao/api/v3/images/generations 相同,区别只在路径与 response_format 的可用取值。
客户端已按 OpenAI Images API 编写时使用本路径。相比原生路径多两点能力:
- 支持
response_format: b64_json,网关会下载生成的图片并内联返回。 - 支持
multipart/form-data,参考图可以上传文件而不必用 URL。
n 必须为 1。需要多张请用 sequential_image_generation,不要再靠 n。
文生图、图生图还是多图融合,只由 image 字段决定:
| 场景 | image |
|---|---|
| 文生图 | 不传 |
| 单图编辑 | 字符串,公网 URL 或 data: URI |
| 多图融合 | 字符串数组,最多 10 张 |
The request body is identical to POST /doubao/api/v3/images/generations; only the path and the accepted response_format values differ.
Use this path when your client already speaks the OpenAI Images API. It adds two things over the native path:
response_format: b64_jsonis supported; the gateway downloads the images and returns them inline.multipart/form-datais supported, so reference images can be uploaded as files instead of URLs.
n must be 1. Use sequential_image_generation for multiple images rather than n.
Text-to-image, single-image edit, or multi-image fusion is decided solely by image:
| Scenario | image |
|---|---|
| Text to image | Omitted |
| Single-image edit | A string: public URL or data: URI |
| Multi-image fusion | A string array, up to 10 |
支持的场景
| 场景 | 字段组合 |
|---|---|
| 文生图 | prompt |
| 文生图-指定像素 | prompt + size: "2048x2048" |
| 单图编辑 | prompt + image(字符串) |
| 多图融合 | prompt + image(2 到 10 张数组) |
| 按坐标编辑 | prompt 中带 [x1, y1, x2, y2] 坐标 + image |
| 生成组图 | sequential_image_generation: "auto" + sequential_image_generation_options.max_images |
| 内联 Base64 输出 | response_format: "b64_json" |
| 图层拆分 | image(恰好 1 张)+ layer_decomposition: true |
| 透明背景 | image(1 张)+ background: transparent + output_format: png |
| Scenario | Field combination |
|---|---|
| Text to image | prompt |
| Text to image at exact pixels | prompt + size: "2048x2048" |
| Single-image edit | prompt + image (a string) |
| Multi-image fusion | prompt + image (2 to 10 array) |
| Coordinate edit | prompt carrying [x1, y1, x2, y2] + image |
| Image group | sequential_image_generation: "auto" + sequential_image_generation_options.max_images |
| Inline Base64 output | response_format: "b64_json" |
| Layer decomposition | image (exactly 1) + layer_decomposition: true |
| Transparent background | image (1) + background: transparent + output_format: png |
请求参数
图像模型 ID,必须写全名。取值见下方模型列表。seedream-5 之类的缩写会返回 400。
图像描述。图生图时描述你想要的改动;layer_decomposition 为 true 时可不传。
参考图。每一项是公网 URL 或格式小写的 data:image/<format>;base64,... URI。最多 10 张,单张不超过 30MB。从第二张参考图起额外计费。
输出尺寸,档位 1K、1.5K、2K,或具体像素 宽x高,范围 1024x1024 到 4096x4096,比例 1:16 到 16:1。默认 2K。
默认 url,返回有效期 24 小时的临时链接。b64_json 直接返回 Base64 内容。
默认 true,为 true 时在右下角添加「AI 生成」水印。需要无水印必须显式传 false。
随机种子,用于复现结果,取值 -1 到 2147483647,-1 为随机。
提示词遵循强度,值越高越严格贴合提示词。
输出图片格式,取值 jpeg(默认)或 png。
opaque(默认)或 transparent。透明背景要求恰好一张参考图,且不能与 output_format: jpeg 同时使用。
生成前由模型扩写并优化提示词。
提示词优化设置。mode 取 standard 或 fast,fast 仅 pro 支持。
图层拆分,默认 false。要求恰好一张参考图,每个输出图层单独计费。
只能是 1。传大于 1 会返回 400;需要多张请改用 sequential_image_generation。
取值 auto 开启组图,或 disabled 关闭。配合 sequential_image_generation_options.max_images 控制张数,参考图与生成图合计不超过 15 张。
不支持,已废弃。网关始终一次性返回完整 JSON,传 true 会被拒绝。
The image model ID, which must be the full name; see the model list below. Abbreviations such as seedream-5 return 400.
The image description. For image-to-image, describe the change you want. Can be omitted when layer_decomposition is true.
The reference image(s). Each entry is a public URL or a data:image/<format>;base64,... URI with a lowercase format. Up to 10 images, each under 30MB. Images past the first are billed extra.
Output size as a tier (1K, 1.5K, 2K) or exact pixels widthxheight from 1024x1024 to 4096x4096, ratio 1:16 to 16:1. Defaults to 2K.
Defaults to url, a link valid for 24 hours. b64_json returns inline Base64 instead.
Defaults to true, which stamps an "AI generated" mark in the bottom-right corner. Pass false explicitly to remove it.
Random seed for reproducing results, from -1 to 2147483647; -1 means random.
Prompt adherence strength. Higher values follow the prompt more strictly.
Output format: jpeg (default) or png.
opaque (default) or transparent. Transparency requires exactly one reference image and can't be combined with output_format: jpeg.
Lets the model expand and refine the prompt before generating.
Prompt-optimizer settings. mode is standard or fast; fast is pro only.
Layer decomposition, default false. Requires exactly one reference image, and each output layer is billed separately.
Must be 1. Values above 1 return 400; use sequential_image_generation for multiple images.
auto enables an image group, disabled turns it off. Pair with sequential_image_generation_options.max_images; references plus outputs stay within 15.
Not supported and deprecated. The gateway always returns complete JSON; true is rejected.
尺寸与像素
档位: 1K、1.5K、2K,默认 2K。
精确像素: 宽高各自须落在 1024 到 4096 之间,宽高比须在 1:16 到 16:1 之间。
限制的是单边与比例,不是乘积:1024x1024 合法,512x512 会返回 400。
Tiers: 1K, 1.5K, 2K; the default is 2K.
Exact pixels: width and height must each fall between 1024 and 4096, with an aspect ratio between 1:16 and 16:1.
The per-side bounds and ratio are what's limited, not the product: 1024x1024 is valid, while 512x512 returns 400.
响应
同步返回,data 中每项对应一张生成的图片:
{
"data": [
{
"url": "https://ark-content-generation-v2-cn-beijing.tos-cn-beijing.volces.com/seedream/xxx.jpeg",
"size": "2048x2048",
"output_format": "jpeg"
}
],
"created": 1757469067,
"usage": {
"generated_images": 1,
"output_tokens": 15908,
"total_tokens": 15908
}
}data[].url(string) — 有效期 24 小时的图片链接,response_format为url时返回。data[].b64_json(string) —response_format为b64_json时返回的 Base64 内容。data[].size(string) — 该张图片的实际像素尺寸。data[].output_format(string) — 文件格式。图层固定为png,底图跟随请求。data[].z_index/name/description/bounding_box— 仅图层拆分时返回。data[].error(object) — 单图失败信息,仅组图场景中某一张失败时出现。created(integer) — 完成时间,Unix 秒。usage(object) — 用量信息,含generated_images、input_images、output_tokens、total_tokens。
生成是同步的,请求会阻塞到全部图片出完。1K 通常几十秒内返回,2K 更久,客户端超时建议设到 5 分钟以上。
The response is synchronous; each entry in data is one generated image:
{
"data": [
{
"url": "https://ark-content-generation-v2-cn-beijing.tos-cn-beijing.volces.com/seedream/xxx.jpeg",
"size": "2048x2048",
"output_format": "jpeg"
}
],
"created": 1757469067,
"usage": {
"generated_images": 1,
"output_tokens": 15908,
"total_tokens": 15908
}
}data[].url(string) — a link valid for 24 hours, returned whenresponse_formatisurl.data[].b64_json(string) — inline Base64, returned whenresponse_formatisb64_json.data[].size(string) — the actual pixel size of that image.data[].output_format(string) — the file format. Layers are alwayspng; the base image follows the request.data[].z_index/name/description/bounding_box— layer decomposition only.data[].error(object) — per-image failure, present only when one image in a group fails.created(integer) — completion time in Unix seconds.usage(object) —generated_images,input_images,output_tokens,total_tokens.
Generation is synchronous: the request blocks until every image is done. 1K usually returns within tens of seconds and 2K takes longer, so set the client timeout to at least 5 minutes.
错误码
| HTTP | 含义 |
|---|---|
| 400 | 请求参数错误:模型未知、size 超出模型范围、参考图过多、该模型不支持的字段 |
| 401 | Token 缺失或无效,type 为 authentication_error |
| 429 | 触发限流 |
常见 400 原因:model 写了缩写;size 超出 1024x1024 到 4096x4096 或比例越界;n 大于 1;参考图超过 10 张;图层拆分未传图或传了多张;透明背景用于文生图。
| HTTP | Meaning |
|---|---|
| 400 | Invalid parameters: unknown model, size outside the model's range, too many reference images, or a field the model doesn't support |
| 401 | Token missing or invalid, with type authentication_error |
| 429 | Rate limit hit |
Common 400 causes: an abbreviated model; size outside 1024x1024 to 4096x4096 or a bad ratio; n above 1; more than 10 reference images; layer decomposition with no image or several; a transparent background on text-to-image.
For more status codes and retry guidance see Error codes and rate limits; for troubleshooting steps see the FAQ.
支持的模型列表
以下图像模型均可通过本接口提交任务,清单只列各厂商最新一代,实际可用范围以你的账号分组为准:
Midjourney 系列
Midjourney 走操作型接口,模型只有一档,具体动作(放大、扩图、变体等)见图像系列文档。
OpenAI 图像 系列
gpt-image-2.5-flare最新一代,支持参考图编辑gpt-image-2上一代主力gpt-image-1.5轻量,出图快gpt-image-1-mini成本最低 等
Google 图像 系列
gemini-3-pro-image旗舰,4K 输出与文字渲染强gemini-3.1-flash-image轻量,适合批量 等
Seedream 系列
seedream-5.0-pro旗舰,画质与文字准确度最好seedream-5.0-flash轻量,出图快 等
更多模型持续更新中…
两个型号的参数完全相同,差别只在速度与成本:
| 型号 | 定位 |
|---|---|
seedream-5.0-pro | 画质与文字准确度最好,适合成片交付 |
seedream-5.0-flash | 出图快、成本低,适合批量与草稿 |
GET https://ark.oairoute.com/api/pricing。Every image model below can be submitted through this endpoint; the list shows only each vendor's latest generation, and what your account group actually allows takes precedence:
Midjourney 系列
Midjourney 走操作型接口,模型只有一档,具体动作(放大、扩图、变体等)见图像系列文档。
OpenAI 图像 系列
gpt-image-2.5-flare最新一代,支持参考图编辑gpt-image-2上一代主力gpt-image-1.5轻量,出图快gpt-image-1-mini成本最低 等
Google 图像 系列
gemini-3-pro-image旗舰,4K 输出与文字渲染强gemini-3.1-flash-image轻量,适合批量 等
Seedream 系列
seedream-5.0-pro旗舰,画质与文字准确度最好seedream-5.0-flash轻量,出图快 等
更多模型持续更新中…
The two variants take identical parameters and differ only in speed and cost:
| Variant | Positioning |
|---|---|
seedream-5.0-pro | Best quality and text accuracy; suits final deliverables |
seedream-5.0-flash | Fast and cheap; suits batches and drafts |
GET https://ark.oairoute.com/api/pricing.计费
总价 = 输出图单价 + 参考图加价 × max(0, 参考图张数 − 1)。
输出图按实际像素面积分档,第 1 张参考图免费,第 2 张起每张加收固定单价。任务失败自动全额退款。图层拆分时每个输出图层单独计费。
具体价格见模型价格与分组接口。
Total = output-image price + reference surcharge × max(0, reference count − 1).
Output images are tiered by actual pixel area. The first reference image is free and each one after it adds a flat surcharge. Failed tasks are refunded in full. Layer decomposition bills every output layer separately.
See Model pricing and group API for actual prices.
使用示例
内联 Base64 输出
需要把结果直接存进数据库或内网服务时,用 b64_json 避免二次下载。
组图
sequential_image_generation: "auto" 一次最多返回 4 张同主题图片。某一张失败时该数组项只带 error,其余照常返回,usage.generated_images 只计成功的张数。
图层还原
拆分得到的图层按 z_index 从小到大叠放。绝对坐标换算为 x=left、y=top、w=right−left、h=bottom−top;任意 W×H 画布用归一化值除以 1000 再乘画布尺寸。
Inline Base64 output
When results go straight into a database or an internal service, use b64_json to avoid a second download.
Image groups
sequential_image_generation: "auto" returns up to 4 images on one theme. If one fails, that array entry carries only error while the rest still return, and usage.generated_images counts only the successes.
Layer reconstruction
Stack the returned layers by ascending z_index. Convert absolute boxes with x=left, y=top, w=right−left, h=bottom−top; on an arbitrary W×H canvas, divide the normalized values by 1000 and multiply by the canvas size.