Unode
User GuideAPI ReferenceHelp & SupportBusiness Cooperation

OpenAI Image Format (Image)

OpenAI Image Format (Image)

Official Documentation

📝 Introduction

Given a text prompt and/or input image, the model will generate new images. OpenAI provides multiple powerful image generation models that can create, edit, and modify images based on natural language descriptions.

🤖 Supported Models

Currently supported models include:

ModelDescription
gpt-image-1GPT-Image-1 image generation model
gpt-image-1.5GPT-Image-1.5 image generation and editing model
gpt-image-2GPT-Image-2 image generation and editing model, supporting multi-image editing capabilities, able to create new composite images based on multiple input images
gpt-image-2.5-sunburstMost capable GPT-Image-2.5 model, optimized for precise image generation and editing. The dated snapshot gpt-image-2.5-sunburst-2026-09-08 is also supported.
gpt-image-2.5-flareFast GPT-Image-2.5 model for high-quality everyday image generation and editing. The dated snapshot gpt-image-2.5-flare-2026-09-08 is also supported.

💡 Request Examples

Create Image ✅

# Generate an image and return a temporary URL
curl https://www.unodetech.xyz/v1/images/generations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $API_KEY" \
  -d '{
    "model": "gpt-image-2",
    "prompt": "A cute little sea otter",
    "n": 1,
    "size": "1024x1024",
    "response_format": "url"
  }'

# Maximum-quality GPT Image 2.5 generation
curl https://www.unodetech.xyz/v1/images/generations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $API_KEY" \
  -d '{
    "model": "gpt-image-2.5-sunburst",
    "prompt": "A cute little sea otter",
    "quality": "max",
    "size": "1024x1024"
  }'

# Transparent background with WebP output
curl https://www.unodetech.xyz/v1/images/generations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $API_KEY" \
  -d '{
    "model": "gpt-image-2",
    "prompt": "A cute little sea otter",
    "background": "transparent",
    "output_format": "webp"
  }'

Response Example:

{
  "created": 1589478378,
  "data": [
    {
      "url": "https://cdn.example.com/generated-images/...?...",
      "revised_prompt": "A cute little sea otter playing in the water, with round eyes and fluffy fur"
    }
  ],
  "background": "opaque",
  "output_format": "png",
  "quality": "high",
  "size": "1024x1024",
  "usage": {
    "total_tokens": 100,
    "input_tokens": 50,
    "output_tokens": 50,
    "input_tokens_details": {
      "text_tokens": 10,
      "image_tokens": 40
    }
  }
}

Edit Image ✅

# GPT Image 2.5 image editing
curl https://www.unodetech.xyz/v1/images/edits \
  -H "Authorization: Bearer $API_KEY" \
  -F image="@otter.png" \
  -F mask="@mask.png" \
  -F model="gpt-image-2.5-sunburst" \
  -F prompt="A cute little sea otter wearing a beret" \
  -F size="1024x1024" \
  -F response_format="url"

# gpt-image-2 multi-image editing example
curl https://www.unodetech.xyz/v1/images/edits \
  -H "Authorization: Bearer $API_KEY" \
  -F "model=gpt-image-2" \
  -F "image[]=@body-lotion.png" \
  -F "image[]=@bath-bomb.png" \
  -F "image[]=@incense-kit.png" \
  -F "image[]=@soap.png" \
  -F "prompt=Create an elegant gift basket containing these four items" \
  -F "quality=high"

Response Example:

{
  "created": 1713833628,
  "data": [
    {
      "url": "https://cdn.example.com/generated-images/...?..."
    }
  ],
  "usage": {
    "total_tokens": 100,
    "input_tokens": 50,
    "output_tokens": 50,
    "input_tokens_details": {
      "text_tokens": 10,
      "image_tokens": 40
    }
  }
}

📮 Request

Endpoints

Create Image

POST /v1/images/generations

Create images based on text prompts.

Edit Image

POST /v1/images/edits

Create edited or extended images based on one or more original images and prompts.

JSON image-edit requests

Image editing supports both multipart/form-data uploads and application/json request bodies. For JSON requests, provide source images in the images array. Each image reference must contain either an image_url (a URL or Base64 data URL) or a file_id. A mask can use the same reference format. All other allowed edit parameters remain the same.

{
  "model": "gpt-image-2.5-sunburst",
  "prompt": "A cute little sea otter wearing a beret",
  "images": [{ "image_url": "https://example.com/otter.png" }],
  "mask": { "file_id": "file-mask" },
  "quality": "max"
  // ...other image-edit parameters
}

