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

# Image Editing

> Edit an existing image with a prompt and reference images using the NoMask API.

Use `POST /images/edits` to change an image you already have. Send the image and tell the model what to change and what to keep.

> [card] [Try image editing](https://docs.nomask.ai/api-reference/image-edits.md)
>
> Open the endpoint reference and build a request.

## Choose a model

Find an image model in the [model catalog](https://nomask.ai/models) or use the [List models endpoint](https://docs.nomask.ai/api-reference/list-models.md). Look for `capabilities.image_editing: true` and use the model’s public `id`. Check `limits` for the prompt length, reference count, resolutions, and aspect ratios the model supports.

Image model catalog

[JSON](https://nomask.ai/images/models)
[Markdown](https://nomask.ai/images/models.md)

## Send an edit request

Set `NOMASK_API_KEY` to your [NoMask API key](https://docs.nomask.ai/authentication.md), set `NOMASK_IMAGE_MODEL` to your chosen model ID, and place a PNG named `reference.png` next to your script. If the model requires more than one reference, add the required files before sending the request.

```bash cURL (multipart) theme={"system"}
curl --fail-with-body https://api.nomask.ai/v1/images/edits \
  -H "Authorization: Bearer $NOMASK_API_KEY" \
  -F "model=$NOMASK_IMAGE_MODEL" \
  -F "prompt=Change the background to light blue. Keep the subject and framing." \
  -F "image=@reference.png" \
  --output edit-response.json
```

```python Python (JSON) theme={"system"}
import base64
import os
from pathlib import Path

import requests

reference = base64.b64encode(Path("reference.png").read_bytes()).decode("ascii")
response = requests.post(
    "https://api.nomask.ai/v1/images/edits",
    headers={"Authorization": f"Bearer {os.environ['NOMASK_API_KEY']}"},
    json={
        "model": os.environ["NOMASK_IMAGE_MODEL"],
        "prompt": "Change the background to light blue. Keep the subject and framing.",
        "images": [f"data:image/png;base64,{reference}"],
    },
    timeout=225,
)
response.raise_for_status()
edited = response.json()["data"][0]
Path("edited.png").write_bytes(base64.b64decode(edited["b64_json"]))
```

### Reference images and output options

* **Multipart**. Send one file as `image`, or repeat `image[]` for multiple files.
* **JSON**. Send an array of base64 data URLs in `images`. The `image` alias accepts a single data URL or an array. Use one field per request.
* **Limits**. Send at least one reference and stay within your model’s reference limits. PNG, JPEG, and WebP are accepted. References can total up to 25 MiB, and the full JSON body can be up to 40 MiB.
* **Output**. The endpoint returns one image per request (`n=1`). PNG is the default. Use `output_format` for `jpg` or `webp`, and use `resolution` or `aspect_ratio` to choose settings listed by the model.

Remote image URLs, masks, and streaming are unsupported.

## Save the edited image

A successful request returns one image in `data[0].b64_json`. Decode it and save the bytes using the returned `mime_type`. The response also includes the actual `width` and `height`, the number of references used in `nomask.reference_images`, and the charge in `nomask.cost_usd`. Paid requests use your [API balance](https://docs.nomask.ai/billing.md).

The Python example saves the image directly. If you ran the cURL example, the image is in `edit-response.json`. Use `jq` and `base64` to extract the PNG.

```bash theme={"system"}
jq -r '.data[0].b64_json' edit-response.json | base64 --decode > edited.png
```

## Troubleshoot an edit

| Error | What to check |
| - | - |
| `invalid_image` | Check the model’s reference count and make sure each file or data URL contains a valid PNG, JPEG, or WebP. |
| `payload_too_large` | Reduce the combined reference size or the size of the JSON body. |
| `content_policy_violation` | The model blocked the request. Review your prompt and reference images. |
| `idempotency_conflict` | This key was already accepted. Check the original response before retrying. |

For the full error list, see [Errors](https://docs.nomask.ai/errors.md).


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