Edit Image
/v1/images/editsEdit an image given a prompt and source image
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; useGET /v1/modelsto see what your API key can use.
Request Body
Parameter image
The image to edit. Format, size, and dimension requirements depend on the selected model.
Parameter prompt
A text description of the desired edit.
Parameter mask
An additional image whose fully transparent areas indicate where the image should be edited, for models that accept a mask.
Parameter model
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
The number of images to generate. Must be between 1 and 10.
Parameter size
The size of the generated images. Supported values depend on the selected model (for example 1024x1024).
Parameter response_format
The format in which the generated images are returned. Must be url or b64_json.
Parameter user
A unique identifier representing your end-user for abuse monitoring.
Response
Response Field created
Unix timestamp of when the images were created.
Response Field data
Array of generated images.
Each object contains:
url(string): URL of the edited image (if response_format isurl)b64_json(string): Base64-encoded image (if response_format isb64_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.