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

# Image editing

> Edit an existing image from a prompt and one or more reference images.

The edits endpoint changes an existing image based on a prompt. This is image-to-image: you send one or more reference images plus an instruction, and you get a new image back. It works with the official OpenAI image SDKs, the same as [image generation](/capabilities/image-generation).

| Endpoint                | What it does                                             |
| ----------------------- | -------------------------------------------------------- |
| `POST /v1/images/edits` | Edit an existing image with one or more reference images |

Unlike generation, an edit request is sent as `multipart/form-data` because it uploads image files. `deepshi-image-1` is a good default; it accepts up to five reference images.

## Step 1: Send an edit request

Send a `model`, a `prompt`, and at least one `image` file:

```bash curl theme={null}
curl https://api.deepshi.ai/v1/images/edits \
  -H "Authorization: Bearer $DEEPSHI_API_KEY" \
  -F model="deepshi-image-1" \
  -F prompt="remove the person on the left" \
  -F 'image[]=@input.png'
```

The response is the same as generation. The edited image is base64-encoded in `data[0].b64_json`:

```json theme={null}
{
  "created": 1782595538,
  "model": "deepshi-image-1",
  "size": "1024x1024",
  "data": [
    { "b64_json": "iVBORw0KGgoAAAANSUhEUgAA...", "index": 0 }
  ],
  "usage": {
    "cost": { "total_cost": 0.01 }
  }
}
```

## Step 2: Save the result

Decode `b64_json` and write it to a file:

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

  client = OpenAI(base_url="https://api.deepshi.ai/v1", api_key="YOUR_DEEPSHI_API_KEY")

  resp = client.images.edit(
      model="deepshi-image-1",
      prompt="remove the person on the left",
      image=open("input.png", "rb"),
  )

  with open("edited.png", "wb") as f:
      f.write(base64.b64decode(resp.data[0].b64_json))
  print("saved edited.png")
  ```

  ```javascript JavaScript theme={null}
  import OpenAI from "openai";
  import { writeFileSync, createReadStream } from "node:fs";

  const client = new OpenAI({
    baseURL: "https://api.deepshi.ai/v1",
    apiKey: process.env.DEEPSHI_API_KEY,
  });

  const resp = await client.images.edit({
    model: "deepshi-image-1",
    prompt: "remove the person on the left",
    image: createReadStream("input.png"),
  });

  writeFileSync("edited.png", Buffer.from(resp.data[0].b64_json, "base64"));
  console.log("saved edited.png");
  ```
</CodeGroup>

## Reference images

Most image models support editing. How many reference images each one accepts varies, from 1 up to 14. To send more than one, pass multiple `image[]` parts:

```bash theme={null}
curl https://api.deepshi.ai/v1/images/edits \
  -H "Authorization: Bearer $DEEPSHI_API_KEY" \
  -F model="deepshi-image-1" \
  -F prompt="combine these into one scene" \
  -F 'image[]=@first.png' \
  -F 'image[]=@second.png'
```

To see a model's editing support and its reference-image cap, check the card on the [image models](/models/image-models) page, or read the top-level `edit` block from `GET /v1/models`:

```json theme={null}
"edit": { "supported": true, "max_reference_images": 5 }
```

<Note>
  `deepshi-banana-pro` is generate-only and does not support editing. A model that can't edit
  has `"edit": { "supported": false }` in `GET /v1/models`.
</Note>

## Sizing, parameters, and pricing

An edit request takes the same sizing fields as generation (`width` and `height`, `aspect_ratio`, `resolution`, or `image_size`, depending on the model) and the same [common parameters](/capabilities/image-generation#common-parameters). The Deepshi models (`deepshi-image-1`, `deepshi-banana-pro`) support only `n: 1`.

Pricing also works the same way as generation, and every response includes `usage.cost.total_cost` in USD. See [Pricing](/capabilities/image-generation#pricing).

## Next steps

<CardGroup cols={2}>
  <Card title="Image generation" icon="image" href="/capabilities/image-generation">
    Generate images from a text prompt.
  </Card>

  <Card title="Image models" icon="layer-group" href="/models/image-models">
    See which models support editing and how many reference images they take.
  </Card>
</CardGroup>