Authentication Method

Include the following in the request header for API key authentication:

Authorization: Bearer $API_KEY

Where $API_KEY is your API key.

Request Body Parameters

Create Image (/v1/images/generations)

ParameterTypeRequiredDescription
promptstringYesText description of the desired image. Maximum 32000 characters.
modelstringYesImage generation model, such as gpt-image-1, gpt-image-1.5, gpt-image-2, gpt-image-2.5-sunburst, or gpt-image-2.5-flare. Dated GPT Image 2.5 snapshots ending in -2026-09-08 are also supported.
nintegerNoNumber of images to generate (1–10). Default: 1.
sizestringNoSize of the generated image. Standard options: 1024x1024, 1536x1024 (horizontal), 1024x1536 (vertical), auto. gpt-image-2 and both GPT Image 2.5 variants also accept custom WIDTHxHEIGHT strings; see Custom dimensions. Default: auto.
qualitystringNoQuality of the generated image. Options for GPT Image models: low, medium, high, auto. GPT Image 2.5 Sunburst and Flare additionally support xhigh and max. Default: auto.
backgroundstringNoBackground of the generated image. Options: transparent, opaque, auto. Transparent requires output_format of png or webp. Default: auto.
output_formatstringNoFile format of the returned image. Options: png, jpeg, webp. Default: png.
output_compressionintegerNoCompression level (0–100) for jpeg and webp output. Default: 100.
moderationstringNoContent-moderation strictness for generated images. Options: low, auto. Default: auto.
response_formatstringNoImage response format. Use url for an image URL or b64_json for Base64 data. When omitted, the model or upstream provider's default behavior is preserved.
streambooleanNoGenerate the image in streaming mode. Default: false.
partial_imagesintegerNoNumber of partial images to emit during streaming (0–3). Only valid when stream is true.
userstringNoUnique identifier for the end user to help OpenAI monitor and detect abuse.

URL responses

For GPT Image models that only return Base64, the API stores the generated image and returns a temporary signed URL when URL delivery is available. This parameter is handled by the API compatibility layer and does not require native upstream support for response_format.

Before use, a platform administrator must enable image URL delivery in the current environment and include the current API key or traffic in its rollout. Otherwise, response_format=url returns 503. Clients do not configure or receive Bunny credentials.

Edit Image (/v1/images/edits)

ParameterTypeRequiredDescription
imagefile or file[]YesImage(s) to edit. Each must be a PNG, WEBP, or JPG file, less than 25MB. Up to 16 images can be provided as an array.
promptstringYesText description of the desired edit. Maximum 32000 characters.
maskfileNoPNG image whose transparent areas (alpha = 0) indicate the positions to edit. Must be less than 4MB and the same size as the image.
modelstringYesImage editing model, such as gpt-image-1, gpt-image-1.5, gpt-image-2, gpt-image-2.5-sunburst, or gpt-image-2.5-flare. Dated GPT Image 2.5 snapshots ending in -2026-09-08 are also supported.
nintegerNoNumber of images to generate (1–10). Default: 1.
sizestringNoSize of the generated image. Standard options: 1024x1024, 1536x1024 (horizontal), 1024x1536 (vertical), auto. gpt-image-2 and both GPT Image 2.5 variants also accept custom WIDTHxHEIGHT strings; see Custom dimensions. Default: auto.
qualitystringNoQuality of the generated image. Options for GPT Image models: low, medium, high, auto. GPT Image 2.5 Sunburst and Flare additionally support xhigh and max. Default: auto.
backgroundstringNoBackground of the generated image. Options: transparent, opaque, auto. Transparent requires output_format of png or webp. Default: auto.
output_formatstringNoFile format of the returned image. Options: png, jpeg, webp. Default: png.
output_compressionintegerNoCompression level (0–100) for jpeg and webp output. Default: 100.
input_fidelitystringNoControls how closely the output adheres to the input image(s). Options: high, low.
moderationstringNoContent-moderation strictness for generated images. Options: low, auto. Default: auto.
response_formatstringNoImage response format. Use url for an image URL or b64_json for Base64 data. When omitted, the model or upstream provider's default behavior is preserved.
streambooleanNoGenerate the image in streaming mode. Default: false.
partial_imagesintegerNoNumber of partial images to emit during streaming (0–3). Only valid when stream is true.
userstringNoUnique identifier for the end user to help OpenAI monitor and detect abuse.

Custom dimensions

