Skip to main content
POST
/
v1
/
images
/
generations
curl --request POST \
  --url https://api.apimart.ai/v1/images/generations \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
    "model": "gpt-image-2-official",
    "prompt": "An ancient castle beneath a starry sky",
    "size": "16:9",
    "resolution": "2k",
    "quality": "high",
    "n": 1
  }'
{
  "code": 200,
  "data": [
    {
      "status": "submitted",
      "task_id": "task_01KPTXXXXXXXXXXXXXXX"
    }
  ]
}
curl --request POST \
  --url https://api.apimart.ai/v1/images/generations \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
    "model": "gpt-image-2-official",
    "prompt": "An ancient castle beneath a starry sky",
    "size": "16:9",
    "resolution": "2k",
    "quality": "high",
    "n": 1
  }'
{
  "code": 200,
  "data": [
    {
      "status": "submitted",
      "task_id": "task_01KPTXXXXXXXXXXXXXXX"
    }
  ]
}

Authorizations

Authorization
string
required
All endpoints require Bearer Token authenticationGet your API Key:Visit the API Key management page to get your API KeyInclude it in the request header:
Authorization: Bearer YOUR_API_KEY

Body

model
string
default:"gpt-image-2-official"
required
Image generation model nameFixed to gpt-image-2-official (OpenAI official gpt-image-2 model)
prompt
string
required
Text description for image generation
  • Supports English and Chinese, detailed descriptions recommended
  • Pre-submission content moderation / safety review — violations are rejected immediately
size
string
default:"1:1"
Image aspect ratioExternally uses ratio values; internally mapped to actual pixels according to resolution.13 supported ratios:
  • 1:1 - Square (default, social avatars / logos)
  • 3:2 - Landscape (common DSLR ratio)
  • 2:3 - Portrait (vertical posters)
  • 4:3 - Landscape (classic monitor / slideshow)
  • 3:4 - Portrait
  • 5:4 - Landscape
  • 4:5 - Portrait (Instagram vertical post)
  • 16:9 - Landscape (widescreen video thumbnail)
  • 9:16 - Portrait (phone full-screen / short video cover)
  • 2:1 - Landscape (web banner)
  • 1:2 - Portrait
  • 21:9 - Landscape (cinematic ultra-wide)
  • 9:21 - Portrait
resolution
string
default:"1k"
Resolution tier (new field)Controls the actual output clarity.
  • 1k - 1024 baseline, cost-efficient for daily use (default)
  • 2k - 2048 baseline, suitable for posters / high-definition needs
  • 4k - 3840 baseline, only 6 ratios supported (16:9 / 9:16 / 2:1 / 1:2 / 21:9 / 9:21)
Unsupported 4K combinations return 400 (limited by OpenAI’s per-image total-pixel cap of 8,294,400):
  • 1:1 × 4k ❌ (3840² = 14.7M exceeds cap)
  • 3:2 / 2:3 × 4k ❌ (3840×2560 = 9.83M exceeds cap)
  • 4:3 / 3:4 × 4k ❌ (3840×2880 = 11.06M exceeds cap)
  • 5:4 / 4:5 × 4k ❌ (3840×3072 = 11.80M exceeds cap)
For high-definition output of these ratios, use resolution=2k (max 2048 side, within pixel budget).
quality
string
default:"auto"
Image quality
  • auto - Automatic (default, typically equivalent to low)
  • low - Fast and economical, sufficient for rough outlines
  • medium - Balanced
  • high - Maximum precision (4K + high can take >120s)
background
string
default:"auto"
Background mode
  • auto - Automatic (default)
  • opaque - Opaque
  • transparent - ⚠️ gpt-image-2-official does not support transparent backgrounds; the system silently downgrades to auto
moderation
string
default:"auto"
Moderation strength
  • auto - Default moderation strength
  • low - More lenient moderation
output_format
string
default:"png"
Output format
  • png - Default
  • jpeg - Smaller files
  • webp - Optimal for modern browsers
output_compression
integer
Output compression level, range 0-100
  • Only effective for jpeg / webp
