---
name: unmerge
description: Split a flat image (PNG, JPG or WebP) into separate transparent PNG layers with Unmerge, with the hidden parts behind objects filled in. Use when the user wants to separate an image into layers, pull a subject or text off its background as its own layer, make an editable layered version of a poster, illustration or screenshot, or "unflatten" an image. Needs an Unmerge API key in UNMERGE_API_KEY.
author: Unmerge
version: 1.0.0
tags: [image, layers, background-removal, design, mcp]
---

# Unmerge: split an image into layers

Unmerge takes one flat image and returns named transparent PNG layers (for example "Background", "Person", "Title"), each with its position on the canvas. Hidden parts behind objects are filled in, so each layer can be moved on its own.

## Before you start

- The user needs an API key from https://unmerge.app/account/api, set as `UNMERGE_API_KEY`. Never print the key or write it into a file.
- Cost: 1 credit per layer returned, at most 17 layers per image. A split needs at least 5 credits to start. Check with `get_credits` (or `GET /api/v1/credits`) before a batch and tell the user what it will cost.
- Images: PNG, JPG or WebP, up to 10 MB and 4 megapixels.

## With the MCP tools

If the `unmerge` MCP server is connected (tools `split_into_layers`, `get_layers`, `unlock_layers`, `get_credits`), use them:

1. `split_into_layers` with `image_url` (public https) or `image_base64`. Add `prompt` only when the user said what to separate, in plain words, for example "the cat, the sofa and the background".
2. It waits up to 50 seconds. If the status is still `processing`, call `get_layers` with the `project_id` until it is `ready`.
3. When `ready`, each layer has `name`, `bounds` ([x1, y1, x2, y2], null for a full background), `z_index` and a PNG `url` that works for one hour. Download the files the user wants right away.
4. Status `needs_credits` means the model returned more layers than the credits held. Tell the user how many credits are owed (`credits.owed`) and call `unlock_layers` only if they agree.

## With the HTTP API

Without MCP, call the API with curl. The base is `https://unmerge.app/api/v1`.

Start a split from a local file:

```bash
curl https://unmerge.app/api/v1/layers \
  -H "Authorization: Bearer $UNMERGE_API_KEY" \
  -H "Idempotency-Key: poster-001" \
  -F file=@poster.png \
  -F prompt="the title, the person and the background"
```

Or send JSON with `image_url` or `image_base64` instead of `file`. The response is 202 with the project `id`. Reuse the same `Idempotency-Key` when retrying so the image is not split twice.

Poll until the status is no longer `processing`:

```bash
curl https://unmerge.app/api/v1/layers/<id> \
  -H "Authorization: Bearer $UNMERGE_API_KEY"
```

Status is one of `uploaded`, `processing`, `ready`, `needs_credits`, `failed`, `expired`. Wait a few seconds between polls. Layer URLs expire after an hour; get the project again for fresh ones.

Other calls:

- `POST /api/v1/layers/<id>/unlock` pays `credits.owed` for a `needs_credits` project (ask the user first).
- `GET /api/v1/credits` returns `{ "credits": n }`.

## Errors

| Status | Code | What to do |
| --- | --- | --- |
| 401 | `unauthorized` | Key missing, wrong or revoked; ask the user to check `UNMERGE_API_KEY`. |
| 402 | `insufficient_credits` | Fewer than 5 credits, or not enough to unlock. Point the user to https://unmerge.app/pricing. |
| 400 | `image_fetch_failed` | The URL could not be downloaded over https in 10 seconds; send the file or base64 instead. |
| 413, 415 | `too_large`, `too_many_pixels`, `unsupported_type` | Resize or convert to PNG/JPG/WebP under 10 MB and 4 megapixels. |
| 429 | `rate_limited`, `too_many_uploads` | Over 120 requests a minute, or the weekly upload limit; slow down. |
| 503 | `not_open` | The API is off for now; try later. |

Full docs: https://unmerge.app/docs/api and https://unmerge.app/docs/mcp
