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

> ## Agent Instructions
> Authenticate every request with your API key in the `X-API-Key` header or `Authorization: Bearer`. Keys start with `sk-nunchux-`.
> Image generation is synchronous: the image is in the response.
> Video generation is asynchronous: submit the job, poll its task until it reaches a terminal status, then download the output promptly, because output URLs expire.

# Image-to-image

> Edit an image, or combine several images, with a text prompt with a Nunchux Optimized model. The edited image is in the response.

# Image-to-image

Send a source image and a text prompt that describes the edit. Some models also take several source images, for example to put the subject of one image into the scene of another. The response contains the edited image. The request is synchronous. There is no task to poll.

## Models

| Model | Model ID | Source images | Use it for |
| - | - | - | - |
| FLUX.2 Klein 9B Edit | `nunchux-flux.2-klein-9b-edit` | Up to 4 | Edits that must keep the identity of the subject. |
| FLUX.2 Klein 4B Edit | `nunchux-flux.2-klein-4b-edit` | Up to 4 | The fastest edits. High-volume edit passes. The output follows the input image. |
| Qwen Image Edit 2511 Lightning | `nunchux-qwen-image-edit-2511-lightning` | Up to 3 | Targeted edits: swap elements, change the style, edit text in the image. The recommended editing model. |
| Qwen Image Edit 2511 | `nunchux-qwen-image-edit-2511` | Up to 3 | Full-step Qwen Image Edit 2511, in 40 steps, with a guidance control and a negative prompt. Slower than the Lightning model. |
| Qwen Image Edit 2509 Lightning | `nunchux-qwen-image-edit-2509-lightning` | Up to 3 | The earlier Qwen Image Edit release, in 8 steps, for work that already depends on it. |
| Qwen Image Edit 2509 | `nunchux-qwen-image-edit-2509` | Up to 3 | Full-step Qwen Image Edit 2509, in 40 steps, with a guidance control and a negative prompt. Slower than the Lightning model. |
| Qwen Image Edit | `nunchux-qwen-image-edit` | 1 | Full-step Qwen edits, with a guidance control and a negative prompt. Slower than the Lightning model. |
| FLUX.2 dev | `nunchux-flux.2-dev` | Up to 6 | Full-step FLUX edits, with a guidance control. The same model as FLUX.2 dev text-to-image. |
| FLUX 3 Image Klein Edit | `nunchux-flux.3-image-klein-edit` | Up to 10 | Edits and compositions of many images with the newest FLUX generation, in 16 steps. No guidance or negative prompt. |
| FLUX 3 Image Klein Base Edit | `nunchux-flux.3-image-klein-base-edit` | Up to 10 | The undistilled FLUX 3 Image Klein Edit, in 16 to 50 steps, with a guidance control and a negative prompt. Slower than FLUX 3 Image Klein Edit. |
| Qwen Image 2.1 Edit | `nunchux-qwen-image-2.1-edit` | Up to 10 | Edits up to 2752x2752, with a negative prompt. |

