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

# Edit Image

> Edit or extend images based on a prompt

```
POST /v1/images/edits
```

Creates an edited or extended image given an original image and a prompt. The image must be provided as a file upload.

## Request Body

This endpoint accepts `multipart/form-data`.

<ParamField body="image" type="file" required>
  The image to edit. Must be a valid PNG file, less than 4MB, and square.
</ParamField>

<ParamField body="prompt" type="string" required>
  A text description of the desired edit.
</ParamField>

<ParamField body="model" type="string" required>
  The model to use for image editing.
</ParamField>

<ParamField body="mask" type="file">
  An additional image whose fully transparent areas indicate where the image should be edited. Must be a valid PNG file with the same dimensions as the original image.
</ParamField>

<ParamField body="n" type="integer" default="1">
  The number of images to generate. Must be between 1 and 10.
</ParamField>

<ParamField body="size" type="string" default="1024x1024">
  The size of the generated images.
</ParamField>

<ParamField body="response_format" type="string" default="url">
  The format of the generated images. Either `url` or `b64_json`.
</ParamField>

## Response

<ResponseField name="created" type="integer">
  Unix timestamp of when the images were created.
</ResponseField>

<ResponseField name="data" type="array">
  Array of edited images.

  <Expandable title="Image object">
    <ResponseField name="url" type="string">
      The URL of the edited image.
    </ResponseField>

    <ResponseField name="b64_json" type="string">
      Base64-encoded image data.
    </ResponseField>
  </Expandable>
</ResponseField>

## Examples

### Edit with Mask

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

  client = OpenAI(
      api_key="sk-voidai-your_key_here",
      base_url="https://api.voidai.app/v1"
  )

  response = client.images.edit(
      model="dall-e-2",
      image=open("original.png", "rb"),
      mask=open("mask.png", "rb"),
      prompt="A sunlit indoor lounge area with a pool containing a flamingo",
      n=1,
      size="1024x1024"
  )

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

  ```typescript TypeScript theme={null}
  import OpenAI from 'openai';
  import fs from 'fs';

  const client = new OpenAI({
    apiKey: 'sk-voidai-your_key_here',
    baseURL: 'https://api.voidai.app/v1'
  });

  const response = await client.images.edit({
    model: 'dall-e-2',
    image: fs.createReadStream('original.png'),
    mask: fs.createReadStream('mask.png'),
    prompt: 'A sunlit indoor lounge area with a pool containing a flamingo',
    n: 1,
    size: '1024x1024'
  });

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

  ```bash cURL theme={null}
  curl https://api.voidai.app/v1/images/edits \
    -H "Authorization: Bearer sk-voidai-your_key_here" \
    -F image="@original.png" \
    -F mask="@mask.png" \
    -F model="dall-e-2" \
    -F prompt="A sunlit indoor lounge area with a pool containing a flamingo" \
    -F n=1 \
    -F size="1024x1024"
  ```
</CodeGroup>

### Edit Without Mask

<CodeGroup>
  ```python Python theme={null}
  response = client.images.edit(
      model="dall-e-2",
      image=open("image.png", "rb"),
      prompt="Add a rainbow in the sky",
      n=1,
      size="1024x1024"
  )
  ```

  ```bash cURL theme={null}
  curl https://api.voidai.app/v1/images/edits \
    -H "Authorization: Bearer sk-voidai-your_key_here" \
    -F image="@image.png" \
    -F model="dall-e-2" \
    -F prompt="Add a rainbow in the sky" \
    -F n=1 \
    -F size="1024x1024"
  ```
</CodeGroup>

## Response Example

```json theme={null}
{
  "created": 1701691200,
  "data": [
    {
      "url": "https://storage.voidai.app/images/edit-abc123.png"
    }
  ]
}
```

## Notes

<Warning>
  The mask image must have transparency where you want edits to occur. Fully opaque areas will remain unchanged.
</Warning>

<Info>
  For best results, ensure your original image and mask are both square PNG files with the same dimensions.
</Info>
