OpenAI: GPT Images 2 (Text to Image) API Reference

About

GPT Image 2 is OpenAI's next-generation image generation model. It supports flexible resolutions up to 4K and multiple model variants.

Use it as a text-to-image API through Infron!

1. Calling the API

Setup your API Key

To begin using Infron, you first need to create an account and generate your API Key.

Once you have your API key, set it as an environment variable in your runtime environment. This allows your applications to securely access Infron’s API.

export INFRON_KEY="YOUR_API_KEY"

Submit a request

For long-running requests, you can poll for results.

curl https://media.onerouter.pro/v1/images/generations \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "openai/gpt-image-2/text-to-image",
  "n": 1,
  "size": "auto",
  "quality": "auto",
  "output_format": "png",
  "background": "auto",
  "moderation": "auto",
  "prompt": "An anthropomorphic lamb in the style of an everyday snapshot."
}'

Response with queue task id

The response will look like this:

{
  "code": 200,
  "message": "success",
  "data": {
    "task_id": "924c0599dd1643c497f87f76099802c1",
    "object": "image",
    "model": "openai/gpt-image-2/text-to-image",
    "status": "created",
    "urls": {
      "query": "https://media.onerouter.pro/v1/images/tasks/924c0599dd1643c497f87f76099802c1"
    },
    "created_at": "2026-07-16 02:54:03.04"
  }
}

Fetch request status

You can fetch the status of a request to check if it is completed or still in progress.

curl https://media.onerouter.pro/v1/images/tasks/{task_id} \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" 

# For example
curl https://media.onerouter.pro/v1/images/tasks/924c0599dd1643c497f87f76099802c1 \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json"

Response with queue task status query

{
  "code": 200,
  "message": "success",
  "data": {
    "task_id": "924c0599dd1643c497f87f76099802c1",
    "object": "image",
    "model": "openai/gpt-image-2/text-to-image",
    "status": "in_progress",
    "fail_reason": "",
    "submit_time": 1784170443,
    "start_time": 1784170443,
    "finish_time": 0,
    "outputs": [],
    "created_at": "2026-07-16 02:54:03"
  }
}

Possible statuses:

  • created
  • in_progress
  • processing
  • completed
  • failed

created -> in_progress → processing → completed | failed

Poll every 1-2 seconds until status is "completed" or "failed"

Get the result (when status is "completed")

Once the request is completed, you can fetch the result. See the Output Schema for the expected result format.

{
  "code": 200,
  "message": "success",
  "data": {
    "task_id": "924c0599dd1643c497f87f76099802c1",
    "object": "image",
    "model": "openai/gpt-image-2/text-to-image",
    "status": "completed",
    "fail_reason": "",
    "submit_time": 1784170443,
    "start_time": 1784170443,
    "finish_time": 1784170464,
    "outputs": [
      "https://storage.googleapis.com/infron_gcs/image%2Fgenerated%2Fofficial_openai_image_32bd4efead384d31a1b9ba1ba8e00582.png"
    ],
    "usage": {
      "completion_tokens": 201,
      "completion_tokens_details": {
        "image_tokens": 201,
        "text_tokens": 0
      },
      "image_count": 1,
      "image_quality": "auto",
      "prompt_tokens": 18,
      "prompt_tokens_details": {
        "image_tokens": 0,
        "text_tokens": 18
      },
      "quality": "auto",
      "size": "auto",
      "total_tokens": 219,
      "web_search": false
    },
    "cost": {
      "total_cost": 0.004896,
      "cost_details": {
        "prompt_cost": 0,
        "completion_cost": 0,
        "image_cost": 0.004896,
        "video_cost": 0,
        "audio_cost": 0,
        "native_web_search_cost": 0,
        "plugin_web_search_cost": 0,
        "tools_cost": 0,
        "prompt_cache_read_cost": 0,
        "prompt_cache_write_cost": 0,
        "prompt_cache_write_5_min": 0,
        "prompt_cache_write_1_h": 0,
        "reasoning_cost": 0,
        "discount_rate": 1,
        "is_byok": false,
        "byok_cost": 0
      }
    },
    "created_at": "2026-07-16 02:54:03"
  }
}

2. Schema

Input

