Seedream 5.0 Flash

使用模型 doubao-seedream-5.0-flash,支持文生图、最多 10 张参考图的图生图,以及单张参考图的图层分解。普通生成输出一张图片;图层分解输出底图和独立前景图层。

定价

参考图片免费,所有支持的输出分辨率同价。

每个成功输出 4.68 积分,图层模式的背景图也计为一个输出。普通生成预扣 4.68 积分;图层模式最多按 17 个输出预扣 79.56 积分,核实成功结果后仅退还未使用的差额。例如,确认成功返回背景图和两个前景图层时,实扣 14.04 积分,退回预扣差额 65.52 积分。账户倍率作用于总价,积分保留两位小数。结果缺失或不一致时保留预扣款等待核对,不会在已成功生成后重新生成或执行失败退款。

请求参数

接口:POST /v1/images/generations。使用 Authorization: Bearer sk-your-api-key 进行认证。

字段类型必填说明
modelstring是固定为 doubao-seedream-5.0-flash。
inputobject是生成参数,见下表。
callback_urlstring否任务完成或失败时接收通知的 URL。

Input 参数

输入参数类型说明
promptstring两种模式均必填,不能为空。
layer_decompositionboolean默认 false;设为 true 时分解一张参考图片。
image_urlsstring[]仅接受公开 HTTP(S) URL;普通生成最多 10 张,图层分解必须恰好 1 张。不支持 Base64。
sizestring普通生成默认 2K,支持 1K、1.5K、2K 或精确 WIDTHxHEIGHT;图层分解默认 auto,仅支持 auto、1K、1.5K、2K。
output_formatstringjpeg(默认)或 png。
watermarkboolean默认 false;设为 true 可添加水印。

普通生成的精确尺寸总像素须在 921,600–4,624,220 之间,宽高比须在 1/16–16 之间。auto 仅用于图层分解;精确像素尺寸仅用于普通生成。Flash 不支持组图生成、联网搜索、提示词优化参数或流式输出。结果为图片 URL,不提供 Base64 或 PSD 文件。无需传输出数量,平台根据模式计算。

异步任务与回调

创建任务后返回 taskId,例如:

{
  "code": 200,
  "msg": "success",
  "data": {
    "taskId": "00000000-0000-4000-8000-000000000002"
  }
}

使用任务 ID 查询结果:

curl https://api.aivideoapi.ai/v1/tasks/00000000-0000-4000-8000-000000000002 \
  -H "Authorization: Bearer sk-your-api-key"

任务可能处于 pending、processing、completed 或 failed 状态。completed 时读取 output.urls 和 output.metadata。客户端遇到超时应继续查询已有任务,避免重复提交生成请求。

也可以在创建任务时传入 callback_url,通过回调接收最终结果。完成回调正文与下面的完成查询结果结构相同;签名验证与重试说明见回调通知。

普通生成

创建请求

curl -X POST https://api.aivideoapi.ai/v1/images/generations \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "doubao-seedream-5.0-flash",
    "input": {
      "prompt": "一只橘猫坐在窗边看日落,温暖的插画风格",
      "size": "2K"
    }
  }'

完成结果(脱敏示例)

通过 GET /v1/tasks/{taskId} 查询任务,可获得如下单张 JPEG 结果。输出尺寸以 images[0].size 为准;本例按账户倍率 1 消费 4.68 积分。任务 ID、图片链接和时间已替换为示例值,链接不可用于实际下载。usage 中的 token 数仅供用量参考,Flash 按成功输出数量计费。

