> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dreamto.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Fine-grained layer decomposition

> Split one image into a base image and up to 99 independently editable transparent layers, with control over the maximum number of output images.

Layer decomposition automatically splits the subjects, background, text and other content of one image into **one base image** and **several independently editable layers**. Each layer is a PNG with an alpha channel and comes with its position on the base image, ready for further editing and compositing in a design tool or your own application. Set `layer_decomposition` to `true` to enable it.

| Seedream 5.5 enhancement | Description |
| - | - |
| More layers | A request returns up to 100 images: one base image and up to 99 layers |
| Controllable output count | `layer_decomposition_options.max_images` caps the base image plus the layers, 2–100, default 30 (one base image and up to 29 layers) |
| Rich-text OCR | Optionally returns the text, position and approximate styles of regular text layers; see [Rich-text OCR](https://docs.dreamto.ai/en/image/models/seedream-5-5/rich-text-ocr.md) |

> [!NOTE]
>
> When the prompt does not say how to decompose the image, or is unclear, the model plans the decomposition from `max_images` and the complexity of the input image. A larger `max_images` generally gives a finer decomposition.

## Example

The example separates every animal of an illustration into its own layer and leaves everything else in the base image. With `max_images: 40`, the response returns 33 images: one base image and 32 animal layers.

| Input | Base image | Layer overview |
| - | - | - |
| ![Illustrated forest, river, and camping scene with animals](https://arkdocs-en.tos-ap-southeast-1.volces.com/images/image-generation/animal-test.jpeg) | ![Base image of the animal scene](https://arkdocs-en.tos-ap-southeast-1.volces.com/images/image-generation/seedream-5-5-animal-base-20261104.png) | ![32 independent animal layers ordered by z\_index](https://arkdocs-en.tos-ap-southeast-1.volces.com/images/image-generation/seedream-5-5-animal-layers-overview-transparent-20261104.png) |

> For display, the layer overview combines the 32 output layers into one image. It is not an image generated by the model.

Some of the original transparent PNG layers (the numbers are the `z_index` values of the response):

| Layer 1: Bald eagle | Layer 7: Giant panda | Layer 11: Zebra | Layer 17: Lion | Layer 24: Fox | Layer 32: Frog |
| - | - | - | - | - | - |
| ![Layer 1: Bald eagle](https://arkdocs-en.tos-ap-southeast-1.volces.com/images/image-generation/seedream-5-5-animal-layer-01-20261104.png) | ![Layer 7: Giant panda](https://arkdocs-en.tos-ap-southeast-1.volces.com/images/image-generation/seedream-5-5-animal-layer-07-20261104.png) | ![Layer 11: Zebra](https://arkdocs-en.tos-ap-southeast-1.volces.com/images/image-generation/seedream-5-5-animal-layer-11-20261104.png) | ![Layer 17: Lion](https://arkdocs-en.tos-ap-southeast-1.volces.com/images/image-generation/seedream-5-5-animal-layer-17-20261104.png) | ![Layer 24: Fox](https://arkdocs-en.tos-ap-southeast-1.volces.com/images/image-generation/seedream-5-5-animal-layer-24-20261104.png) | ![Layer 32: Frog](https://arkdocs-en.tos-ap-southeast-1.volces.com/images/image-generation/seedream-5-5-animal-layer-32-20261104.png) |

> [!TIP]
>
> Download the official [full example package (ZIP, about 67 MB)](https://arkdocs-en.tos-ap-southeast-1.volces.com/files/image-generation/seedream-5-5-animal-layers-20261104-v3.zip) with the base image, the 32 transparent animal layers and an interactive preview page: extract it, open `preview.html` in a browser and select the layer cards to show or hide layers and inspect the reconstructed image.

## Request

`$DREAMTO_API_KEY` is your API Key.

```bash cURL theme={null}
curl -X POST "https://api.dreamto.ai/api/v3/images/generations" \
  -H "Authorization: Bearer $DREAMTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "seedream-5.5",
    "prompt": "Separate each animal into a complete, independent layer, including animals of the same species. Preserve the appearance, colors, pose, white outline, and original position of each animal. Keep all non-animal elements in the base image and naturally fill the areas left after the animals are removed.",
    "image": "https://arkdocs-en.tos-ap-southeast-1.volces.com/images/image-generation/animal-test.jpeg",
    "size": "2K",
    "layer_decomposition": true,
    "layer_decomposition_options": {
      "max_images": 40,
      "text_recognition": true
    },
    "output_format": "png",
    "response_format": "url",
    "watermark": true
  }'
```

```python Python theme={null}
import os

import requests

URL = "https://api.dreamto.ai/api/v3/images/generations"
HEADERS = {"Authorization": f"Bearer {os.environ['DREAMTO_API_KEY']}"}

payload = {
    "model": "seedream-5.5",
    "prompt": "Separate each animal into a complete, independent layer, including animals of the same species. Preserve the appearance, colors, pose, white outline, and original position of each animal. Keep all non-animal elements in the base image and naturally fill the areas left after the animals are removed.",
    "image": "https://arkdocs-en.tos-ap-southeast-1.volces.com/images/image-generation/animal-test.jpeg",
    "size": "2K",
    "layer_decomposition": True,
    "layer_decomposition_options": {
        "max_images": 40,
        "text_recognition": True
    },
    "output_format": "png",
    "response_format": "url",
    "watermark": True
}

result = requests.post(URL, headers=HEADERS, json=payload, timeout=600).json()
for image in result["data"]:
    print(image["url"])
```

```python OpenAI SDK theme={null}
import os

from openai import OpenAI

client = OpenAI(base_url="https://api.dreamto.ai/api/v3", api_key=os.environ["DREAMTO_API_KEY"])

response = client.images.generate(
    model="seedream-5.5",
    prompt="Separate each animal into a complete, independent layer, including animals of the same species. Preserve the appearance, colors, pose, white outline, and original position of each animal. Keep all non-animal elements in the base image and naturally fill the areas left after the animals are removed.",
    size="2K",
    output_format="png",
    response_format="url",
    extra_body={
        "image": "https://arkdocs-en.tos-ap-southeast-1.volces.com/images/image-generation/animal-test.jpeg",
        "layer_decomposition": True,
        "layer_decomposition_options": {
            "max_images": 40,
            "text_recognition": True
        },
        "watermark": True,
    },
)
for item in response.data:
    print(item)
```

## Rules

* **One image to decompose only**: `image` is a string or an array with a single element (`png` / `jpeg`, 262,144–36,000,000 total pixels, aspect ratio 1/16–16, up to 30 MB). Several images, or none, return 400.
* **`prompt` is optional**: without it the model identifies the main elements of the image and separates them into layers; with it the model follows the intent of the prompt. To mark exact regions, give the coordinates of the elements to separate with `<bbox>left top right bottom</bbox>` in the prompt.
* **`size` takes a resolution tier only**: `1K` / `1.5K` / `2K` or `auto` (default), not `WIDTHxHEIGHT`. The base image is output at the resolution given by `size` with the aspect ratio of the source image; each layer at a resolution close to `size` with its own aspect ratio in the source image. `auto` follows the source size: sizes between `1280x720` and `2048x2048` × 1.1025 are kept, smaller ones are output at 1K and larger ones at 2K.
* **`output_format` only sets the base image**: layers are always returned as `png`.
* **`background` is not accepted**: layer decomposition always returns transparent PNG layers and passing it returns 400.
* **No partial success**: if any layer fails, the whole request fails and is not charged.
* If the prompt asks for more layers than the limit, some layer information may be lost.

## Response

The first item of `data[]` is the base image (`z_index` 0; it covers the whole canvas and has no `bounding_box`); each following item is a layer:

| Field | Meaning |
| - | - |
| `z_index` | Stacking order: the base image is 0 and layers count up from 1; larger is higher |
| `name` | Layer name, generated by the model from the layer content |
| `description` | Detailed description of the layer, with features such as color, state and material |
| `bounding_box.absolute` | Pixel coordinates `[left, top, right, bottom]` of the layer on the output base image; the top-left of the base image is `(0, 0)` |
| `bounding_box.normalized` | The same box as integers 0–1000 relative to the base image size |
| `size` / `output_format` / `background` | Actual size, format and transparency of the image |

```json theme={null}
{
  "model": "seedream-5.5",
  "created": 1784696685,
  "data": [
    {
      "url": "https://files.dreamto.ai/images/seedream_base_1c9e.png",
      "size": "2048x2048",
      "output_format": "png",
      "z_index": 0
    },
    {
      "url": "https://files.dreamto.ai/images/seedream_layer_1_4a7d.png",
      "size": "1273x265",
      "output_format": "png",
      "background": "transparent",
      "z_index": 1,
      "name": "Seedream title text",
      "description": "Large yellow Seedream title text in a serif font",
      "bounding_box": {
        "absolute": [
          383,
          120,
          1655,
          384
        ],
        "normalized": [
          187,
          59,
          808,
          188
        ]
      }
    }
  ],
  "usage": {
    "input_images": 1,
    "generated_images": 2,
    "output_tokens": 17701,
    "total_tokens": 17701
  }
}
```

## Restore the layers

**On the output base image**, use `bounding_box.absolute`. For example `[225, 442, 796, 1414]` means the top-left corner of the layer is `(225, 442)` and the bottom-right corner is `(796, 1414)`:

* Top-left position of the layer: `x = left`, `y = top`;
* Width occupied by the layer: `w = right - left`; height: `h = bottom - top`;
* Scale the output layer to `w × h` and place it at `(x, y)` on the base image.

**On any canvas** (`W` × `H`), use `bounding_box.normalized`. For example `[220, 432, 777, 1000]` means the left edge of the layer is 22.0% of the width from the left, the top edge 43.2% of the height from the top, the right edge at 77.7% and the bottom edge on the bottom of the canvas:

* `x = left / 1000 × W`, `y = top / 1000 × H`;
* `w = (right - left) / 1000 × W`, `h = (bottom - top) / 1000 × H`;
* Normalized coordinates are integers, so rounding errors may occur.

Stack several layers in ascending `z_index`.

## Billing and balance check

The base image and every layer are billed by their own actual size (`data[].size`), plus one input image for the image being decomposed; one request can contain both price tiers. Before the call the balance is checked for `max_images` (default 30) images; with an insufficient balance the request returns 402 and the model is not called. Only the images actually returned are charged, so a fitting `max_images` lowers the balance needed for the check. A request with many layers can take several minutes; set the client read timeout to at least 300 seconds.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.