GPT Image 2
Model Overview
As of late April 2026, this is the most advanced and capable image generation model available from OpenAI. It is designed for high-quality text-to-image generation and image editing, supporting prompt-based rendering, structured edits, and efficient token usage with caching.
How to Make a Call
API Schemas
Generate image
The text prompt describing the content, style, or composition of the image to be generated.
The size of the generated image.
1024x1024Possible values: The quality of the image that will be generated.
mediumPossible values: The format of the generated image.
pngPossible values: 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.
autoPossible values: Control the content-moderation level for images.
autoPossible values: The number of images to generate.
1Possible values: Compression level (0-100%), applies to JPEG and WebP only.
100The format in which the generated images are returned.
urlPossible values: curl -L \
--request POST \
--url 'https://api.aimlapi.com/v1/images/generations' \
--header 'Authorization: Bearer <YOUR_AIMLAPI_KEY>' \
--header 'Content-Type: application/json' \
--data '{
"model": "openai/gpt-image-2",
"prompt": "A T-Rex relaxing on a beach, lying on a sun lounger and wearing sunglasses."
}'{
"data": [
{
"url": "https://cdn.aimlapi.com/generations/hedgehog/1749730923700-29fe35d2-4aef-4bc5-a911-6c39884d16a8.png",
"b64_json": null
}
],
"meta": {
"usage": {
"credits_used": 120000,
"usd_spent": 0.06
}
}
}Edit image
The text prompt describing the content, style, or composition of the image to be generated.
One or multiple images to edit. Each must be a local file (png, webp, or jpg), up to 50MB. Maximum 16 images.
The size of the generated image.
1024x1024Possible values: The quality of the image that will be generated.
mediumPossible values: The format of the generated image.
pngPossible values: A local PNG file used as a mask. Transparent areas define where the image will be edited. Must be under 4MB and match the image dimensions.
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.
autoPossible values: The number of images to generate.
1Compression level (0-100%), applies to JPEG and WebP only.
100The format in which the generated images are returned.
urlPossible values: {
"data": [
{
"url": "https://cdn.aimlapi.com/generations/hedgehog/1749730923700-29fe35d2-4aef-4bc5-a911-6c39884d16a8.png",
"b64_json": null
}
],
"meta": {
"usage": {
"credits_used": 120000,
"usd_spent": 0.06
}
}
}Code Examples
Generate image
Let's generate an image of the specified size using a simple prompt.
We obtained the following 1536×1024 image by running this code example (~45 s):

Edit image: Combine images
Let's generate an image using two input images and a prompt that defines how they should be edited.
We obtained the following 1024x1024 image by running this code example (~ 1 min 18 s):

Last updated
Was this helpful?

