APIMODELSAPIMODELS
API Documentation

apimodels.app

Docs/GPT Image 2 Upscaled API
IMG

GPT Image 2 Upscaled API

This is an upscaled variant: 2K and 4K images are generated smaller and then upscaled to the target size, so fine detail and texture are below native 2K / 4K. It suits test runs, bulk previews and images where fine detail is not critical. For print-level detail, legible small text or native 4K, use gpt-image-2.

Text-to-image and image editing with the same request format as gpt-image-2. 1K / 2K / 4K output. Async: POST creates a task, then poll with GET ?task_id= or supply a callback_url.

Authentication

Add the Authorization header with your API key to every request:

Authorization: Bearer YOUR_API_KEY

Pricing

ResolutionPrice per imageOutput
1K$0.01Around 1 megapixel (e.g. 1024x1024 for 1:1)
2K$0.015Generated smaller, upscaled to 2K
4K$0.02Generated smaller, upscaled to 4K

USD per image. The price depends only on resolution, not on quality, aspect ratio or prompt length. Failed requests are not charged.

Endpoints

POST/api/v1/images/generations

Create an image task (text-to-image, or editing when reference images are provided).

GET/api/v1/images/generations?task_id=xxx

Query task status and get the image URL.

Request Parameters

modelrequiredstring
Must be "gpt-image-2-upscaled".
promptrequiredstring
Prompt or editing instructions. When editing multiple images, reference them as "image 1", "image 2". Length 1–20000 chars.
aspect_ratiostring
Output aspect ratio; see the supported list per resolution below. Omit or pass "auto": when editing, the output follows the reference image; for text-to-image it falls back to 1:1.
resolutionstring
"1K" (default) / "2K" / "4K". 1K $0.01, 2K $0.015, 4K $0.02. 2K and 4K are upscaled (see the notice above).
image_urlstring
Single reference image URL (publicly reachable). Providing it routes the request to image editing. ≤ 10MB.
image_urlsstring[]
Multiple reference image URLs (up to 16, ≤ 10MB each). Beyond 16, only the first 16 are used.
image_base64string
Base64-encoded or data-URI reference image (for local files). Mutually exclusive with image_url.
image_mime_typestring
MIME type of image_base64. Default image/jpeg. Supports image/png, image/jpeg, image/webp.
callback_urlstring
Webhook URL called when the task reaches completed or failed. See "Webhook Callback" below.

Supported Aspect Ratios

Resolutionaspect_ratio
1K1:1 / 2:3 / 3:2 / 4:5 / 5:4 / 4:3 / 3:4 / 16:9 / 9:16 / 21:9
2K1:1 / 2:3 / 3:2 / 4:3 / 3:4 / 16:9 / 9:16 / 21:9
4K1:1 / 2:3 / 3:2 / 4:3 / 3:4 / 16:9 / 9:16 / 21:9

5:4 and 4:5 are supported at 1K only. At 2K / 4K use 1K instead, or switch to 4:3 / 3:4.

Code Examples

# Create task: 2K, 16:9 text-to-image
curl -X POST https://api.apimodels.app/v1/images/generations \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2-upscaled",
    "prompt": "A cherry blossom tree by a tranquil river at dawn, soft light",
    "aspect_ratio": "16:9",
    "resolution": "2K"
  }'

# Response:
# { "code": 200, "msg": "success", "data": { "taskId": "clxxx...", "state": "pending" } }

# Poll task status
curl "https://api.apimodels.app/v1/images/generations?task_id=TASK_ID" \
  -H "Authorization: Bearer YOUR_API_KEY"

Response Format

Create task response

{
  "code": 200,
  "msg": "success",
  "data": {
    "taskId": "clxxx...",
    "state": "pending"
  }
}

Poll response (completed)

{
  "code": 200,
  "msg": "success",
  "data": {
    "taskId": "clxxx...",
    "state": "completed",
    "resultUrls": ["https://r2.apimodels.app/images/xxx.png"],
    "costTime": 14320,
    "completeTime": 1705123465000
  }
}

Poll response (failed)

{
  "code": 200,
  "msg": "success",
  "data": {
    "taskId": "clxxx...",
    "state": "failed",
    "failMsg": "Content policy violation"
  }
}

Webhook Callback (callback_url)

Pass callback_url in the create request. When the task reaches the completed or failed state, our server sends an HTTP POST to that URL with Content-Type: application/json (no signing header). Delivery is retried up to 3 times with exponential backoff (10s timeout per attempt); if still unsuccessful, a background job keeps retrying for up to 30 minutes until your endpoint returns 2xx.

Payload structure

POST {your callback_url}
Content-Type: application/json

{
  "code": 200,
  "msg": "success",
  "data": {
    "taskId": "clxxx...",
    "model": "gpt-image-2-upscaled",
    "state": "completed" | "failed",
    "param": "<JSON string>",             // request params, JSON.parse once
    "resultJson": "<JSON string> | null", // result object, JSON.parse once
    "failCode": null | "string",
    "failMsg": null | "string",
    "costTime": 14320,                     // duration in ms
    "completeTime": 1705123465000,         // ms epoch
    "createTime": 1705123450000            // ms epoch
  }
}

Note: data.param and data.resultJson are JSON strings. Call JSON.parse once on each. After parsing, resultJson is { "resultUrls": ["https://..."] }; when state=failed it is usually null or {"resultUrls":[]}.

Task States

pendingTask queued
processingImage is being generated
completedDone, resultUrls available
failedFailed, not charged

Error Codes

400Bad Request - missing or invalid parameters
401Unauthorized - invalid API key
402Payment Required - insufficient credits
404Not Found - task ID not found
500Internal Server Error

Notes

  • *Each request returns one image.
  • *quality is accepted but has no effect on this model. The price depends only on resolution.
  • *1K output is around 1 megapixel (e.g. 1024x1024 for 1:1).
  • *Prompt only → text-to-image; with image_url / image_urls / image_base64 → image editing.
  • *Image inputs can be public URLs, data:<mime>;base64,... URIs, or bare base64 strings. Up to 16 per request.
  • *resultUrls are R2 links auto-deleted after 30 days. Download or re-host them within that window.
  • *Failed tasks (state=failed) are not billed, so retrying is safe.