Skip to content

Seedream 5.0 Pro / Flash ​

Seedream 5.0 Pro and Flash support text-to-image generation, reference-image editing, multi-image composition, interactive editing, and layer decomposition through a JSON image generation endpoint.

Endpoint and models ​

http
POST /v1/images/generations
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json
Model IDDescription
doubao-seedream-5-0-proPro, with standard and fast prompt optimization
doubao-seedream-5-0-flashFlash, with standard prompt optimization

This guide covers Pro and Flash only. The domestic production endpoint is https://cubicspace.cn; use an API key issued for this environment and the stable model IDs listed above.

This is a synchronous API: one POST returns image results directly, without a task ID to poll. Normal generation returns one image; decomposition returns a base image and multiple layers.

Generate an image ​

bash
export CUBICSPACE_API_KEY="YOUR_API_KEY"
curl --max-time 420 https://cubicspace.cn/v1/images/generations \
  -H "Authorization: Bearer $CUBICSPACE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "doubao-seedream-5-0-pro",
    "prompt": "Create a landscape poster for a coffee brand, with warm colors and a clear title",
    "size": "1.5K",
    "output_format": "png",
    "response_format": "url",
    "watermark": false
  }'

To use Flash, change model to doubao-seedream-5-0-flash.

Parameters ​

FieldTypeDescription
modelstringOne of the model IDs above
promptstringRequired for generation; optional for automatic layer decomposition
imagestring / string[]Reference URLs or data:image/png;base64,...; up to 10 references for generation, exactly 1 for decomposition
sizestringGeneration: 1K, 1.5K, 2K (default), or supported widthxheight dimensions
layer_decompositionbooleanEnable layer decomposition; defaults to false
output_formatstringjpeg or png; controls only the base image during decomposition, since individual layers are always PNG
response_formatstringurl (default) or b64_json
watermarkbooleanWhether to add a watermark; explicit false is preserved
backgroundstringopaque or transparent; transparency requires one reference with an alpha channel and is incompatible with JPEG output
optimize_prompt_options.modestringstandard; Pro also accepts fast

For explicit generation dimensions, the pixel count must be between 921,600 and 4,624,220, with an aspect ratio between 1:16 and 16:1. When using resolution presets, describe the desired layout or aspect ratio in prompt.

Layer decomposition accepts 1K, 1.5K, 2K, or auto (default), rather than explicit dimensions. Each returned image's actual dimensions appear in data[].size.

Pro and Flash do not support streaming, sequential generation, or web search. Omit stream, sequential_image_generation, sequential_image_generation_options, and tools. If supplied, n must be 1. Image editing also uses this JSON endpoint, with references in the top-level image field.

Reference-image editing ​

Add image to the request. Use a string for one reference, or an array for multiple references:

json
{
  "model": "doubao-seedream-5-0-flash",
  "prompt": "Keep the person and pose from image one, and use the clothing design from image two",
  "image": ["https://example.com/person.png", "https://example.com/clothes.png"],
  "size": "2K",
  "response_format": "url"
}

For interactive editing, describe the region to change using coordinates, boxes, or arrow annotations in the prompt and reference image.

Layer decomposition ​

json
{
  "model": "doubao-seedream-5-0-pro",
  "image": "https://example.com/poster.png",
  "layer_decomposition": true,
  "size": "auto",
  "output_format": "jpeg",
  "response_format": "url"
}

The response contains one base image and up to 16 independent layers. Add prompt to specify which elements to separate.

Response ​

Example of a simplified layer response:

json
{
  "model": "doubao-seedream-5-0-pro",
  "created": 1784696685,
  "data": [
    {"url": "https://example.com/base.jpg", "size": "2048x2048", "output_format": "jpeg", "z_index": 0},
    {
      "url": "https://example.com/title.png",
      "size": "1000x400",
      "output_format": "png",
      "z_index": 1,
      "name": "Title",
      "description": "Title text at the top of the poster",
      "bounding_box": {"absolute": [100, 100, 600, 300], "normalized": [49, 49, 293, 146]}
    }
  ],
  "usage": {"input_images": 1, "generated_images": 2, "output_tokens": 100, "total_tokens": 100}
}

Regular generation also returns a data array. For base64 output, read data[].b64_json. Layer metadata includes z_index (the base image is 0), names, descriptions, and bounding boxes. Image URLs normally expire after 24 hours, so save your results promptly.

usage.input_images counts input images and usage.generated_images counts successful outputs, including the base image during decomposition. output_tokens and total_tokens describe the returned usage. The JSON above illustrates the structure; actual dimensions, layer counts and usage depend on the response.

Reference-image requirements ​

Replace all example.com placeholders with directly accessible image URLs. Local paths, login-protected pages and HTML preview pages cannot be used as image URLs.

For a single edit, pass a string in image:

