This API endpoint allows you to edit images using AI models. You can provide one or more base64-encoded images along with a text prompt describing the desired edit.
The Image Edits API supports both single and multiple image editing, with optional mask support for targeted edits.
Images stored via URL are only available for 1 hour after generation. Make sure to download and save important images locally.
Create Image Edit
To edit an image, use the following endpoint:
POST /v1/images/edits
Request Body
Base64-encoded images (PNG format, < 4MB each)
Base64-encoded mask image (PNG format, < 4MB) for targeted edits
Text description of the desired edit
Model to use for image editing
Number of images to generate (1-10, default: 1)
Image size (options: “256x256”, “512x512”, “1024x1024”)
Response format (options: “url” or “b64_json”, default: “url”)
Transformation strength (0.0-1.0)
Guidance scale for the edit (0.0-20.0)
Number of inference steps (1-100)
Random seed for reproducible results
Kontext max mode configuration
import os
import base64
from openai import OpenAI
client = OpenAI(
base_url="https://api.routeway.ai/v1",
api_key=os.getenv("Routeway_API_KEY")
)
# Read and encode image
with open("input.png", "rb") as image_file:
encoded_image = base64.b64encode(image_file.read()).decode('utf-8')
response = client.images.edit(
images=[encoded_image],
prompt="Add a sunset in the background",
size="1024x1024",
n=1
)
print(response.data[0].url)
Response
The response includes the edited image(s) with either a URL or base64-encoded data, depending on the response_format parameter.
{
"created": 1234567890,
"data": [
{
"url": "https://example.com/image.png",
"revised_prompt": "Add a sunset in the background"
}
]
}
When response_format is set to b64_json, the response will include base64-encoded image data instead of a URL:
{
"created": 1234567890,
"data": [
{
"b64_json": "iVBORw0KGgoAAAANSUhEUgAA...",
"revised_prompt": "Add a sunset in the background"
}
]
}
Error Response
{
"error": {
"message": "Invalid image format",
"type": "invalid_request_error",
"code": 400
}
}