Docs

Edit Image

POST/v1/images/edits

Edit an image given a prompt and source image

On this page
  1. Request Body
  2. Response
  3. Request Example
  4. Response Example
  5. Notes

Creates an edited or extended image given an original image and a prompt. Requires multipart/form-data content type.

This endpoint follows the OpenAI multipart image-editing contract and requires an edit-capable OpenAI image model. Other image families on AnyPath are available through POST /v1/images/generations; use GET /v1/models to see what your API key can use.

Request Body

Parameter image

Type: file

Location: body

Required: yes

The image to edit. Format, size, and dimension requirements depend on the selected model.

Parameter prompt

Type: string

Location: body

Required: yes

A text description of the desired edit.

Parameter mask

Type: file

Location: body

An additional image whose fully transparent areas indicate where the image should be edited, for models that accept a mask.

Parameter model

Type: string

Location: body

The model to use for the edit. Use an edit-capable OpenAI image model such as gpt-image-1.5; view the current list with GET /v1/models.

Parameter n

Type: integer

Location: body

The number of images to generate. Must be between 1 and 10.

Parameter size

Type: string

Location: body

The size of the generated images. Supported values depend on the selected model (for example 1024x1024).

Parameter response_format

Type: string

Location: body

The format in which the generated images are returned. Must be url or b64_json.

Parameter user

Type: string

Location: body

A unique identifier representing your end-user for abuse monitoring.

Response

Response Field created

Type: integer

Unix timestamp of when the images were created.

Response Field data

Type: array

Array of generated images.

Each object contains:

  • url (string): URL of the edited image (if response_format is url)
  • b64_json (string): Base64-encoded image (if response_format is b64_json)

Request Example

curl -X POST "https://api.anypath.dev/v1/images/edits" \
  -H "Authorization: Bearer sk-your-api-key" \
  -F "model=gpt-image-1.5" \
  -F "image=@sunlit_lounge.png" \
  -F "mask=@mask.png" \
  -F "prompt=A sunlit indoor lounge area with a pool" \
  -F "n=1" \
  -F "size=1024x1024"
from openai import OpenAI

client = OpenAI(
    api_key="sk-your-api-key",
    base_url="https://api.anypath.dev/v1"
)

response = client.images.edit(
    model="gpt-image-1.5",
    image=open("sunlit_lounge.png", "rb"),
    mask=open("mask.png", "rb"),
    prompt="A sunlit indoor lounge area with a pool",
    n=1,
    size="1024x1024"
)

print(response.data[0].url)
import OpenAI from 'openai';
import fs from 'fs';

const client = new OpenAI({
  apiKey: 'sk-your-api-key',
  baseURL: 'https://api.anypath.dev/v1'
});

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

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

import (
    "bytes"
    "fmt"
    "io"
    "mime/multipart"
    "net/http"
    "os"
)

func main() {
    body := &bytes.Buffer{}
    writer := multipart.NewWriter(body)

    image, _ := os.Open("sunlit_lounge.png")
    defer image.Close()
    part, _ := writer.CreateFormFile("image", "sunlit_lounge.png")
    io.Copy(part, image)

    mask, _ := os.Open("mask.png")
    defer mask.Close()
    maskPart, _ := writer.CreateFormFile("mask", "mask.png")
    io.Copy(maskPart, mask)

    writer.WriteField("prompt", "A sunlit indoor lounge area with a pool")
    writer.WriteField("n", "1")
    writer.WriteField("size", "1024x1024")
    writer.Close()

    req, _ := http.NewRequest("POST", "https://api.anypath.dev/v1/images/edits", body)
    req.Header.Set("Authorization", "Bearer sk-your-api-key")
    req.Header.Set("Content-Type", writer.FormDataContentType())

    client := &http.Client{}
    resp, _ := client.Do(req)
    defer resp.Body.Close()

    result, _ := io.ReadAll(resp.Body)
    fmt.Println(string(result))
}
<?php
$ch = curl_init('https://api.anypath.dev/v1/images/edits');

$image = new CURLFile('sunlit_lounge.png', 'image/png', 'sunlit_lounge.png');
$mask = new CURLFile('mask.png', 'image/png', 'mask.png');

curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer sk-your-api-key'
    ],
    CURLOPT_POSTFIELDS => [
        'image' => $image,
        'mask' => $mask,
        'prompt' => 'A sunlit indoor lounge area with a pool',
        'n' => 1,
        'size' => '1024x1024'
    ]
]);

$response = curl_exec($ch);
curl_close($ch);

$data = json_decode($response, true);
echo $data['data'][0]['url'];

Response Example

{
  "created": 1706000000,
  "data": [
    {
      "url": "https://..."
    }
  ]
}

Notes

Image edits require an edit-capable OpenAI image model such as gpt-image-1.5. Depending on the model, the source image uses transparent areas to mark where the edit applies, or you provide a separate mask image.