For gpt-image-2, gpt-image-2.5-sunburst, and gpt-image-2.5-flare (including their dated snapshots), size can be a custom WIDTHxHEIGHT value such as 1536x864. Custom dimensions must meet all of these constraints:

  • Width and height must be multiples of 16.
  • The aspect ratio must be between 1:3 and 3:1.
  • Neither edge can exceed 3840 pixels.
  • The total pixel count must be between 655,360 and 8,294,400 pixels.

Resolutions above 2560x1440 are experimental.

📥 Response

Successful Response

Both endpoints return a response containing a list of image objects.

FieldTypeDescription
createdintegerUnix timestamp (in seconds) of when the image was created
dataarrayList of generated image objects
backgroundstringThe actual background setting used (transparent or opaque)
output_formatstringThe actual output format used (png, webp, or jpeg)
qualitystringThe actual quality level used (low, medium, high, xhigh, or max, depending on the model)
sizestringThe actual dimensions of the generated image
usageobjectToken usage for the API call

usage Fields

FieldTypeDescription
total_tokensintegerTotal tokens used
input_tokensintegerTokens used for input
output_tokensintegerTokens used for output
input_tokens_detailsobjectDetailed breakdown of input tokens: text_tokens and image_tokens

Image Object

Each object in the data array contains:

FieldTypeDescription
urlstringImage URL returned for response_format=url; it may be an upstream-native URL or a temporary signed URL created after Base64 storage.
b64_jsonstringBase64-encoded image data. Returned for response_format=b64_json, an upstream Base64 default, or an allowed URL-delivery fallback.
revised_promptstringThe modified prompt used for generation, if the prompt was revised

Each image object contains either url or b64_json; clients must not assume that both fields are present. URL response example:

{
  "url": "https://cdn.example.com/generated-images/...?...",
  "revised_prompt": "A cute little sea otter playing in the water, with round eyes and fluffy fur"
}

Response Format and URL Delivery

response_formatBehavior
OmittedPreserves the model or upstream provider's default response format. GPT Image models usually return b64_json.
b64_jsonRequests Base64 image data in the response.
urlRequests an image URL. Native URLs pass through; eligible Base64 results are stored and replaced with temporary signed URLs.

Temporary URLs expire. Download or transfer the image soon after receiving the response instead of treating the URL as permanent. If a recoverable URL-delivery failure occurs, the API may return Base64 and set X-Image-Delivery-Fallback: base64. Clients requesting response_format=url should inspect both the response field and this header.

The returned URL includes its access signature and can be downloaded directly with HTTP GET; do not attach the API Authorization header. Keep the complete query string because it is part of the signature:

IMAGE_URL=$(jq -r '.data[0].url // empty' response.json)
test -n "$IMAGE_URL" && curl --fail --location "$IMAGE_URL" --output generated.png

URL delivery applies to non-streaming requests that return one complete JSON response. Do not combine response_format=url with stream=true; process streaming image requests using the selected model's streaming event format.

URL Delivery Errors

HTTP statusError codeRecommended action
400Invalid requestEnsure response_format is the lowercase value url or b64_json.
502image_url_delivery_failedThe image was generated, but storage or URL signing failed in strict mode. Retry later without aggressive immediate retries.
502image_response_too_largeThe generated response exceeded the server processing limit. Reduce the image count or dimensions.
503image_url_delivery_unavailableURL delivery is not enabled for the current model, API key, or environment. Use b64_json or wait for an administrator to enable it.
503Other image_delivery_* errorsURL-delivery capacity or runtime state is temporarily unavailable. Retry with backoff.

🌟 Best Practices

Prompt Writing Tips

  1. Use clear and specific descriptions
  2. Specify important visual details
  3. Describe expected artistic style and atmosphere
  4. Pay attention to composition and perspective instructions

Parameter Selection Tips

  1. Size Selection

    • 1024x1024: General scene best choice
    • 1536x1024/1024x1536: Suitable for horizontal/vertical scenes
  2. Quality

    • quality=high: For images requiring fine details
    • quality=xhigh or quality=max: GPT Image 2.5 only; use for higher-detail final assets when increased latency and cost are acceptable
    • quality=auto: Let the model choose the optimal quality

Common Questions

  1. Image generation failed

    • Check if the prompt complies with content policies
    • Confirm file format and size limits
    • Verify API key permissions
  2. Results do not match expectations

    • Optimize prompt description
    • Adjust quality and style parameters
    • Consider using image editing or variation features

Last updated on