gpt-image-1
Model Overview
A powerful multimodal model capable of generating new images, combining existing ones, and applying image masks — all guided by a text prompt.
Setup your API Key
If you don’t have an API key for the AI/ML API yet, feel free to use our Quickstart guide.
API Schemas
Unfortunately, this model only accepts local files specified by their file paths. It does not support image input via URLs or base64 encoding.
Generate image
The text prompt describing the content, style, or composition of the image to be generated.
auto
Possible values: auto
Possible values: The number of images to generate.
1
100
The format of the generated image.
png
Possible values: The quality of the image that will be generated.
medium
Possible values: The size of the generated image.
1024x1024
Possible values: The format in which the generated images are returned.
url
Possible values: POST /v1/images/generations HTTP/1.1
Host: api.aimlapi.com
Authorization: Bearer <YOUR_AIMLAPI_KEY>
Content-Type: application/json
Accept: */*
Content-Length: 201
{
"model": "openai/gpt-image-1",
"prompt": "text",
"background": "auto",
"moderation": "auto",
"n": 1,
"output_compression": 100,
"output_format": "png",
"quality": "medium",
"size": "1024x1024",
"response_format": "url"
}
No content
Edit image
The text prompt describing the content, style, or composition of the image to be generated.
The image(s) to edit. Must be a supported image file or an array of images. Each image should be a png, webp, or jpg file less than 50MB. You can provide up to 16 images.
An additional image whose fully transparent areas (e.g. where alpha is zero) indicate where image should be edited. If there are multiple images provided, the mask will be applied on the first image. Must be a valid PNG file, less than 4MB, and have the same dimensions as image.
Allows to set transparency for the background of the generated image(s). When auto is used, the model will automatically determine the best background for the image. If transparent, the output format needs to support transparency, so it should be set to either png (default value) or webp.
auto
Possible values: 1
The compression level (0-100%) for the generated images.
100
The format of the generated image.
png
Possible values: The quality of the image that will be generated.
medium
Possible values: The size of the generated image.
1024x1024
Possible values: The format in which the generated images are returned.
url
Possible values: POST /v1/images/edits HTTP/1.1
Host: api.aimlapi.com
Authorization: Bearer <YOUR_AIMLAPI_KEY>
Content-Type: application/json
Accept: */*
Content-Length: 214
{
"model": "openai/gpt-image-1",
"prompt": "text",
"image": "binary",
"mask": "binary",
"background": "auto",
"n": 1,
"output_compression": 100,
"output_format": "png",
"quality": "medium",
"size": "1024x1024",
"response_format": "url"
}
No content
Quick Examples
Generate image
Let's generate an image of the specified size using a simple prompt.
import requests
import json
def main():
response = requests.post(
"https://api.aimlapi.com/v1/images/generations",
headers={
# Insert your AIML API Key instead of <YOUR_AIMLAPI_KEY>:
"Authorization": "Bearer <YOUR_AIMLAPI_KEY>",
"Content-Type": "application/json",
},
json={
"prompt": "Add a crown",
"model": "openai/gpt-image-1",
"size": "1024x1024"
}
)
response.raise_for_status()
data = response.json()
print(json.dumps(data, indent=2, ensure_ascii=False))
if __name__ == "__main__":
main()
We obtained the following 1536x1024 image by running this code example (~ 26 s):

"A T-Rex relaxing on a beach, lying on a sun lounger and wearing sunglasses. Realistic photo."
Edit image: Combine images
Let's combine two images of different sizes using a simple prompt.
from openai import OpenAI
def main():
client = OpenAI(
api_key="<YOUR_AIMLAPI_KEY>",
base_url="https://api.aimlapi.com/v1",
)
result = client.images.edit(
model="openai/gpt-image-1",
image=[
open("t-rex.png", "rb"),
open("crown.png", "rb"),
],
prompt="Put the crown on the T-rex's head"
)
print("Generation:", result)
if __name__ == "__main__":
main()
We obtained the following 1024x1024 image by running this code example (~ 34 s):

Edit image: Use an image mask
In this example, we’ll provide the model with our previously generated image of a T-rex on a beach, along with a same-sized mask where the area occupied by the dinosaur is transparent (alpha = 0). In the prompt, we’ll ask the model to remove the masked object from the image and see how well it handles the task.
from openai import OpenAI
def main():
client = OpenAI(
api_key="<YOUR_AIMLAPI_KEY>",
base_url="https://api.aimlapi.com/v1",
)
result = client.images.edit(
model="openai/gpt-image-1",
image=open("t-rex.png", "rb"),
mask=open('t-rex-alpha_mask.png', 'rb'),
prompt="Remove this from the picture"
)
print("Generation:", result)
if __name__ == "__main__":
main()
We obtained the following 1024x1024 image by running this code example (~ 32 s).

Last updated
Was this helpful?