Modify existing images using text prompts and optional masks.
The image editing endpoint lets you modify existing images by providing a text prompt describing the desired changes. You can optionally include a mask to constrain edits to specific regions.
Provide an image and a prompt describing how to modify it.
Python
Node.js
cURL
import osfrom openai import OpenAIclient = OpenAI( base_url="https://api.routeway.ai/v1", api_key=os.getenv("ROUTEWAY_API_KEY"),)response = client.images.edit( model="gpt-image-1", image=open("input.png", "rb"), prompt="Add a rainbow in the sky",)print(response.data[0].url)
import fs from "fs";import OpenAI from "openai";const client = new OpenAI({ baseURL: "https://api.routeway.ai/v1", apiKey: process.env.ROUTEWAY_API_KEY,});const response = await client.images.edit({ model: "gpt-image-1", image: fs.createReadStream("input.png"), prompt: "Add a rainbow in the sky",});console.log(response.data[0].url);
curl -X POST https://api.routeway.ai/v1/images/edits \ -H "Authorization: Bearer $ROUTEWAY_API_KEY" \ -F model="gpt-image-1" \ -F image="@input.png" \ -F prompt="Add a rainbow in the sky"
Use a mask to specify which region of the image should be edited. The mask is a same-size image where transparent areas indicate where edits should be applied.
Python
Node.js
cURL
response = client.images.edit( model="gpt-image-1", image=open("room.png", "rb"), mask=open("mask.png", "rb"), prompt="A modern red sofa", size="1024x1024",)print(response.data[0].url)
const response = await client.images.edit({ model: "gpt-image-1", image: fs.createReadStream("room.png"), mask: fs.createReadStream("mask.png"), prompt: "A modern red sofa", size: "1024x1024",});console.log(response.data[0].url);
curl -X POST https://api.routeway.ai/v1/images/edits \ -H "Authorization: Bearer $ROUTEWAY_API_KEY" \ -F model="gpt-image-1" \ -F image="@room.png" \ -F mask="@mask.png" \ -F prompt="A modern red sofa" \ -F size="1024x1024"
The mask must be a PNG with an alpha channel. Transparent pixels mark the area to edit; opaque pixels are preserved.
Generate several variations of an edit by setting n.
Python
Node.js
cURL
response = client.images.edit( model="gpt-image-1", image=open("photo.png", "rb"), prompt="Replace the background with a snowy mountain landscape", n=3,)for i, image in enumerate(response.data): print(f"Variation {i + 1}: {image.url}")
const response = await client.images.edit({ model: "gpt-image-1", image: fs.createReadStream("photo.png"), prompt: "Replace the background with a snowy mountain landscape", n: 3,});response.data.forEach((image, i) => { console.log(`Variation ${i + 1}: ${image.url}`);});
curl -X POST https://api.routeway.ai/v1/images/edits \ -H "Authorization: Bearer $ROUTEWAY_API_KEY" \ -F model="gpt-image-1" \ -F image="@photo.png" \ -F prompt="Replace the background with a snowy mountain landscape" \ -F n=3