Skip to main content

Images API

POST /v1/images/generations

The Images API generates images from text prompts using models like DALL-E, gpt-image-1, and gpt-image-1.5.

HTTP Request

curl https://api.apertis.ai/v1/images/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <APERTIS_API_KEY>" \
-d '{
"model": "gpt-image-1",
"prompt": "A cute baby sea otter",
"n": 1,
"size": "1024x1024"
}'

Authentication

HeaderFormatExample
AuthorizationBearer tokenAuthorization: Bearer sk-your-api-key

Parameters

Required Parameters

ParameterTypeDescription
promptstringA text description of the desired image(s). See prompt limits below

Prompt Length Limits

ModelMax Prompt Length
dall-e-21000 characters
dall-e-34000 characters
gpt-image-132000 characters
gpt-image-1.532000 characters

Optional Parameters

ParameterTypeDescription
modelstringThe model to use for image generation. Default: dall-e-2
nintegerNumber of images to generate (1-10). Default: 1
sizestringSize of the generated images (see Size Options below)
qualitystringQuality of the image: standard, hd. Default: standard
response_formatstringFormat of the response: url, b64_json. Default: url
stylestringStyle of the image: vivid, natural. Default: vivid
userstringA unique identifier for the end-user

gpt-image-1 and gpt-image-1.5 Specific Parameters

ParameterTypeDescription
backgroundstringBackground type: transparent, opaque, auto. Default: auto
moderationstringModeration level: low, auto. Default: auto
output_formatstringOutput format: png, jpeg, webp. Default: png
output_compressionintegerCompression level (0-100%) for jpeg/webp output formats. Default: 100

Note: GPT image models always return base64-encoded images (b64_json). The response_format parameter with url option is not supported for these models.

Size Options

ModelSupported Sizes
dall-e-2256x256, 512x512, 1024x1024
dall-e-31024x1024, 1792x1024, 1024x1792
gpt-image-11024x1024, 1536x1024, 1024x1536, auto
gpt-image-1.51024x1024, 1536x1024, 1024x1536, auto

Example Usage

Python

from openai import OpenAI

client = OpenAI(
api_key="sk-your-api-key",
base_url="https://api.apertis.ai/v1"
)

response = client.images.generate(
model="gpt-image-1",
prompt="A white siamese cat",
n=1,
size="1024x1024"
)

print(response.data[0].url)

JavaScript

import OpenAI from 'openai';

const client = new OpenAI({
apiKey: 'sk-your-api-key',
baseURL: 'https://api.apertis.ai/v1'
});

const response = await client.images.generate({
model: 'gpt-image-1',
prompt: 'A white siamese cat',
n: 1,
size: '1024x1024'
});

console.log(response.data[0].url);

With Transparent Background (gpt-image-1)

response = client.images.generate(
model="gpt-image-1",
prompt="A logo of a blue bird on transparent background",
n=1,
size="1024x1024",
background="transparent"
)

HD Quality with DALL-E 3

response = client.images.generate(
model="dall-e-3",
prompt="A stunning sunset over mountains",
n=1,
size="1792x1024",
quality="hd",
style="vivid"
)

Response Format

DALL-E Response (with URL)

{
"created": 1699000000,
"data": [
{
"url": "https://...",
"revised_prompt": "A cute baby sea otter floating on its back..."
}
]
}

GPT Image Response (base64)

{
"created": 1699000000,
"data": [
{
"b64_json": "iVBORw0KGgoAAAANSUhEUgAA..."
}
],
"usage": {
"total_tokens": 100,
"input_tokens": 50,
"output_tokens": 50
}
}

Response Fields

FieldTypeDescription
createdintegerUnix timestamp of when the image was created
dataarrayArray of generated image objects
data[].urlstringURL of the generated image (DALL-E models only, valid for 60 minutes)
data[].b64_jsonstringBase64-encoded image (GPT image models, or when response_format is b64_json)
data[].revised_promptstringThe prompt used to generate the image (may be revised by the model)
usageobjectToken usage information (GPT image models only)
usage.total_tokensintegerTotal tokens used
usage.input_tokensintegerInput tokens used
usage.output_tokensintegerOutput tokens used

Supported Models

ModelDescription
dall-e-2Original DALL-E model, fast generation
dall-e-3Higher quality, better prompt following
gpt-image-1Advanced model with transparent background support
gpt-image-1.5Latest model with enhanced image quality and transparent background support

Image Edits

POST /v1/images/edits

The Image Edits endpoint allows you to edit or extend existing images using models like gpt-image-1 and gpt-image-1.5.

HTTP Request

curl https://api.apertis.ai/v1/images/edits \
-H "Authorization: Bearer <APERTIS_API_KEY>" \
-F "[email protected]" \
-F "prompt=Add a rainbow in the sky" \
-F "model=gpt-image-1" \
-F "size=1024x1024"

Parameters

ParameterTypeRequiredDescription
imagefileYesThe image to edit. PNG, WebP, or JPG under 50MB for gpt-image-1/1.5
promptstringYesA text description of the desired edit. Max 32,000 characters for gpt-image-1/1.5
maskfileNoMask image indicating transparent areas to edit. PNG under 4MB
modelstringNoModel to use: gpt-image-1, gpt-image-1.5, flux-kontext-pro, flux-kontext-max
nintegerNoNumber of images to generate (1-10). Default: 1
sizestringNoSize: 1024x1024, 1536x1024, 1024x1536, auto. Default: auto
qualitystringNoQuality: high, medium, low, auto. Default: auto for gpt-image-1/1.5
response_formatstringNoResponse format: url, b64_json. GPT image models always return base64
userstringNoA unique identifier for the end-user

gpt-image-1 and gpt-image-1.5 Edit Parameters

ParameterTypeDescription
backgroundstringBackground type: transparent, opaque, auto. Default: auto
moderationstringModeration level: low, auto. Default: auto
output_formatstringOutput format: png, jpeg, webp. Default: png
output_compressionintegerCompression level (0-100%) for jpeg/webp output formats. Default: 100

gpt-image-1 Only Parameter

ParameterTypeDescription
input_fidelitystringControl how much the model matches input image features: high, low. Default: low

Example Usage

Python

from openai import OpenAI

client = OpenAI(
api_key="sk-your-api-key",
base_url="https://api.apertis.ai/v1"
)

response = client.images.edit(
model="gpt-image-1",
image=open("original.png", "rb"),
prompt="Add a sunset in the background",
n=1,
size="1024x1024"
)

print(response.data[0].url)

JavaScript

import OpenAI from 'openai';
import fs from 'fs';

const client = new OpenAI({
apiKey: 'sk-your-api-key',
baseURL: 'https://api.apertis.ai/v1'
});

const response = await client.images.edit({
model: 'gpt-image-1',
image: fs.createReadStream('original.png'),
prompt: 'Add a sunset in the background',
n: 1,
size: '1024x1024'
});

console.log(response.data[0].url);

With Mask for Inpainting

response = client.images.edit(
model="gpt-image-1",
image=open("original.png", "rb"),
mask=open("mask.png", "rb"),
prompt="Replace the masked area with a beautiful garden",
n=1,
size="1024x1024"
)