See [Choosing a model](https://docs.nunchux.ai/nunchux-optimized/overview.md#choosing-a-model) for a comparison, and [Performance tiers](https://docs.nunchux.ai/performance-tiers.md) for the tiers that each model serves.

## Endpoint

```text theme={"system"}
POST https://api.nunchux.com/v1/images/edits
```

## Request

Every request must include your API key and a JSON content type. See [Authentication](https://docs.nunchux.ai/authentication.md).

**X-API-Key** `string` *required*

Your API key.

**Content-Type** `string` *required*

Must be `application/json`.

**model** `string` *required*

The model that edits the image.

Options: `nunchux-flux.2-klein-4b-edit`, `nunchux-flux.2-klein-9b-edit`, `nunchux-qwen-image-edit-2511-lightning`, `nunchux-qwen-image-edit-2511`, `nunchux-qwen-image-edit-2509-lightning`, `nunchux-qwen-image-edit-2509`, `nunchux-qwen-image-edit`, `nunchux-flux.2-dev`, `nunchux-flux.3-image-klein-edit`, `nunchux-flux.3-image-klein-base-edit`, `nunchux-qwen-image-2.1-edit`

**url** `string`

The source image, as a data URI (for example `data:image/png;base64,...`) or as a public URL. Send the source image in `url` or in `image`, not in both. Supported formats: PNG, JPEG, WebP. Maximum size: 10 MB. Each side must be at least 64 px. The aspect ratio must be no more extreme than 8:1 in either orientation. A remote URL must resolve to a public host. Nunchux does not follow redirects.

When you send a data URI, Nunchux keeps a copy of the image so that it appears in your request history for 7 days.

**image** `string | array`

One source image, or a list of source images. Use a list to send more than one image. Each item follows the same rules as `url`: a data URI or a public URL. You can mix both kinds in one list. The model receives the images in the order of the list.

The number of images that each model takes is in the [Models](#models) table. A list with more images than the model takes, or an empty list, returns a 400 with the `invalid_request` code.

**prompt** `string` *required*

A text description of the edit. Say what to change, add or remove.

On Qwen Image 2.1 Edit, the prompt and the source images share 8192 positions. Each prompt token uses one. Each source image uses 64 when it is square, and up to 182 when it is long and narrow, such as 8:1. A request that needs more positions returns a 400 with `error.details.field` set to `prompt`.

**tier** `string` (default: radical\_speed)

The balance of speed and cost. See [Performance tiers](https://docs.nunchux.ai/performance-tiers.md).

Options: `radical_speed`, `radical_value`

Qwen Image Edit and FLUX.2 dev have `radical_speed` only. On them, `radical_value` returns a 400.

**width** `integer` *required*

Output width in pixels. Send it together with `height`. Range: 1 to 8192. On Qwen Image Edit, Qwen Image Edit 2511, Qwen Image Edit 2511 Lightning, Qwen Image Edit 2509, Qwen Image Edit 2509 Lightning and FLUX.2 dev: 256 to 2048, in steps of 16. On FLUX 3 Image Klein Edit and FLUX 3 Image Klein Base Edit: 256 to 4096, in steps of 16. On Radical Value, FLUX 3 Image Klein Edit and FLUX 3 Image Klein Base Edit take at most 4,194,304 pixels (`width` times `height`, the area of 2048x2048), so 4096x1024 works and 2576x1632 returns a 400. On Qwen Image 2.1 Edit: 256 to 2752, in steps of 32. A size that is a multiple of 16 but not of 32, such as 1040, returns a 400 on Qwen Image 2.1 Edit.

**height** `integer` *required*

Output height in pixels. Send it together with `width`. Range: 1 to 8192. On Qwen Image Edit, Qwen Image Edit 2511, Qwen Image Edit 2511 Lightning, Qwen Image Edit 2509, Qwen Image Edit 2509 Lightning and FLUX.2 dev: 256 to 2048, in steps of 16. On FLUX 3 Image Klein Edit and FLUX 3 Image Klein Base Edit: 256 to 4096, in steps of 16. On Radical Value, FLUX 3 Image Klein Edit and FLUX 3 Image Klein Base Edit take at most 4,194,304 pixels (`width` times `height`, the area of 2048x2048), so 4096x1024 works and 2576x1632 returns a 400. On Qwen Image 2.1 Edit: 256 to 2752, in steps of 32. A size that is a multiple of 16 but not of 32, such as 1040, returns a 400 on Qwen Image 2.1 Edit.

**n** `integer` (default: 1)

The number of images to generate. Only 1 is supported.

**response\_format** `string` (default: b64\_json)

The format of the returned image.

Options: `url`, `b64_json`

In both formats, Nunchux keeps the generated image for 7 days, so that it appears in your request history. Then Nunchux deletes it.

**steps** `integer`

Qwen Image Edit, Qwen Image Edit 2511, Qwen Image Edit 2511 Lightning, Qwen Image Edit 2509, Qwen Image Edit 2509 Lightning, FLUX.2 dev, FLUX 3 Image Klein Edit, FLUX 3 Image Klein Base Edit and Qwen Image 2.1 Edit only. The number of denoising steps. Range: 1 to 8 on the two Lightning models, 1 to 16 on FLUX 3 Image Klein Edit, 16 to 50 on FLUX 3 Image Klein Base Edit, 1 to 50 on the others. Default: 8 on the two Lightning models, 16 on FLUX 3 Image Klein Edit, 40 on Qwen Image Edit 2511, Qwen Image Edit 2509 and Qwen Image 2.1 Edit, 50 on the others. More steps give more detail, but take longer.

**true\_cfg\_scale** `number`

Qwen Image Edit, Qwen Image Edit 2511, Qwen Image Edit 2509 and Qwen Image 2.1 Edit only. How closely the edit follows the prompt, and how strongly it avoids the `negative_prompt`. Range: 0.0 to 20.0. Default: 4.0 on Qwen Image Edit, Qwen Image Edit 2511 and Qwen Image Edit 2509, 1.0 on Qwen Image 2.1 Edit.

On Qwen Image 2.1 Edit, the default 1.0 has no effect. Send a value above 1.0 together with `negative_prompt`.

**guidance\_scale** `number` (default: 4)

FLUX.2 dev and FLUX 3 Image Klein Base Edit only. How closely the edit follows the prompt. Range: 0.0 to 20.0. Default: 4.0.

**negative\_prompt** `string`

Qwen Image Edit, Qwen Image Edit 2511, Qwen Image Edit 2509, Qwen Image 2.1 Edit and FLUX 3 Image Klein Base Edit only. What the edited image must not show. On Qwen Image 2.1 Edit, it takes effect only when you also send `true_cfg_scale` above 1.0.

**prompt\_expansion** `string` (default: off)

FLUX 3 Image Klein Edit and FLUX 3 Image Klein Base Edit only. With `standard`, Nunchux rewrites the prompt into a detailed description of the result before the image renders. It adds about 3 to 4 seconds. The response returns the rewritten prompt as `revised_prompt`. FLUX 3 Image Klein Edit and FLUX 3 Image Klein Base Edit follow a full description much better than a short prompt, so send `standard` unless your prompt already describes the whole result.

Options: `off`, `standard`

**seed** `integer`

The random seed. The same seed with the same parameters gives the same result.

**content\_moderation** `boolean` (default: true)

Whether Nunchux's content filter checks this request. Only accounts approved to turn moderation off may send `false`. Others get a 403. See [Content moderation](https://docs.nunchux.ai/content-moderation.md).

> [!NOTE]
>
> Dimensions
>
> * Send `width` and `height` together. A request with only one of them returns a 400.
> * Every image-to-image model is priced per megapixel today and charges from the output area. A request with no dimensions returns a 400. The API does not use the source image size or a default size.
> * Both values must be integers. The string `"1024"` is rejected, not converted.
> * The source image is a reference, not a canvas. The model does not crop or stretch it to `width` and `height`. When the source ratio is different from the output ratio, the model re-frames the content. With several source images, `width` and `height` alone set the output size.
> * Smaller source images process faster. Larger output images take longer to generate.

A minimal request body:

```json theme={"system"}
{
  "model": "nunchux-qwen-image-edit-2511-lightning",
  "url": "https://example.com/example.jpg",
  "prompt": "Transform into a watercolor painting",
  "tier": "radical_speed",
  "width": 1024,
  "height": 1024,
  "response_format": "b64_json"
}
```

A request body for Qwen Image 2.1 Edit. Its `width` and `height` are multiples of 32:

```json theme={"system"}
{
  "model": "nunchux-qwen-image-2.1-edit",
  "url": "https://example.com/example.jpg",
  "prompt": "Transform into a watercolor painting",
  "tier": "radical_speed",
  "width": 1024,
  "height": 1024,
  "response_format": "b64_json"
}
```

A request body for FLUX 3 Image Klein Edit, with prompt expansion. The response returns the rewritten prompt in `data[0].revised_prompt`:

```json theme={"system"}
{
  "model": "nunchux-flux.3-image-klein-edit",
  "url": "https://example.com/example.jpg",
  "prompt": "Make it a rainy night",
  "prompt_expansion": "standard",
  "tier": "radical_speed",
  "width": 1024,
  "height": 1024,
  "response_format": "b64_json"
}
```

## Response

The response is JSON. The `data` array contains the edited image, as base64 data or as a URL.

**created** `integer` *required*

The Unix timestamp of the generation.

**data** `array` *required*

The generated items.

**Item properties**

**url** `string`

The URL of the image. Returned when `response_format` is `url`.

**b64\_json** `string`

The image as base64 data. Returned when `response_format` is `b64_json`.

**revised\_prompt** `string`

FLUX 3 Image Klein Edit and FLUX 3 Image Klein Base Edit only. The rewritten prompt that the model rendered. Returned when `prompt_expansion` is `standard` and the rewrite succeeds.

**model** `string` *required*

The model that edited the image.

**tier** `string` *required*

The tier that served the request: `radical_speed` or `radical_value`.

```json Base64 format theme={"system"}
{
  "created": 1234567890,
  "data": [
    {
      "b64_json": "iVBORw0KGgoAAAANSUhEUgAABAAAAAQACAYAAAB/HSuDAAAACXBIWXMAAA7EAAAOxAGVKw4b..."
    }
  ],
  "model": "nunchux-qwen-image-edit-2511-lightning",
  "tier": "radical_speed"
}
```

```json URL format theme={"system"}
{
  "created": 1234567890,
  "data": [
    {
      "url": "https://example.com/edited-image.png"
    }
  ],
  "model": "nunchux-qwen-image-edit-2511-lightning",
  "tier": "radical_speed"
}
```

To save a base64 result from cURL, add this pipe to the command:

```bash theme={"system"}
# Replace output.jpg with the file name that you want.
| jq -r '.data[0].b64_json // error(.error.message // .detail // tostring)' | base64 -d > output.jpg
```

## Example

```bash cURL theme={"system"}
# The media URL below is a placeholder. Point it at your own publicly
# reachable file before running this.
curl -X POST https://api.nunchux.com/v1/images/edits \
  -H "Content-Type: application/json" \
  -H "X-API-Key: $NUNCHUX_API_KEY" \
  -d '{
    "model": "nunchux-qwen-image-edit-2511-lightning",
    "url": "https://example.com/example.jpg",
    "prompt": "Transform into a watercolor painting",
    "tier": "radical_speed",
    "width": 1024,
    "height": 1024,
    "response_format": "b64_json"
  }' | jq -r '.data[0].b64_json // error(.error.message // .detail // tostring)' | base64 -d > output.jpg
```

```python Python theme={"system"}
# The media URL below is a placeholder. Point it at your own publicly
# reachable file before running this.
import os
import base64
import requests

response = requests.post(
    "https://api.nunchux.com/v1/images/edits",
    headers={
        "Content-Type": "application/json",
        "X-API-Key": os.environ["NUNCHUX_API_KEY"],
    },
    json={
        "model": "nunchux-qwen-image-edit-2511-lightning",
        "url": "https://example.com/example.jpg",
        "prompt": "Transform into a watercolor painting",
        "tier": "radical_speed",
        "width": 1024,
        "height": 1024,
    },
)

# Decode the base64 image and save it. Change output.jpg to any file name.
image_b64 = response.json()["data"][0]["b64_json"]
with open("output.jpg", "wb") as f:
    f.write(base64.b64decode(image_b64))
```

```javascript JavaScript theme={"system"}
// The media URL below is a placeholder. Point it at your own publicly
// reachable file before running this.
import { writeFile } from "node:fs/promises";

const response = await fetch("https://api.nunchux.com/v1/images/edits", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "X-API-Key": process.env.NUNCHUX_API_KEY,
  },
  body: JSON.stringify({
    model: "nunchux-qwen-image-edit-2511-lightning",
    url: "https://example.com/example.jpg",
    prompt: "Transform into a watercolor painting",
    tier: "radical_speed",
    width: 1024,
    height: 1024,
  }),
});
const data = await response.json();

// Decode the base64 image and save it. Change output.jpg to any file name.
await writeFile("output.jpg", Buffer.from(data.data[0].b64_json, "base64"));
```

```python Python (OpenAI) theme={"system"}
# Replace photo.jpg with the path to your source image.
import os
import requests

from openai import OpenAI

client = OpenAI(
    base_url="https://api.nunchux.com/v1",
    api_key=os.environ["NUNCHUX_API_KEY"],
)

response = client.images.edit(
    model="nunchux-qwen-image-edit-2511-lightning",
    image=open("photo.jpg", "rb"),
    prompt="Transform into a watercolor painting",
    response_format="url",
    extra_body={"width": 1024, "height": 1024},
)

# This tab returns a URL. Download it and save it. Change output.jpg to any file name.
image_url = response.data[0].url
with open("output.jpg", "wb") as f:
    f.write(requests.get(image_url).content)
```

## Several source images

Send a list in `image`. Say in the prompt what to take from each image. This request puts the person from the first image into the scene of the second:

```bash cURL theme={"system"}
# The media URLs below are placeholders. Point them at your own publicly
# reachable files before running this.
curl -X POST https://api.nunchux.com/v1/images/edits \
  -H "Content-Type: application/json" \
  -H "X-API-Key: $NUNCHUX_API_KEY" \
  -d '{
    "model": "nunchux-flux.2-klein-9b-edit",
    "image": [
      "https://example.com/person.jpg",
      "https://example.com/beach.jpg"
    ],
    "prompt": "Place the person from the first image on the beach from the second image",
    "tier": "radical_speed",
    "width": 1024,
    "height": 1024,
    "response_format": "b64_json"
  }' | jq -r '.data[0].b64_json // error(.error.message // .detail // tostring)' | base64 -d > output.jpg
```

```python Python (OpenAI) theme={"system"}
# Replace person.jpg and beach.jpg with the paths to your source images.
import os
import requests

from openai import OpenAI

client = OpenAI(
    base_url="https://api.nunchux.com/v1",
    api_key=os.environ["NUNCHUX_API_KEY"],
)

response = client.images.edit(
    model="nunchux-flux.2-klein-9b-edit",
    image=[open("person.jpg", "rb"), open("beach.jpg", "rb")],
    prompt="Place the person from the first image on the beach from the second image",
    response_format="url",
    extra_body={"width": 1024, "height": 1024},
)

# This tab returns a URL. Download it and save it. Change output.jpg to any file name.
image_url = response.data[0].url
with open("output.jpg", "wb") as f:
    f.write(requests.get(image_url).content)
```

> [!NOTE]
>
> Upload limit with the OpenAI SDK
>
> The OpenAI SDK uploads the files as a form, with one `image[]` part for each file. A form takes up to 10 image files, so it can send as many images as any model takes. Each file must be PNG, JPEG or WebP, and 10 MB or smaller.

## Tips

* Say exactly what to change, add or remove. The models can follow instructions with more than one change.
* With several source images, refer to each one by its place in the list, for example "the person from the first image".
* Use Qwen Image Edit 2511 Lightning when the edit must keep the identity of the subject, or when it changes text in the image.
* Use FLUX.2 Klein 4B Edit for fast, high-volume edit passes.
* Use Qwen Image Edit 2511 or Qwen Image Edit when you want more detail than the Lightning model gives and the extra time is acceptable. Qwen Image Edit 2511 takes up to 3 source images. Use `negative_prompt` to keep things out of the edit.
* Use Qwen Image Edit 2509 or Qwen Image Edit 2509 Lightning when your work already depends on the 2509 release. For new work, use Qwen Image Edit 2511 or Qwen Image Edit 2511 Lightning.
* Use FLUX.2 dev for detailed edits when you already generate with FLUX.2 dev. Steer it with `guidance_scale`.
* Use FLUX 3 Image Klein Edit for fast edits, and to combine up to 10 source images. Describe the whole result in the prompt: the subject, the setting, the light and the style, or send `prompt_expansion` set to `standard` to have Nunchux write the description. It takes no guidance and no negative prompt.
* Use FLUX 3 Image Klein Base Edit when you want more detail or more control than FLUX 3 Image Klein Edit gives, and the extra time is acceptable. It also takes up to 10 source images. Steer it with `guidance_scale` and `negative_prompt`, and send `prompt_expansion` set to `standard` for a short prompt.
* Use Qwen Image 2.1 Edit for edits up to 2752x2752, or with up to 10 source images. Send `width` and `height` in multiples of 32.
* Use `radical_speed` when response time is important. Use `radical_value` for large batches where cost per image is more important. Qwen Image Edit and FLUX.2 dev have `radical_speed` only.
* Send smaller source images for faster processing.

## Errors and limits

| Status | Code | Cause |
| - | - | - |
| 400 | none | A required field is missing, the model ID is not valid, or a value is not valid. The body is a plain `detail` string. |
| 400 | `invalid_request` | The model does not offer the `tier` you sent, for example `radical_value` on Qwen Image Edit. `error.details.reason` is `tier_not_available`. |
| 400 | `invalid_request` | The request sends more source images than the model takes, or an empty list. `error.details.field` is `image`. With too many images, `error.details.reason` is `too_many_images` and `error.details.limit` is the model's cap. |
| 400 | `invalid_request` | The model does not take a field you sent, or does not take its value. For example: `guidance_scale` or `negative_prompt` on FLUX 3 Image Klein Edit, a `steps` value outside 16 to 50 on FLUX 3 Image Klein Base Edit, a `prompt_expansion` mode other than `off` or `standard`, `guidance_scale` on Qwen Image 2.1 Edit, or a size the model does not render, such as 2784x2784 or 1040x1040 on Qwen Image 2.1 Edit. `error.details.field` names the field, and `error.details.reason` is `field_not_accepted`. |
| 400 | `engine_error` | The model cannot render the request, or a source image is rejected: the URL cannot be fetched, the data URI cannot be decoded, or the image is outside the size and ratio limits. |
| 403 | `model_not_available` | Your account does not have access to this model. |
| 504 | `engine_timeout` | Nunchux could not fetch the source image in time. Make sure that the URL is reachable and fast, or send the image as a data URI. |

> [!NOTE]
>
> Refused requests
>
> * Nunchux charges only after a successful generation. A refused request is never billed.
> * Do not branch on a dimension-specific code. A refused size, field or image list returns `invalid_request`, and `error.details.field` names the field. `engine_error` means the model could not render the request, or a source image was rejected.

For authentication, credit and rate-limit errors, see [Error codes](https://docs.nunchux.ai/errors.md). Every request counts toward the requests-per-minute cap of your plan. See [Rate limits](https://docs.nunchux.ai/rate-limits.md).


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