Skip to main content
POST
/
v1
/
images
/
edits
Image editing
curl --request POST \
  --url https://openp.ai/v1/images/edits
import requests

url = "https://openp.ai/v1/images/edits"

response = requests.post(url)

print(response.text)
const options = {method: 'POST'};

fetch('https://openp.ai/v1/images/edits', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://openp.ai/v1/images/edits",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
package main

import (
"fmt"
"net/http"
"io"
)

func main() {

url := "https://openp.ai/v1/images/edits"

req, _ := http.NewRequest("POST", url, nil)

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://openp.ai/v1/images/edits")
.asString();
require 'uri'
require 'net/http'

url = URI("https://openp.ai/v1/images/edits")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)

response = http.request(request)
puts response.read_body
Generate an edited version based on a source image (with an optional mask), for tasks like removal, outpainting and style transfer.

Request

curl https://openp.ai/v1/images/edits \
  -H "Authorization: Bearer $OPENPAI_API_KEY" \
  -F image="@photo.png" \
  -F mask="@mask.png" \
  -F prompt="A sunny beach in the background" \
  -F model="gpt-image-1" \
  -F size="1024x1024" \
  -F n=1

Parameters

FieldTypeRequiredDescription
imagefileSource image (PNG / JPEG). gpt-image-1 accepts multiple (comma-separated or repeated fields)
maskfileSame size as the source; transparent areas are editable
promptstringEditing instruction
modelstringgpt-image-1 / dall-e-2
ninteger1-10
sizestring256x256 / 512x512 / 1024x1024, etc.
response_formatstringurl / b64_json
qualitystringlow / medium / high (gpt-image-1)

Response

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

Python example

from openai import OpenAI
client = OpenAI(api_key="sk-...", base_url="https://openp.ai/v1")

resp = client.images.edit(
    model="gpt-image-1",
    image=open("photo.png", "rb"),
    mask=open("mask.png", "rb"),
    prompt="Replace the background with a beach",
    size="1024x1024",
    n=1,
)
print(resp.data[0].url)

Making a mask

  • The mask must be the same size as the source + a PNG alpha channel.
  • Transparent pixels mark the area the model is allowed to repaint.
  • Opaque pixels mark the area that must stay as the original.
  • You can create it with Photoshop / GIMP / PIL.

Multi-image blending (gpt-image-1)

gpt-image-1 supports using multiple images as input references:
resp = client.images.edit(
    model="gpt-image-1",
    image=[open("a.png","rb"), open("b.png","rb"), open("c.png","rb")],
    prompt="Draw the three characters onto a single poster",
    size="1024x1024",
)