gpt-image-1

This documentation is valid for the following list of our models:

  • openai/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

Note that by default, the quality parameter is set to 'medium'. The output image will still look great, but for even more detailed results, consider setting this parameter to 'high'.

Generate image

post
Authorizations
Body
modelundefined · enumRequiredPossible values:
promptstring · max: 32000Required

The text prompt describing the content, style, or composition of the image to be generated.

backgroundstring · enumOptionalDefault: autoPossible values:
moderationstring · enumOptionalDefault: autoPossible values:
nnumber · min: 1 · max: 10Optional

The number of images to generate.

Default: 1
output_compressioninteger · max: 100OptionalDefault: 100
output_formatstring · enumOptional

The format of the generated image.

Default: pngPossible values:
qualitystring · enumOptional

The quality of the image that will be generated.

Default: mediumPossible values:
sizestring · enumOptional

The size of the generated image.

Default: 1024x1024Possible values:
response_formatstring · enumOptional

The format in which the generated images are returned.

Default: urlPossible values:
Responses
201Success
post
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"
}
201Success

No content

Edit image

post
Authorizations
Body
modelstring · enumRequiredPossible values:
promptstring · max: 32000Required

The text prompt describing the content, style, or composition of the image to be generated.

imagestring · binaryRequired

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.

maskstring · binaryOptional

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.

backgroundstring · enumOptional

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.

Default: autoPossible values:
nnumber · min: 1 · max: 10OptionalDefault: 1
output_compressioninteger · max: 100Optional

The compression level (0-100%) for the generated images.

Default: 100
output_formatstring · enumOptional

The format of the generated image.

Default: pngPossible values:
qualitystring · enumOptional

The quality of the image that will be generated.

Default: mediumPossible values:
sizestring · enumOptional

The size of the generated image.

Default: 1024x1024Possible values:
response_formatstring · enumOptional

The format in which the generated images are returned.

Default: urlPossible values:
Responses
201Success
post
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"
}
201Success

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()
Response
{
  "created": 1749730922,
  "background": "opaque",
  "data": [
    {
      "url": "https://cdn.aimlapi.com/generations/hedgehog/1749730923700-29fe35d2-4aef-4bc5-a911-6c39884d16a8.png"
    }
  ],
  "output_format": "png",
  "quality": "medium",
  "size": "1536x1024",
  "usage": {
    "input_tokens": 29,
    "input_tokens_details": {
      "image_tokens": 0,
      "text_tokens": 29
    },
    "output_tokens": 1568,
    "total_tokens": 1597
  }
}

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."
More images
"A T-Rex relaxing on a beach, lying on a sun lounger and wearing sunglasses."
"Racoon eating ice-cream"

Edit image: Combine images

Let's combine two images of different sizes using a simple prompt.

Our input images
t-rex.png
crown.png
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()
Response
Generation: ImagesResponse(created=1750278299, data=[Image(b64_json=None, revised_prompt=None, url='https://cdn.aimlapi.com/generations/hedgehog/1750278300281-023df523-e986-431c-bb61-5b9e43301cef.png')], usage=Usage(input_tokens=574, input_tokens_details=UsageInputTokensDetails(image_tokens=517, text_tokens=57), output_tokens=1056, total_tokens=1630), background='opaque', output_format='png', quality='medium', size='1024x1024')

We obtained the following 1024x1024 image by running this code example (~ 34 s):

A true king of the monsters. On vacation.

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.

Image & Mask
Image
Mask
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()
Response
Generation: ImagesResponse(created=1750275775, data=[Image(b64_json=None, revised_prompt=None, url='https://cdn.aimlapi.com/generations/hedgehog/1750275776080-3fbcf9fc-b8ec-47f1-bb77-4a7e370a3a0c.png')], usage=Usage(input_tokens=360, input_tokens_details=UsageInputTokensDetails(image_tokens=323, text_tokens=37), output_tokens=1056, total_tokens=1416), background='opaque', output_format='png', quality='medium', size='1024x1024')

We obtained the following 1024x1024 image by running this code example (~ 32 s).

Our dinosaur has disappeared into thin air!

Last updated

Was this helpful?