layer_decomposition to true to enable it.
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. Withmax_images: 40, the response returns 33 images: one base image and 32 animal layers.
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):
Request
$DREAMTO_API_KEY is your API Key.
Rules
- One image to decompose only:
imageis 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. promptis 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.sizetakes a resolution tier only:1K/1.5K/2Korauto(default), notWIDTHxHEIGHT. The base image is output at the resolution given bysizewith the aspect ratio of the source image; each layer at a resolution close tosizewith its own aspect ratio in the source image.autofollows the source size: sizes between1280x720and2048x2048× 1.1025 are kept, smaller ones are output at 1K and larger ones at 2K.output_formatonly sets the base image: layers are always returned aspng.backgroundis 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 ofdata[] is the base image (z_index 0; it covers the whole canvas and has no bounding_box); each following item is a layer:
Restore the layers
On the output base image, usebounding_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 × hand place it at(x, y)on the base image.
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.
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.









