Skip to content

Image editing

POST /v1/images/edits takes an existing image and a prompt and returns a changed image: a new background, an object removed, a style applied. It follows the OpenAI image edit format, so client.images.edit works with the base URL changed. The image models that generate also edit — see the models page.

Upload a file

curl https://api.cloakray.com/v1/images/edits \
  -H "Authorization: Bearer $CLOAKRAY_API_KEY" \
  -F "model=gpt-image-2" \
  -F "image=@product.png" \
  -F "prompt=Put the product on a marble countertop in soft morning light"
import fs from "node:fs";
import OpenAI from "openai";

const client = new OpenAI({ baseURL: "https://api.cloakray.com/v1", apiKey: process.env.CLOAKRAY_API_KEY });

const result = await client.images.edit({
  model: "gpt-image-2",
  image: fs.createReadStream("product.png"),
  prompt: "Put the product on a marble countertop in soft morning light",
});

fs.writeFileSync("edited.png", Buffer.from(result.data[0].b64_json, "base64"));

The multipart field may be named image, image[] or file. Only the first image file is used. Add a mask file — a PNG whose transparent areas mark where to edit — on models that support masks.

Send image URLs as JSON

curl https://api.cloakray.com/v1/images/edits \
  -H "Authorization: Bearer $CLOAKRAY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini-3-pro-image-preview",
    "images": [{ "image_url": "https://example.com/room.jpg" }],
    "prompt": "Repaint the walls sage green",
    "n": 1
  }'

The response

The same shape as image generation: a data array with one entry per image, each carrying b64_json. Decode it and save the bytes.

Options and pricing

size, quality, n and output format work where the model supports them; the model's page lists its values. Editing is priced like generation — per image, by resolution, or per token, depending on the model — and is shown on the model's page.