> For the complete documentation index, see [llms.txt](https://bountyv.gitbook.io/vdocs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bountyv.gitbook.io/vdocs/image-api/images-edit.md).

# Image Edit

Apply an instruction-based edit to an uploaded image. Two engines: `flux2` (FLUX.2 ReferenceLatent edit) and `qwen` (Qwen-Image-Edit). Preset `mode`s carry their own instruction; `custom` uses your `prompt`.

```
POST /api/v1/images/edit
```

Synchronous — the edited image is returned directly in the response body.

## Authentication

```
Authorization: Bearer sk_live_...
```

See [Authentication](/vdocs/authentication.md).

## Request

**Content-Type:** `multipart/form-data` — see [Uploading files](/vdocs/uploading-files.md).

| Field             | Type    | Required | Default    | Description                                                                                                               |
| ----------------- | ------- | -------- | ---------- | ------------------------------------------------------------------------------------------------------------------------- |
| `image`           | file    | ✅        | —          | The image to edit. **Repeatable on `qwen`** (max 2, or `image[]`) — see [Second reference image](#second-reference-image) |
| `engine`          | string  | —        | `"flux2"`  | `"flux2"` or `"qwen"`                                                                                                     |
| `mode`            | string  | —        | `"custom"` | Engine-specific edit mode (see below)                                                                                     |
| `prompt`          | string  | —        | —          | Edit instruction. Required when `mode=custom` (empty otherwise — preset modes carry their own instruction server-side)    |
| `foundation`      | string  | —        | `"snofs"`  | `flux2` only — `"snofs"` or `"base"`                                                                                      |
| `a2r_level`       | string  | —        | —          | `flux2` `anime2real` strength — `"light"` \| `"strong"` \| `"max"`                                                        |
| `add_skin`        | boolean | —        | —          | `flux2` only — `"true"` runs the skin/portrait pass                                                                       |
| `negative_prompt` | string  | —        | —          | Extra negatives                                                                                                           |
| `seed`            | integer | —        | —          | Reproducibility                                                                                                           |
| `steps`           | integer | —        | —          | Diffusion steps                                                                                                           |

### Second reference image

`engine=qwen` runs Qwen-Image-Edit-2509, which conditions on two images. Send `image` twice (or use `image[]`): the first is the subject, the second is what you're applying to it — a garment to dress the person in, an object to place, a style to carry across. This is the mechanism behind the `outfit_extract` mode.

| Engine  | Max `image` files |
| ------- | ----------------- |
| `qwen`  | 2                 |
| `flux2` | 1                 |

The model itself accepts a third reference; our deployed graph wires two. Over the cap returns `400` with a `max_reference_images` field.

### Modes

* **`flux2`:** `undress` · `add_cum` · `ruined_makeup` · `anime2real` · `custom`
* **`qwen`:** `undress` · `solo` · `couples` · `outfit_extract` · `selfie` · `selfie_nude` · `custom`

An unrecognized `mode` falls back to `custom`.

## Response

```json
{
  "image": "https://.../generations/<id>.png?token=...",
  "generation_id": "gJ8nP3kQ2m",
  "engine": "flux2",
  "charged_cents": 25,
  "balance_cents": 4775,
  "elapsed_ms": 9210
}
```

| Field           | Type            | Description                                                                                                      |
| --------------- | --------------- | ---------------------------------------------------------------------------------------------------------------- |
| `image`         | string          | Edited image. A time-limited signed URL when the generation persists to storage, otherwise an inline `data:` URL |
| `generation_id` | string \| null  | Generation record ID, or `null` if persistence failed                                                            |
| `engine`        | string          | The engine that ran                                                                                              |
| `charged_cents` | integer         | Amount deducted from your balance for this call                                                                  |
| `balance_cents` | integer         | Remaining balance                                                                                                |
| `elapsed_ms`    | integer \| null | Edit time in milliseconds                                                                                        |

## Example

```bash
curl -X POST https://substance-api.com/api/v1/images/edit \
  -H "Authorization: Bearer sk_live_..." \
  -F "image=@input.png" \
  -F "engine=flux2" \
  -F "mode=undress"
```

## Errors

| Status | When                                                                                                   |
| ------ | ------------------------------------------------------------------------------------------------------ |
| `400`  | Missing `image`; missing `prompt` for `mode: "custom"`; or the prompt is rejected by the safety filter |
| `401`  | Missing/invalid API key                                                                                |
| `402`  | Insufficient credits                                                                                   |
| `403`  | `nsfw` entitlement not enabled on your account                                                         |
| `503`  | Pipeline temporarily disabled                                                                          |
| `502`  | Edit failed upstream. Balance is refunded automatically                                                |

See [Errors](/vdocs/errors.md) for the general error format.

## Pricing

Billed per call — see [Credits & pricing](/vdocs/account/credits.md) for current rates. Rate varies by `engine`.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://bountyv.gitbook.io/vdocs/image-api/images-edit.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