n
integer
default:"1"
Number of images to generateRange: 1 ~ 4
Must be a pure number (e.g., 1), do not wrap in quotes
image_urls
array
Reference image URL array
mask_url
string
Mask image URL, used for inpainting
  • Must be used together with image_urls
  1. Ensure the mask image has an Alpha channel before uploading.
  2. The mask image dimensions must match the first reference image.

Size × Resolution Mapping

size × resolution → OpenAI actual pixels (13 ratios × 3 tiers):
size1k2k4k
1:11024×10242048×2048❌ exceeds pixel cap
3:21536×10242048×1360❌ exceeds pixel cap
2:31024×15361360×2048❌ exceeds pixel cap
4:31024×7682048×1536❌ exceeds pixel cap
3:4768×10241536×2048❌ exceeds pixel cap
5:41280×10242560×2048❌ exceeds pixel cap
4:51024×12802048×2560❌ exceeds pixel cap
16:91536×8642048×11523840×2160
9:16864×15361152×20482160×3840
2:12048×10242688×13443840×1920
1:21024×20481344×26881920×3840
21:92016×8642688×11523840×1648
9:21864×20161152×26881648×3840
Note: 3:2 / 2:3 @ 2K is actually 2048×1360 (1360 must be a multiple of 16, approximate 3:2 with <0.5% error); 21:9 @ 4K is 3840×1648 (exact 2.33:1). All others are exact ratios.

Usage Examples

Text-to-image (minimal request)
{
  "model": "gpt-image-2-official",
  "prompt": "An ancient castle beneath a starry sky"
}
2K high-definition poster
{
  "model": "gpt-image-2-official",
  "prompt": "Cyberpunk night scene",
  "size": "16:9",
  "resolution": "2k",
  "quality": "high",
  "output_format": "jpeg",
  "output_compression": 90
}
4K wallpaper
{
  "model": "gpt-image-2-official",
  "prompt": "Snow mountain sunrise panorama",
  "size": "16:9",
  "resolution": "4k",
  "quality": "high",
  "n": 1
}
Image-to-image (multi-reference fusion)
{
  "model": "gpt-image-2-official",
  "prompt": "Fuse the two reference images into a single illustration poster, preserving the main silhouettes",
  "size": "1:1",
  "quality": "high",
  "image_urls": [
    "https://your-cdn.com/input-a.png",
    "https://your-cdn.com/input-b.png"
  ]
}
Inpainting (mask)
{
  "model": "gpt-image-2-official",
  "prompt": "Replace the background with a desert sunset",
  "size": "1:1",
  "quality": "medium",
  "image_urls": ["https://your-cdn.com/photo.png"],
  "mask_url": "https://your-cdn.com/mask.png"
}
Multiple images (n > 1)
{
  "model": "gpt-image-2-official",
  "prompt": "Four minimalist poster variations of a red fox",
  "size": "1:1",
  "quality": "low",
  "n": 4
}
Direct pixel string (advanced)
{
  "model": "gpt-image-2-official",
  "prompt": "wide cinematic shot",
  "size": "3840x2160",
  "quality": "high"
}

Response

code
integer
Response status code
data
array
Response data array

Querying Task Results

After successful submission, a task_id is returned. Poll the task status via GET /v1/tasks/{task_id}, see Task Query API for details.

Success Response Example

{
  "code": 200,
  "data": {
    "id": "task_01KPTXXXXXXXXXXXXXXX",
    "status": "completed",
    "progress": 100,
    "actual_time": 46,
    "result": {
      "images": [
        {
          "url": [
            "https://upload.apimart.ai/f/image/xxxxxxxx-gpt_image_2_official_task_xxx_0.png"
          ],
          "expires_at": 1776928569
        }
      ]
    }
  }
}
Task status flow: submittedin_progresscompleted / failed. Image access: data.result.images[0].url[0].

Polling Recommendations

  • Initial query delay: Wait 10~20 seconds after submission before first query
  • Query interval: 3~5 seconds recommended
  • Timeout reference: high + 2k/4k combinations can take up to 130 seconds; client timeout ≥ 180 seconds recommended
  • Batch query: To query multiple tasks at once, use POST /v1/tasks/batch