POST /v1/images/edits
Edit an existing image according to a text prompt. You can send a single base image or multiple, and optionally a mask.
- Method: POST
- Path:
/v1/images/edits
- Auth: Bearer token in
Authorization
header - Content-Type:
multipart/form-data
Request parameters
model
(string, required): Image editing model.prompt
(string, required, 1..32000): Instructions for the edit.background
(string, optional): Background control (provider-specific).mask
(binary | null, optional): PNG mask where transparent areas will be replaced.n
(integer ≥ 1, optional): Number of images to generate.quality
(string, optional): Provider-specific quality preset.response_format
(enum:url
|b64_json
, defaulturl
): Output format.size
(string, optional): Resolution like1024x1024
.image
(binary, optional): Base image file (single).images[]
(binary[], optional): Multiple base images.
Note: Provide either image
or images[]
.
Example requests
- Python
- Node.js
- cURL
from openai import OpenAI
client = OpenAI(base_url="https://api.naga.ac/v1", api_key="YOUR_API_KEY")
with open("image.png", "rb") as img:
# Optional: open a mask file
# with open("mask.png", "rb") as m:
resp = client.images.edit(
model="gpt-image-1",
image=img,
prompt="Make the sky more dramatic and add light rays",
size="1024x1024",
n=1,
response_format="url", # or "b64_json"
# mask=m,
)
print(resp.data)
import OpenAI from "openai";
import fs from "fs";
const client = new OpenAI({ baseURL: "https://api.naga.ac/v1", apiKey: "YOUR_API_KEY" });
const resp = await client.images.edit({
model: "gpt-image-1",
image: fs.createReadStream("image.png"),
// mask: fs.createReadStream("mask.png"), // optional
prompt: "Make the sky more dramatic and add light rays",
size: "1024x1024",
n: 1,
response_format: "url", // or "b64_json"
});
console.log(resp.data);
curl https://api.naga.ac/v1/images/edits \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: multipart/form-data" \
-F image="@image.png" \
-F prompt="Make the sky more dramatic and add light rays" \
-F model="gpt-image-1" \
-F size="1024x1024" \
-F n=1 \
-F response_format="url"
Response
Returns a JSON object with a data
array of edited images. Each item contains either:
url
whenresponse_format = "url"
, orb64_json
whenresponse_format = "b64_json"
.