Skip to main content
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.
POST https://api.routeway.ai/v1/images/edits

Basic Image Editing

Provide an image and a prompt describing how to modify it.
import os
from openai import OpenAI

client = 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)

Inpainting with Masks

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.
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)
The mask must be a PNG with an alpha channel. Transparent pixels mark the area to edit; opaque pixels are preserved.

Supported Formats

FormatSupported
PNG
JPEG
WebP
GIF (first frame)
Images must be square and no larger than 4MB. Non-square images may be automatically cropped or rejected depending on the model.

Size Constraints

The size parameter controls the output dimensions of the edited image.
SizeNotes
1024x1024Default. Works with all models.
512x512Smaller output, faster processing.
256x256Minimum supported size.
For best results, provide an input image that matches the requested output size. Mismatched sizes may result in distortion or quality loss.

Editing with Multiple Outputs

Generate several variations of an edit by setting n.
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}")

Saving Edited Images

import base64

response = client.images.edit(
    model="gpt-image-1",
    image=open("input.png", "rb"),
    prompt="Make it look like a pencil sketch",
    response_format="b64_json",
)

image_data = base64.b64decode(response.data[0].b64_json)

with open("edited.png", "wb") as f:
    f.write(image_data)

print("Edited image saved to edited.png")

Best Practices

Without a mask, the model decides what to change. For predictable results, provide a mask that clearly marks the target region.
Describe only what should change, not the entire image. “A blue vase with flowers” works better than re-describing the whole scene.
Provide images at the same resolution you request in size to avoid quality degradation from rescaling.