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

# Layer Decomposition

> Split an image into a base image plus independently editable PNG layers.

Hand Mesh one flat image and get back a base image plus independently editable PNG
layers — background, product shot, headline — each with its own stacking order,
bounding box and name. No cutting the result up yourself.

Available on `bytedance/seedream-5.5`.

## Split an image

> [tab] curl
>
> ```bash theme={null}
> curl https://api.meshapi.ai/v1/images/generations \
>   -H "Authorization: Bearer rsk_YOUR_KEY" \
>   -H "Content-Type: application/json" \
>   -d '{
>     "model": "bytedance/seedream-5.5",
>     "prompt": "split this poster into editable layers",
>     "image": "https://example.com/poster.png",
>     "layer_decomposition": true,
>     "size": "2K"
>   }'
> ```

> [tab] Python
>
> ```python theme={null}
> from openai import OpenAI
>
> client = OpenAI(api_key="rsk_...", base_url="https://api.meshapi.ai/v1")
>
> response = client.images.generate(
>     model="bytedance/seedream-5.5",
>     prompt="split this poster into editable layers",
>     size="2K",
>     extra_body={
>         "image": "https://example.com/poster.png",
>         "layer_decomposition": True,
>     },
> )
> for item in response.data:
>     print(item.model_extra.get("z_index"), item.url)
> ```

`image` takes a URL or a `data:image/png;base64,…` URI.

## Request fields

| Field | Type | Description |
| - | - | - |
| `layer_decomposition` | boolean | Turn the split on. |
| `layer_decomposition_options.max_images` | integer, `2`–`100` | Ceiling on base image **plus** layers. Omit it and the provider decides. |
| `layer_decomposition_options.text_recognition` | boolean | Return rich-text OCR for each formatted-text layer. |

```json theme={null}
{
  "model": "bytedance/seedream-5.5",
  "prompt": "split this poster into editable layers",
  "image": "https://example.com/poster.png",
  "layer_decomposition": true,
  "layer_decomposition_options": { "max_images": 30, "text_recognition": true },
  "background": "transparent",
  "output_format": "png",
  "size": "2K"
}
```

## Response

Every entry in `data[]` is one image and carries its own metadata.

| Field | Description |
| - | - |
| `z_index` | Stacking order. **`0` is the base image**; layers count up from there. |
| `bounding_box` | Where the layer sits in the base image's coordinates (`absolute` and `normalized`). |
| `name` | Short label for the layer, e.g. `headline`. |
| `description` | What the layer contains. |
| `size` | That image's real pixel dimensions, e.g. `1776x2368`. |
| `output_format` | `png`, `jpeg` or `webp` — per item, since base and layers can differ. |
| `background` | `transparent` or `opaque`. |
| `text_recognition` | `{ text, lines[] }`. Only with `text_recognition: true`, and only on formatted-text layers. |

```json theme={null}
{
  "created": 1762790400,
  "data": [
    {
      "url": "https://.../base.png",
      "z_index": 0,
      "size": "1776x2368",
      "background": "opaque"
    },
    {
      "url": "https://.../layer-1.png",
      "z_index": 1,
      "size": "1654x817",
      "background": "transparent",
      "name": "headline",
      "description": "FLASH SALE in red",
      "bounding_box": { "absolute": [9, 0, 1654, 817] },
      "text_recognition": { "text": "FLASH SALE", "lines": [] }
    }
  ]
}
```

A field appears only when the provider reported it, so an ordinary generation does not
grow a wall of nulls.

### Streaming

`"stream": true` works, and the final chunk carries the same per-item metadata as the
buffered response — a layer is only placeable with its `z_index` and `bounding_box`, so
the two shapes are guaranteed to agree.

## Where it is accepted

> [!WARNING]
>
> `layer_decomposition` is accepted on **`POST /v1/images/generations` only**.
>
> Sending it on `/v1/chat/completions` or `/v1/messages` is a `400`: a chat content part
> carries only a URL, so layers would arrive with no `z_index` or `bounding_box` and could
> not be placed. `/v1/images/edits` does not accept the fields.

## Refusals

A request asking for layers either gets layers or is told why not — it never silently
falls back to one flat image. All of these are `400`.

| What you sent | What happens |
| - | - |
| A model without the feature | Refused by name. Nothing is generated and nothing is billed. |
| `"model": "auto"` | Refused. The router ranks on quality and cost and cannot narrow its pool by this capability, so it would reach a capable model only by luck — name the model instead. |
| `layer_decomposition` on `/v1/chat/completions` | Refused as an unsupported parameter for that endpoint. |
| `"n": 2` | Refused — `bytedance/seedream-5.5` has no group generation. Use `layer_decomposition_options.max_images` to control how many images come back. |

If the capable model fails transiently, a fallback alternate that cannot decompose is
dropped from the routing plan rather than served, so your result is never silently
downgraded.

## Pricing

Every returned image is billed, base image included — a 30-layer split is 30 images, not
one. Each is charged at the tier of the `size` **you requested**:

| Requested `size` | Per image |
| - | - |
| omitted, `1K` (≤ 2.61 MP) | \$0.02 |
| `2K` / `4K` (≤ 4.63 MP) | \$0.035 |

The input image is \$0.008.

> [!WARNING]
>
> Two things to plan for:
>
> * **Cost scales with `max_images`.** Thirty layers at `2K` is roughly \$1.05 plus input.
>   Set `max_images` to what you will actually use.
> * **The balance hold is sized against the ceiling.** With `max_images` set, the hold
>   covers that many images; omit it and the hold assumes the maximum of 100. Run layer
>   requests on a key with headroom. The hold is released when the request finishes, and
>   you are charged for what was actually returned.

> [!NOTE]
>
> Check `GET /v1/models` for live pricing on `bytedance/seedream-5.5`.


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