Image editing
Menu
Images

Image editing

Edit or extend an existing image from a prompt and an optional mask.

POST /v1/images/edits

Creates an edited or extended image from one or more source images and a prompt. The endpoint follows the OpenAI Images API and accepts multipart/form-data, so the official OpenAI SDKs work unchanged with base_url set to https://rutoken.ai/v1. Supported models include gpt-image-1 and dall-e-2, depending on what is enabled in the Model Square.

Authentication

Send your key in the Authorization: Bearer sk-xxxx header.

Request body

Content type: multipart/form-data.

Parameter Type Required Description
image file Yes Image to edit. gpt-image-1: PNG, WEBP or JPG under 50 MB; repeat the field (image[]) to send up to 16 images. dall-e-2: one square PNG under 4 MB.
prompt string Yes Description of the desired result. Max 32000 characters for gpt-image-1, 1000 for dall-e-2.
model string Yes Model ID, e.g. gpt-image-1.
mask file No PNG whose fully transparent areas mark where the image should be edited. Must have the same size as image.
n integer No Number of images, 1–10. Default 1.
size string No gpt-image-1: 1024x1024, 1536x1024, 1024x1536 or auto. dall-e-2: 256x256, 512x512, 1024x1024.
quality string No gpt-image-1: low, medium, high or auto.
response_format string No url or b64_json (dall-e-2 only; gpt-image-1 always returns b64_json).
background string No gpt-image-1 only: transparent, opaque or auto.
output_format string No gpt-image-1 only: png, jpeg or webp.
input_fidelity string No gpt-image-1 only: high or low — how closely to preserve input details such as faces.
stream boolean No Stream partial images, when the upstream supports it.
user string No End-user identifier.

Request example

cURL
curl https://rutoken.ai/v1/images/edits \
  -H "Authorization: Bearer $API_KEY" \
  -F model="gpt-image-1" \
  -F image="@room.png" \
  -F mask="@mask.png" \
  -F prompt="Add a large green plant next to the sofa" \
  -F size="1024x1024"
Python
import base64
from openai import OpenAI

client = OpenAI(base_url="https://rutoken.ai/v1", api_key="sk-xxxx")
resp = client.images.edit(
    model="gpt-image-1",
    image=open("room.png", "rb"),
    mask=open("mask.png", "rb"),
    prompt="Add a large green plant next to the sofa",
    size="1024x1024",
)
with open("room-edited.png", "wb") as f:
    f.write(base64.b64decode(resp.data[0].b64_json))
Node.js
import fs from "node:fs";
import OpenAI from "openai";

const client = new OpenAI({ baseURL: "https://rutoken.ai/v1", apiKey: "sk-xxxx" });
const resp = await client.images.edit({
  model: "gpt-image-1",
  image: fs.createReadStream("room.png"),
  mask: fs.createReadStream("mask.png"),
  prompt: "Add a large green plant next to the sofa",
  size: "1024x1024",
});
fs.writeFileSync("room-edited.png", Buffer.from(resp.data[0].b64_json, "base64"));

Response

json
{
  "created": 1760000000,
  "data": [
    { "b64_json": "iVBORw0KGgoAAAANSUhEUgAA..." }
  ],
  "usage": {
    "total_tokens": 1650,
    "input_tokens": 450,
    "output_tokens": 1200,
    "input_tokens_details": { "text_tokens": 30, "image_tokens": 420 }
  }
}
Field Type Description
created integer Unix timestamp.
data[].b64_json string Base64-encoded result image.
data[].url string Result URL, when response_format is url.
usage object Token usage for token-billed models such as gpt-image-1.

Notes

  • The gateway also accepts a JSON body for this endpoint and forwards it upstream as is; use it only if your upstream model documents a JSON form of image editing.
  • POST /v1/images/variations is not implemented.

See also: Image generation, Errors.