json
{
  "model": "doubao-seedream-5-0-flash",
  "prompt": "Keep the composition and title. Change only the blue circle to green.",
  "image": "https://example.com/poster.png",
  "size": "1.5K",
  "output_format": "png",
  "response_format": "url",
  "watermark": false
}

Encode local files as complete data URLs, including the lowercase MIME type:

python
import base64
from pathlib import Path

image = "data:image/png;base64," + base64.b64encode(
    Path("reference.png").read_bytes()
).decode("ascii")

Normal reference inputs support JPEG, PNG, WebP, BMP, TIFF, GIF, HEIC and HEIF. Each image must be at most 30 MB and 36 million pixels, with both dimensions greater than 14 pixels and an aspect ratio between 1:16 and 16:1. Decomposition accepts PNG/JPEG only, from 512×512 to 36 million total pixels, at most 30 MB.

Flash supports the same decomposition parameters as Pro. A failure to generate any layer fails the entire decomposition request; partial success is not returned. Individual layers can be much smaller than the minimum size for normal image generation. Do not stretch each layer over the full base image.

Restore layer positions ​

Draw images in ascending z_index order. The base image covers the canvas and normally has no bounding_box.

  • absolute contains [left, top, right, bottom] in base-image pixels. Position the layer at (left, top) with dimensions (right-left, bottom-top).
  • normalized uses the same boundaries on a 0–1000 scale. For a target canvas of W by H, position the layer at (left/1000×W, top/1000×H) and size it to ((right-left)/1000×W, (bottom-top)/1000×H).
  • Preserve PNG transparency and resize each layer to its bounding region. Names and descriptions identify content; use z_index for ordering.

A layer file's size can differ from its bounding region and can even exceed one dimension of the base image. Use bounding_box to restore its display region instead of using the file's pixel dimensions as its on-canvas dimensions.

Complete Python example ​

This example uses only the Python standard library. Set CUBICSPACE_API_KEY before running it. It supports both URL and Base64 responses; change response_format to url to use download links.

python
import base64
import json
import os
from pathlib import Path
from urllib.error import HTTPError
from urllib.request import Request, urlopen

base_url = os.getenv("CUBICSPACE_BASE_URL", "https://cubicspace.cn").rstrip("/")
payload = {
    "model": "doubao-seedream-5-0-flash",
    "prompt": "A clean poster: a red paper boat at left, a blue circle at right, title SPRING above, cream background.",
    "size": "1K",
    "output_format": "png",
    "response_format": "b64_json",
    "watermark": False,
}
# Editing: add payload["image"] = "https://.../reference.png".
# Decomposition: add image and layer_decomposition=True, and set size="auto".
# You may remove prompt to let the model identify the main elements.
request = Request(
    base_url + "/v1/images/generations",
    data=json.dumps(payload, ensure_ascii=False).encode("utf-8"),
    headers={
        "Authorization": "Bearer " + os.environ["CUBICSPACE_API_KEY"],
        "Content-Type": "application/json",
    },
    method="POST",
)
try:
    with urlopen(request, timeout=420) as response:
        result = json.load(response)
except HTTPError as error:
    raise RuntimeError(f"HTTP {error.code}: {error.read().decode('utf-8', errors='replace')}") from error

output = Path("seedream_output")
output.mkdir(exist_ok=True)
metadata = {**result, "data": []}
for index, item in enumerate(result["data"]):
    if item.get("b64_json"):
        content = base64.b64decode(item["b64_json"], validate=True)
    else:
        with urlopen(item["url"], timeout=90) as image_response:
            content = image_response.read()
    extension = item.get("output_format", "png")
    path = output / f"image_{index:02d}.{extension}"
    path.write_bytes(content)
    metadata["data"].append({k: v for k, v in item.items() if k != "b64_json"})
    print(path, item.get("size"), item.get("z_index"))
(output / "metadata.json").write_text(
    json.dumps(metadata, ensure_ascii=False, indent=2), encoding="utf-8"
)

Iterate over every data entry when saving layers; saving only data[0] loses the independent layers. Re-running this script overwrites files with the same names. Use a different output directory to retain earlier results.

Troubleshooting ​

SituationWhat to check
401 / authentication failureUse the correct environment's API key and Authorization: Bearer ...
403 / model unavailableCheck account and token model permissions
Invalid parametersCheck size, reference count, prompt and decomposition combinations; Flash does not accept fast prompt optimization
Cannot read an imageUse a direct image URL or a data URL with the correct MIME prefix
Slow response / client timeoutAllow enough time for this synchronous request; a timeout does not prove the operation failed, so do not repeatedly submit it
Misplaced layersSort by z_index and interpret bounding boxes in base-image coordinates

Do not automatically retry parameter, permission or authentication errors. Keep the error details and request ID for troubleshooting, and avoid recording or sharing API keys.