GPT Image 2
gpt-image-2 uses the standard OpenAI Images API for text-to-image and reference-image editing. This page defines the public request and response standard only.
Endpoints
| Use case | Method | Path | Request format |
|---|---|---|---|
| Text-to-image | POST | /v1/images/generations | application/json |
| Reference-image editing / image-to-image | POST | /v1/images/edits | multipart/form-data |
Request Parameters
| Parameter | Required | Description |
|---|---|---|
model | Yes | Use gpt-image-2 |
prompt | Yes | Image prompt |
size | No | Output size in WIDTHxHEIGHT format, such as 1024x1024, 1536x1024, 1024x1536, 2560x1440, or 3840x2160 |
n | No | Number of images. Defaults to 1 |
quality | No | auto, low, medium, or high. If omitted, the model default is used |
response_format | No | url or b64_json. If omitted, the platform default is used |
user | No | End-user identifier |
/v1/images/edits must also upload the reference image as a file field named image. Use only the request parameters listed on this page.
Size Rules
sizeusesWIDTHxHEIGHT; width and height must be multiples of16.- The aspect ratio must be between
1:3and3:1. - You can use up to
3840x2160-class dimensions. Sizes above2560x1440are high-resolution/experimental, so test them in small batches first. - The standard OpenAI Images API for
gpt-image-2does not useresolution,aspect_ratio, orimage_sizeas public request parameters.
Common size examples:
| Target | Example size |
|---|---|
| 1:1 standard | 1024x1024 |
| 4:3 standard | 1024x768 |
| 3:4 standard | 768x1024 |
| 16:9 2K | 2560x1440 |
| 9:16 2K | 1440x2560 |
| 16:9 4K | 3840x2160 |
| 9:16 4K | 2160x3840 |
Text-to-Image Example
bash
curl -X POST https://cubicspaces.cloud/v1/images/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "gpt-image-2",
"prompt": "Generate a clean product photo of a red ceramic mug on a white tabletop",
"size": "1024x768",
"n": 1,
"quality": "auto",
"response_format": "b64_json"
}'Reference-Image Editing Example
bash
curl -X POST https://cubicspaces.cloud/v1/images/edits \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "model=gpt-image-2" \
-F "prompt=Generate a clean product photo based on the reference image" \
-F "image=@reference.png" \
-F "size=1024x768" \
-F "n=1" \
-F "quality=auto" \
-F "response_format=b64_json"Response Shape
json
{
"created": 1778218450,
"data": [
{
"b64_json": "iVBORw0KGgo...",
"revised_prompt": "A clean product photo..."
}
]
}If response_format=url is requested and supported by the selected model, data[0] contains a url field. Always read the image result from data[0].b64_json or data[0].url.