APIMODELSAPIMODELS
Документация API

apimodels.app

Docs/GPT Image 2 API

GPT Image 2 API reference

OpenAI gpt-image-2. A single endpoint handles text-to-image and multi-image editing (up to 16 reference images, 30MB each); output composition is driven by aspect_ratio. Native 1K / 2K / 4K ($0.025 / $0.03 / $0.05). Async: POST creates the task, then poll with GET ?task_id= or supply a callback_url.

Model page: GPT Image 2 API — pricing, specs and the playground

Authentication

Authorization: Bearer YOUR_API_KEY

Model & pricing

ModelmodelPriceNotes
GPT Image 2gpt-image-2$0.025 / $0.03 / $0.05Async · 1K / 2K / 4K tiers

Endpoints

POST/api/v1/images/generationscreate task
GET/api/v1/images/generations?task_id=...poll status

Code examples

# ─── 1. Text-to-image ──────────────────────────────────────
# resolution: "1K" | "2K" | "4K" (optional, default 1K). aspect_ratio: 1:1, 3:2, 2:3, 4:3, 3:4, 16:9, 9:16.
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",
    "prompt": "A minimalist product shot of a white sneaker on a pastel gradient backdrop, soft studio lighting",
    "aspect_ratio": "1:1",
    "resolution": "2K"
  }'

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


# ─── 2. Image editing with a reference URL ─────────────────
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",
    "prompt": "Place this product on a marble kitchen counter with soft morning light",
    "image_url": "https://example.com/product.jpg",
    "aspect_ratio": "3:2"
  }'


# ─── 3. Multi-image fusion (up to 10 reference images) ─────
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",
    "prompt": "Use the model from image 1 wearing the outfit from image 2, studio lighting",
    "image_urls": [
      "https://example.com/model.jpg",
      "https://example.com/outfit.jpg"
    ],
    "aspect_ratio": "2:3"
  }'


# ─── 4. Image editing via base64 ───────────────────────────
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",
    "prompt": "Add a geometric fox logo in the center of the mug",
    "image_base64": "iVBORw0KGgoAAAANSUhEUgAA...",
    "image_mime_type": "image/png",
    "aspect_ratio": "1:1"
  }'


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

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


# ─── 6. Webhook callback (optional) ────────────────────────
# Add "callback_url" to the create request and your endpoint
# will receive a POST with the same payload when the task
# completes — useful for production to avoid polling.
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",
    "prompt": "Studio photo of a ceramic mug",
    "aspect_ratio": "1:1",
    "callback_url": "https://your-domain.com/webhook/image"
  }'

Request parameters

FieldRequiredTypeDescription
modelYesstringMust be "gpt-image-2"
promptYesstringPrompt or editing instructions. When editing multiple images, reference them as "image 1", "image 2". Length 1–20000 chars.
aspect_ratioNostringOutput aspect ratio. Enum: 1:1 / 2:3 / 3:2 / 4:5 / 5:4 / 4:3 / 3:4 / 16:9 / 9:16 / 21:9. Omit or pass "auto" — see the note below. Note: 5:4 and 4:5 are supported at 1K only — not at 2K/4K (use 1K, or switch to 3:4 / 4:3). Note on auto: when editing, it follows the reference image; for text-to-image there is nothing to follow, so it falls back to a 1:1 square rather than letting the model choose. Pick an enum value when you need a shape. Two things measured on 2026-08-13: asking for a ratio in the prompt does nothing (prompt-only "5:2" with no size still returned 1024x1024), and an exact size outside the enum is snapped to the nearest grid step (1600x640 for 5:2 and 1552x656 for 21:9 both came back 1456x624). The widest shape currently reachable is 21:9 (2.33).
resolutionNostring"1K" (default) / "2K" / "4K". Tiered pricing: 1K $0.025, 2K $0.03, 4K $0.05.
image_urlNostringSingle reference image URL (publicly reachable). Providing it routes to image-to-image. ≤ 10MB.
image_urlsNostring[]Multiple reference image URLs (up to 16, ≤ 10MB each) for multi-image fusion. Beyond 16, only the first 16 are used.
image_base64NostringBase64-encoded or data-URI reference image (for local files). Mutually exclusive with image_url.
image_mime_typeNostringMIME type of image_base64. Default image/jpeg. Supports image/png, image/jpeg, image/webp.
output_formatNostringDelivery format: "png" / "jpeg" / "webp". Default when omitted: opaque images are delivered as JPEG q95, images with an alpha channel stay PNG. Pass "png" for the lossless original (no re-encode at all — the upstream PNG is delivered byte-for-byte), at roughly 6x the JPEG size: a 1760x2352 render measures 6.6MB as PNG versus 1.0MB as JPEG. "webp" is JPEG-sized and is the only option that both compresses and keeps an alpha channel. Use png when your pipeline requires lossless; otherwise leave it unset.
callback_urlNostringWebhook URL called when task completes. Server will POST the same JSON as the poll response to this URL.

