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

# Image Edits

> Edit one or more uploaded images with a prompt and optional mask.

`POST /v1/images/edits` uses multipart form-data.

Use this endpoint when you want to modify one or more uploaded images rather than generate a new image from scratch.

## Common fields

| Field             | Required | Notes                                                           |
| ----------------- | -------- | --------------------------------------------------------------- |
| `model`           | Yes      | Image editing model                                             |
| `prompt`          | Yes      | Edit instruction                                                |
| `image`           | Yes      | One uploaded image, or use repeated image fields when supported |
| `mask`            | No       | Optional mask to constrain the editable region                  |
| `response_format` | No       | `url` or `b64_json`                                             |

## Multipart Example

<CodeGroup>
  ```python Python theme={null}
  from pathlib import Path
  from openai import OpenAI

  client = OpenAI(
      base_url="https://api.naga.ac/v1",
      api_key="YOUR_API_KEY",
  )

  result = client.images.edit(
      model="gpt-image-1",
      prompt="Replace the background with a rainy cyberpunk street.",
      image=Path("input.png"),
      mask=Path("mask.png"),
      response_format="url",
  )

  print(result.data[0].url)
  ```

  ```javascript Node.js theme={null}
  import fs from 'fs';
  import OpenAI from 'openai';

  const client = new OpenAI({
    baseURL: 'https://api.naga.ac/v1',
    apiKey: 'YOUR_API_KEY',
  });

  const result = await client.images.edit({
    model: 'gpt-image-1',
    prompt: 'Replace the background with a rainy cyberpunk street.',
    image: fs.createReadStream('input.png'),
    mask: fs.createReadStream('mask.png'),
    response_format: 'url',
  });

  console.log(result.data[0].url);
  ```

  ```bash cURL theme={null}
  curl https://api.naga.ac/v1/images/edits \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -F "model=gpt-image-1" \
    -F "prompt=Replace the background with a rainy cyberpunk street." \
    -F "image=@input.png" \
    -F "mask=@mask.png" \
    -F "response_format=url"
  ```
</CodeGroup>

## Notes

* at least one image must be provided
* `mask` is optional
* `response_format` can be `url` or `b64_json`
* prompt and output usage are tracked separately from input image usage

## Common mistakes

* sending JSON instead of multipart form-data
* forgetting that `mask` is optional but uploaded images are not
* using image edits when plain image generation would be simpler

## Reference

* [Edit images](/api-reference/endpoints/images/edits)