{
  "id": "00000000-0000-4000-8000-000000000002",
  "status": "completed",
  "model": "doubao-seedream-5.0-flash",
  "credits_consumed": 4.68,
  "created_at": 1700000000,
  "completed_at": 1700000028,
  "output": {
    "urls": [
      "https://example.com/seedream/generated.jpg"
    ],
    "metadata": {
      "model": "doubao-seedream-5.0-flash",
      "usage": {
        "input_images": 0,
        "total_tokens": 16820,
        "output_tokens": 16820,
        "generated_images": 1
      },
      "images": [
        {
          "size": "1856x2320",
          "output_index": 0,
          "output_format": "jpeg"
        }
      ],
      "image_sizes": [
        "1856x2320"
      ],
      "output_format": "jpeg",
      "generated_images": 1,
      "settlement_reason": null,
      "settlement_status": "settled",
      "layer_decomposition": false,
      "requested_image_count": 1,
      "result_url_expires_in": 86400,
      "source_url_expires_in": 86400
    }
  }
}

图层分解

创建请求

curl -X POST https://api.aivideoapi.ai/v1/images/generations \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "doubao-seedream-5.0-flash",
    "callback_url": "https://your-server.com/webhook",
    "input": {
      "prompt": "将画面中的前景主体与背景分离",
      "image_urls": ["https://example.com/scene.png"],
      "layer_decomposition": true,
      "size": "auto",
      "output_format": "png"
    }
  }'

完成结果保留标准 output.urls 数组,output.metadata.images 描述每个输出。output_index 是对应 URL 在 output.urls 中从 0 开始的下标;z_index 是图层顺序;name、description、size、output_format 为可选描述。前景图层的 bounding_box.absolute 和 bounding_box.normalized 均采用 [左, 上, 右, 下],不是宽高;归一化坐标是 0–1000 的整数。背景图没有边界框。应保留每个 URL 条目,用 output_index 关联描述,不要通过文件名推断层次或合并重复 URL 的图层。

图层分解完成结果(脱敏示例)

通过 GET /v1/tasks/{taskId} 查询任务,完成后可获得如下结果。示例包含底图和 7 个前景图层,共 8 个输出。任务 ID、图片链接、时间、图层名称和描述已替换为示例值;图片链接不可用于实际下载。

此处按账户倍率 1 展示:预扣 79.56 积分,实际消费 4.68 × 8 = 37.44 积分,返还差额 42.12 积分。实际扣费以返回的 credits_consumed 为准;usage 中的 token 数用于用量展示,Flash 按成功输出数量计费。

底图的 z_index 为 0,可能不包含 name、description 和 bounding_box,客户端应兼容字段缺省。size 是输出图片尺寸,bounding_box 描述该图层在原图中的位置,两者的宽高不一定相同。requested_image_count: 17 是最大预扣输出数量,本次成功数量为 generated_images: 8。

