GPT Image 2

POSThttps://api.newportai.com/api/async/gpt_image

The GPT Image 2 API leverages OpenAI's gpt-image-2 model to generate high-quality images from text prompts with customizable quality levels and sizes. It supports image-to-image editing via reference images, batch generation, and flexible aspect ratios.

  • Submit a POST request to the GPT Image 2 API to obtain a taskId.
  • Submit a POST request to the Polling API to retrieve the generated images.
  • Configure a Callback URL to receive results automatically on completion.

Request Headers

Content-Type string Required

Enum: application/json

Authorization string Required

Bearer authentication token. Example: Bearer {{APIKey}}.

Request Body

prompt string Required

The text description of the image to generate. Maximum length is 4000 characters.

width integer Optional

The width of the generated image in pixels. Must be a multiple of 16 and between 16 and 3840. Default value: 1024.

height integer Optional

The height of the generated image in pixels. Must be a multiple of 16 and between 16 and 3840. Default value: 1024.

quality string Optional

The quality level of the generated image. Enum: low, medium, high. Lower quality generates faster results with fewer credits. Default value: low.

n integer Optional

The number of images to generate in a single request. Must be between 1 and 10. Default value: 1.

images array Optional

A list of publicly accessible reference image URLs (maximum 4 items). When provided, the API performs image-to-image editing based on the reference images. Supported formats include JPG, JPEG, PNG, WEBP, and GIF.

Response

code integer

Returns 0 for success, or a specific error code.

message string

Returns "success" or a descriptive error message.

data object
taskId string

The unique identifier for the task. Use this ID with the Polling API to retrieve the generated images.

Errors

10192Illegal param

Polling

Use the Polling API to retrieve the processing results.

Callback

Alternatively, you can enable Callback to receive task results automatically upon completion.

0Task Completed
{
    "code": 0,
    "message": "success",
    "data": {
        "images": [
            {
                "imageUrl": "https://dreamface-resource-new.oss-cn-hongkong.aliyuncs.com/df-ability-tmp/84064945-12a0-4ced-8b44-88663f5a1ac1-0.jpg",
                "imageType": "png"
            }
        ],
        "task": {
            "taskId": "API-177ecf0d5aac4571b9ce1bec58f26524",
            "status": 3,
            "errorCode": 0,
            "reason": "ok",
            "taskType": "gpt_image",
            "executionTime": 229393,
            "creditsConsumed": 144,
            "expire": 1780651903492
        }
    }
}
Request
cURL
curl -X POST 'https://api.newportai.com/api/async/gpt_image' \
  -H "Authorization: Bearer {{APIKey}}" \
  -H 'Content-Type: application/json' \
  -d '{
    "width":1024,
    "height":1024,
    "quality":"high",
    "prompt":"A wild ginseng plant with intact roots and natural soil, macro photography, 8K",
    "n":1
}'
0Successful
{
    "code": 0,
    "message": "success",
    "data": {
        "taskId": "API-177ecf0d5aac4571b9ce1bec58f26524"
    }
}