Skip to content

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 caseMethodPathRequest format
Text-to-imagePOST/v1/images/generationsapplication/json
Reference-image editing / image-to-imagePOST/v1/images/editsmultipart/form-data

Request Parameters

ParameterRequiredDescription
modelYesUse gpt-image-2
promptYesImage prompt
sizeNoOutput size in WIDTHxHEIGHT format, such as 1024x1024, 1536x1024, 1024x1536, 2560x1440, or 3840x2160
nNoNumber of images. Defaults to 1
qualityNoauto, low, medium, or high. If omitted, the model default is used
response_formatNourl or b64_json. If omitted, the platform default is used
userNoEnd-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

  • size uses WIDTHxHEIGHT; width and height must be multiples of 16.
  • The aspect ratio must be between 1:3 and 3:1.
  • You can use up to 3840x2160-class dimensions. Sizes above 2560x1440 are high-resolution/experimental, so test them in small batches first.
  • The standard OpenAI Images API for gpt-image-2 does not use resolution, aspect_ratio, or image_size as public request parameters.

Common size examples:

TargetExample size
1:1 standard1024x1024
4:3 standard1024x768
3:4 standard768x1024
16:9 2K2560x1440
9:16 2K1440x2560
16:9 4K3840x2160
9:16 4K2160x3840

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.