{
  "id": "00000000-0000-4000-8000-000000000001",
  "status": "completed",
  "model": "doubao-seedream-5.0-flash",
  "credits_consumed": 37.44,
  "created_at": 1700000000,
  "completed_at": 1700000075,
  "output": {
    "urls": [
      "https://example.com/seedream/base.png",
      "https://example.com/seedream/layer-1.png",
      "https://example.com/seedream/layer-2.png",
      "https://example.com/seedream/layer-3.png",
      "https://example.com/seedream/layer-4.png",
      "https://example.com/seedream/layer-5.png",
      "https://example.com/seedream/layer-6.png",
      "https://example.com/seedream/layer-7.png"
    ],
    "metadata": {
      "model": "doubao-seedream-5.0-flash",
      "usage": {
        "input_images": 1,
        "total_tokens": 41704,
        "output_tokens": 41704,
        "generated_images": 8
      },
      "images": [
        {
          "size": "1152x2048",
          "z_index": 0,
          "output_index": 0,
          "output_format": "png"
        },
        {
          "size": "698x752",
          "z_index": 1,
          "output_index": 1,
          "output_format": "png",
          "name": "背景行人",
          "description": "画面左侧背景中的行人。",
          "bounding_box": {
            "absolute": [0, 1009, 327, 1363],
            "normalized": [0, 493, 283, 665]
          }
        },
        {
          "size": "504x955",
          "z_index": 2,
          "output_index": 2,
          "output_format": "png",
          "name": "竖向招牌",
          "description": "街道两侧的竖向灯箱与招牌。",
          "bounding_box": {
            "absolute": [111, 0, 615, 955],
            "normalized": [96, 0, 533, 466]
          }
        },
        {
          "size": "750x935",
          "z_index": 3,
          "output_index": 3,
          "output_format": "png",
          "name": "中央显示屏",
          "description": "画面中央的电子显示屏。",
          "bounding_box": {
            "absolute": [206, 617, 436, 904],
            "normalized": [179, 301, 378, 441]
          }
        },
        {
          "size": "590x1329",
          "z_index": 4,
          "output_index": 4,
          "output_format": "png",
          "name": "右侧店铺招牌",
          "description": "画面右侧店铺的招牌与装饰。",
          "bounding_box": {
            "absolute": [884, 483, 1152, 1086],
            "normalized": [767, 236, 999, 530]
          }
        },
        {
          "size": "1130x608",
          "z_index": 5,
          "output_index": 5,
          "output_format": "png",
          "name": "顶部拱门",
          "description": "画面上方的拱门与灯光装饰。",
          "bounding_box": {
            "absolute": [0, 429, 619, 762],
            "normalized": [0, 209, 536, 372]
          }
        },
        {
          "size": "480x1245",
          "z_index": 6,
          "output_index": 6,
          "output_format": "png",
          "name": "右侧人物",
          "description": "画面右侧背景中的持伞人物。",
          "bounding_box": {
            "absolute": [764, 995, 1023, 1667],
            "normalized": [663, 486, 887, 813]
          }
        },
        {
          "size": "983x1366",
          "z_index": 7,
          "output_index": 7,
          "output_format": "png",
          "name": "前景人物",
          "description": "画面前景中的主要人物及服饰。",
          "bounding_box": {
            "absolute": [106, 682, 1089, 2048],
            "normalized": [92, 333, 944, 1000]
          }
        }
      ],
      "image_sizes": [
        "1152x2048",
        "698x752",
        "504x955",
        "750x935",
        "590x1329",
        "1130x608",
        "480x1245",
        "983x1366"
      ],
      "output_format": "png",
      "generated_images": 8,
      "settlement_reason": null,
      "settlement_status": "settled",
      "layer_decomposition": true,
      "requested_image_count": 17,
      "result_url_expires_in": 86400,
      "source_url_expires_in": 86400
    }
  }
}

常见错误码

请求失败时,API 返回 JSON 格式的错误响应:

{
  "error": {
    "code": "insufficient_credits",
    "message": "Your credit balance is too low. Please top up.",
    "type": "billing_error"
  }
}

错误码一览

HTTP 状态码错误码类型说明
400invalid_requestinvalid_request_error缺少必填参数或参数无效
401invalid_api_keyauthentication_errorAPI Key 无效、已禁用或已删除
402insufficient_creditsbilling_error积分余额不足,请充值
403ip_not_allowedpermission_error请求 IP 不在 Key 的白名单中
404model_not_foundinvalid_request_error模型不存在或已停用
404task_not_foundinvalid_request_error任务 ID 不存在
429rate_limit_exceededrate_limit_error请求过于频繁,请降低频率
429spend_limit_exceededbilling_error达到 Key 的消费限额(每小时/每天/总量)
500internal_errorapi_error服务器内部错误
503upstream_errorupstream_error上游 AI 服务返回错误

常见场景

invalid_request (400)

缺少必填字段或参数格式错误时返回。

{
  "error": {
    "code": "invalid_request",
    "message": "'model' is required.",
    "type": "invalid_request_error"
  }
}

insufficient_credits (402)

积分不足。可通过 GET /v1/credits 查询余额,前往 Dashboard > Billing 充值。

invalid_api_key (401)

可能原因:

  • Key 不以 sk- 开头
  • Key 已被禁用或删除
  • 用户账户已被封禁

upstream_error (503)

上游 AI 服务返回错误,可能原因:

  • 输入内容包含敏感或违规信息
  • 上游服务暂时不可用
  • 请求参数不被上游支持

因上游错误导致任务失败时,预扣积分会自动退还。