Skip to main content
AI

GPT-Image-2 Image Generation

Use gpt-image-2 for text-to-image and image editing through the OpenAI-compatible image endpoints. This model uses size to control both dimensions and aspect ratio. It does not support aspect_ratio.

Endpoint

POST /v1/images/generations
POST /v1/images/edits

Use /v1/images/generations for text-to-image. Use /v1/images/edits when a reference image is included.

Authentication

Authorization: Bearer sk-***
Content-Type: application/json

Request Parameters

ParameterTypeRequiredDescription
modelstringYesUse gpt-image-2.
promptstringYesImage generation or editing prompt.
imagestring/objectConditionalReference image for editing.
imagesarrayConditionalMultiple reference images when supported.
sizestringYesOutput dimensions. Must be one of the supported size values.
qualitystringNolow, medium, or high. Default: medium.
output_formatstringNopng, jpeg, or webp.
nintegerNoOutput image count. Default: 1; range: 1 to 8.
response_formatstringNoPrefer url.

Supported Sizes

Common values:

SizeRatioTier
1024x7684:31K
768x10243:41K
1024x10241:11K
1536x86416:91K
864x15369:161K
1920x108016:92K
1080x19209:162K
1536x15361:12K
2048x20481:14K
3840x216016:94K
2160x38409:164K

Use the product model configuration as the source of truth for the complete enabled size matrix.

Text-To-Image Example

curl -X POST "{BASE_URL}/v1/images/generations" \
-H "Authorization: Bearer sk-***" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "A small blue glass sphere on a clean white desk, minimal product photo, soft daylight",
"size": "1024x768",
"quality": "low",
"output_format": "webp",
"n": 1,
"response_format": "url"
}'

Image Editing Example

curl -X POST "{BASE_URL}/v1/images/edits" \
-H "Authorization: Bearer sk-***" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "Keep the product shape, change the background to a bright studio scene",
"image": "https://example.com/input.png",
"size": "1024x1024",
"quality": "medium",
"output_format": "png",
"n": 1,
"response_format": "url"
}'

Response Example

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

Billing Notes

gpt-image-2 uses a parameter matrix based on size + quality, multiplied by n. output_format controls file type and is not a separate billing dimension in the current source scope.

Common Errors

  • Missing size.
  • Passing aspect_ratio; use size instead.
  • Passing quality outside low, medium, or high.
  • Requesting n outside 1 to 8.
  • Using an unsupported size for the current account.