Output sizes: 2K and 4K

The 2K and 4K tiers follow OpenAI's own size labels for gpt-image-2. These are the 2K and 4K sizes listed in OpenAI's image generation guide:

TierSizeOpenAI label
2K2048x20482K square
2K2048x11522K landscape
4K3840x21604K landscape
4K2160x38404K portrait
  • OpenAI's 2K sizes have a 2048-pixel long edge. A 16:9 request can return 2048x1152, which is OpenAI's 2K landscape size, or a larger 2736x1536 at the same ratio; 9:16 likewise returns 1152x2048 or 1536x2736. Both are 2K renders, billed at the 2K price of $0.03.
  • The same guide notes that resolutions above 2560x1440 are experimental, so a larger size such as 2736x1536 isn't guaranteed on every request.
  • 4K is capped by OpenAI's limit of 8,294,400 total pixels (3840x2160). 16:9 and 9:16 reach 3840 on the long edge; other ratios have a shorter long edge, for example 2880x2880 at 1:1.
  • OpenAI's full size rules for gpt-image-2: both edges multiples of 16, long edge ≤ 3840, long-to-short ratio ≤ 3:1, total pixels between 655,360 and 8,294,400.
  • Every completed task returns the delivered width and height in data.images, so you can check the size in code.

Source: OpenAI image generation guide · GPT Image 2 settings

Response fields

FieldRequiredTypeDescription
code—integer200 on success; otherwise see the error-code table.
msg—string"success" or an error message.
data.taskId—stringTask ID used for status queries.
data.state—stringpending / processing / completed / failed.
data.resultUrls—string[]Present only when state=completed; R2-hosted image URLs. Auto-deleted after 30 days — download or re-host to your own storage promptly.
data.images—object[]Present only when state=completed (tasks since 2026-10-25): actual pixel size of each image, in the same order as resultUrls — [{ url, width, height }]. An entry that could not be measured carries only url.
data.failMsg—stringPresent only when state=failed; upstream failure reason.
data.costTime—integerTask duration in milliseconds.
data.completeTime—integerCompletion timestamp in ms.

Notes

  • Async flow: POST returns taskId immediately with state=pending; poll GET ?task_id= until state=completed. Typical latency 10–30s, capped at ~3min.
  • Endpoint auto-routes: prompt only → text-to-image; with image_url / image_urls / image_base64 → image-to-image.
  • Image inputs can be public URLs, data:<mime>;base64,... URIs, or bare base64 strings (auto-wrapped). Up to 16 per request, 10MB each; beyond 16, only the first 16 are used.
  • callback_url is preferred in production — the backend POSTs the same data payload to your endpoint when the task finishes, avoiding your own polling loop.
  • resultUrls are R2 links auto-deleted after 30 days — download or re-host them to your own storage within that window.
  • Failed tasks are free: state=failed requests are not billed, retry is safe.
  • Tiered pricing by resolution: 1K $0.025, 2K $0.03, 4K $0.05 — independent of aspect ratio or prompt length. 5:4 / 4:5 are 1K-only (unsupported at 2K/4K).

Related: for the OpenAI-SDK-compatible sync channel see GPT Image 2 All; try it in the Playground

FAQ

How much does the GPT Image 2 API cost?

Tiered by resolution: 1K $0.025, 2K $0.03, 4K $0.05 per image — independent of aspect ratio or prompt length. Charged only on success.

How do I edit an image with GPT Image 2?

POST /api/v1/images/generations with model gpt-image-2, a prompt, and image_url (single) or image_urls[] (up to 16). Poll GET ?task_id= until completed, or pass callback_url.

What is the difference between gpt-image-2, gpt-image-2-all and gpt-image-2-lite?

gpt-image-2 is the async task channel (1K/2K/4K tiers). gpt-image-2-all is the OpenAI-SDK-compatible sync channel with the full quality matrix and multi-image editing. gpt-image-2-lite is the most affordable channel: a flat $0.01 per image, single tier (~1.5MP at your aspect ratio), sync.