Skip to main content

/images/edits

Edit images using AI models. Supports both single and multiple image editing.

FeatureSupportedNotes
Cost TrackingWorks with all supported models
LoggingWorks across all integrations
FallbacksWorks between supported models
LoadbalancingWorks between supported models
Supported ProvidersOpenAI, Gemini (Google AI Studio), Vertex AI, Stability AI, AWS Bedrock (Stability)

Quick Start

Python

from openai import OpenAI

client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://api.haimaker.ai/v1"
)

response = client.images.edit(
model="openai/gpt-image-1",
image=open("original_image.png", "rb"),
prompt="Add a red hat to the person in the image",
n=1,
size="1024x1024"
)

print(response.data[0].url)

cURL

curl https://api.haimaker.ai/v1/images/edits \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "model=openai/gpt-image-1" \
-F "image=@original_image.png" \
-F "prompt=Add a beautiful sunset in the background" \
-F "n=1" \
-F "size=1024x1024"

Image Edit with Mask

Use a mask to specify which areas of the image should be edited:

from openai import OpenAI

client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://api.haimaker.ai/v1"
)

response = client.images.edit(
model="openai/gpt-image-1",
image=open("original_image.png", "rb"),
mask=open("mask_image.png", "rb"), # Transparent areas will be edited
prompt="Replace the background with a beach scene",
n=1,
size="1024x1024"
)

print(response.data[0].url)

Using Different Models

OpenAI GPT-Image-1

from openai import OpenAI

client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://api.haimaker.ai/v1"
)

response = client.images.edit(
model="openai/gpt-image-1",
image=open("portrait.png", "rb"),
prompt="Add sunglasses and a smile",
n=1,
size="1024x1024"
)

print(response.data[0].url)

Gemini

import base64
from openai import OpenAI

client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://api.haimaker.ai/v1"
)

response = client.images.edit(
model="gemini/gemini-2.5-flash-image",
image=open("original_image.png", "rb"),
prompt="Add aurora borealis to the night sky",
size="1792x1024"
)

# Gemini returns base64-encoded images
edited_image_bytes = base64.b64decode(response.data[0].b64_json)
with open("edited_image.png", "wb") as f:
f.write(edited_image_bytes)

Vertex AI

from openai import OpenAI

client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://api.haimaker.ai/v1"
)

response = client.images.edit(
model="vertex_ai/imagen-3.0-capability-001",
image=open("original_image.png", "rb"),
mask=open("mask_image.png", "rb"),
prompt="Turn this into watercolor style scenery",
n=2,
size="1024x1024"
)

for i, image_data in enumerate(response.data):
print(f"Image {i+1}: {image_data.url}")

Input Parameters

ParameterTypeDescriptionRequired
imagefileThe image to edit. Must be a valid PNG file, less than 4MB, and square.Yes
promptstringA text description of the desired image edit.Yes
modelstringThe model to use for image editing.No (defaults to dall-e-2)
maskfileAn additional image whose fully transparent areas indicate where the original image should be edited.No
nintegerThe number of images to generate. Must be between 1 and 10.No (defaults to 1)
sizestringThe size of the generated images.No (defaults to 1024x1024)
response_formatstringThe format in which images are returned (url or b64_json).No (defaults to url)
userstringA unique identifier representing your end-user.No

Response Format

{
"created": 1677649800,
"data": [
{
"url": "https://example.com/edited_image_1.png"
}
]
}

For b64_json format:

{
"created": 1677649800,
"data": [
{
"b64_json": "iVBORw0KGgoAAAANSUhEUgAA..."
}
]
}