ParameterTypeRequiredDefaultRangeDescription
modelstringYes--Explore all modelsModel name.
promptstringYes----Text prompt for generation; Positive text prompt.
nintegerNo1>=1Number of images to generate.
sizestringNoautoauto, 1024x1024, 1536x1024, 1024x1536, 2048x2048, 2048x1152, 3840x2160, 2160x3840, "WIDTHxHEIGHT"The size of the generated image. Use 'auto' to infer from input images. You can also use 'WIDTHxHEIGHT' format to specify the exact size. The model supports any resolution passed in the size parameter as long as all of these constraints are met: 1) Maximum edge length must be less than 3840px; 2) Both edges must be a multiple of 16; 3) Ratio between the long edge and short edge must not be greater than 3:1; 4) Total pixels must not exceed 8,294,400; 5) Total pixels must not be less than 655,360.
qualitystringNoautoauto, low, medium, highQuality for the generated image. Use 'auto' to let the model pick the best quality for the prompt.
output_formatstringNopngpng, jpeg, webpOutput format for the images.
backgroundstringNoautoauto, opaqueOpaque or automatic.
moderationstringNoautoauto, lowYou can control moderation strictness with the moderation parameter.

Example request

curl https://media.onerouter.pro/v1/images/generations \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "openai/gpt-image-2/text-to-image",
  "n": 1,
  "size": "auto",
  "quality": "auto",
  "output_format": "png",
  "background": "auto",
  "moderation": "auto",
  "prompt": "An anthropomorphic lamb in the style of an everyday snapshot."
}'

Output

ParameterTypeRangeDescription
codeinteger--Status code of the request.
messagestring--Status message of the request.
dataobject--Data of the task.
data.task_idstring--ID of the task.
data.objectstring--Object type of the task.
data.modelstring--Model name of the task.
data.statusstringcreated, in_progress, processing, completed, failedStatus of the task.
data.fail_reasonstring--Fail reason of the task.
data.submit_timeinteger--Timestamp of the task submission.
data.start_timeinteger--Timestamp of the task start.
data.finish_timeinteger--Timestamp of the task finish.
data.outputsarray--Outputs of the task.
data.created_atstring--Timestamp of the task creation.

Example output

{
  "code": 200,
  "message": "success",
  "data": {
    "task_id": "924c0599dd1643c497f87f76099802c1",
    "object": "image",
    "model": "openai/gpt-image-2/text-to-image",
    "status": "completed",
    "fail_reason": "",
    "submit_time": 1784170443,
    "start_time": 1784170443,
    "finish_time": 1784170464,
    "outputs": [
      "https://storage.googleapis.com/infron_gcs/image%2Fgenerated%2Fofficial_openai_image_32bd4efead384d31a1b9ba1ba8e00582.png"
    ],
    "usage": {
      "completion_tokens": 201,
      "completion_tokens_details": {
        "image_tokens": 201,
        "text_tokens": 0
      },
      "image_count": 1,
      "image_quality": "auto",
      "prompt_tokens": 18,
      "prompt_tokens_details": {
        "image_tokens": 0,
        "text_tokens": 18
      },
      "quality": "auto",
      "size": "auto",
      "total_tokens": 219,
      "web_search": false
    },
    "cost": {
      "total_cost": 0.004896,
      "cost_details": {
        "prompt_cost": 0,
        "completion_cost": 0,
        "image_cost": 0.004896,
        "video_cost": 0,
        "audio_cost": 0,
        "native_web_search_cost": 0,
        "plugin_web_search_cost": 0,
        "tools_cost": 0,
        "prompt_cache_read_cost": 0,
        "prompt_cache_write_cost": 0,
        "prompt_cache_write_5_min": 0,
        "prompt_cache_write_1_h": 0,
        "reasoning_cost": 0,
        "discount_rate": 1,
        "is_byok": false,
        "byok_cost": 0
      }
    },
    "created_at": "2026-07-16 02:54:03"
  }
}

3. Detailed Pricing

SizeLow QualityMedium QualityHigh Quality
1024 x 1024$0.006$0.053$0.211
1536 x 1024$0.005$0.042$0.165
1024 x 1536$0.005$0.042$0.165
2048 x 2048$0.008$0.064$0.256
2048 x 1152$0.006$0.048$0.192
3840 x 2160$0.012$0.101$0.401
2160 x 3840$0.012$0.101$0.401