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",
    "prompt": "A ginger cat sitting on a windowsill watching the sunset, watercolor style",
    "n": 1,
    "size": "16:9",
    "resolution": "2k"
  }'
{
  "code": 200,
  "data": [
    {
      "status": "submitted",
      "task_id": "task_01KPQ7J7DWB7QZ3WCEK3YVPBRA"
    }
  ]
}

Documentation Index

Fetch the complete documentation index at: https://docs.apimart.ai/llms.txt

Use this file to discover all available pages before exploring further.

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",
    "prompt": "A ginger cat sitting on a windowsill watching the sunset, watercolor style",
    "n": 1,
    "size": "16:9",
    "resolution": "2k"
  }'
{
  "code": 200,
  "data": [
    {
      "status": "submitted",
      "task_id": "task_01KPQ7J7DWB7QZ3WCEK3YVPBRA"
    }
  ]
}

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"
required
Image generation model nameFixed to gpt-image-2
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
n
integer
default:"1"
Number of images to generateRange: 1
Must be a pure number (e.g., 1), do not wrap in quotes
size
string
default:"1:1"
Image aspect ratioSupported ratios, plus auto to let the server pick a suitable ratio automatically:
sizeType
autoAutomatic
1:1Square
3:2Landscape
2:3Portrait
4:3Landscape
3:4Portrait
5:4Landscape
4:5Portrait
16:9Landscape
9:16Portrait
2:1Landscape
1:2Portrait
3:1Landscape
1:3Portrait
21:9Landscape
9:21Portrait
Pixel dimensions can also be passed directly, such as 1881x836 / 887x1774.
When size is set to auto, the default ratio is 1:1.
resolution
string
default:"1k"
Output resolution tierOptions: 1k / 2k / 4ksize × resolution → actual pixel mapping:
size1k2k4k
1:11024×1024 / 1254×12542048×20482880×2880
3:21536×10242048×13603520×2336
2:31024×15361360×20482336×3520
4:31024×7682048×15363312×2480
3:4768×10241536×20482480×3312
5:41280×1024 / 1448×10862560×20483216×2576
4:51024×1280 / 1122×14022048×25602576×3216
16:91536×864 / 1672×9412048×11523840×2160
9:16864×1536 / 941×16721152×20482160×3840
2:12048×1024 / 1774×8872688×13443840×1920
1:21024×2048 / 887×17741344×26881920×3840
3:11881×836 / 1536×5123072×10243840×1280
1:3887×1774 / 512×15361024×30721280×3840
21:92016×864 / 1915×8212688×11523840×1648
9:21864×2016 / 821×19151152×26881648×3840
4K supports the 15 ratios listed above; you can also pass the pixel dimensions from the table directly via size.
image_urls
array
Reference image array (OpenAI standard field). Switches to image-to-image mode when provided.
Other OpenAI standard fields (response_format, quality, style) are not supported and will be ignored. Task results only return url — please download and convert to base64 yourself if needed.
official_fallback
boolean
default:"false"
Whether to fall back to the official channel
  • false: Do not use (default)
  • true: Use the official channel

Usage Examples

Text-to-image (minimal request)
{
  "model": "gpt-image-2",
  "prompt": "A ginger cat sitting on a windowsill watching the sunset, watercolor style"
}
Text-to-image (with ratio + 2K)
{
  "model": "gpt-image-2",
  "prompt": "a corgi astronaut on the moon, cinematic, 8k",
  "size": "16:9",
  "resolution": "2k"
}
Text-to-image (4K output)
{
  "model": "gpt-image-2",
  "prompt": "An ancient castle under a starry sky",
  "size": "16:9",
  "resolution": "4k"
}
Image-to-image (reference = URL)
{
  "model": "gpt-image-2",
  "prompt": "Turn this photo into a watercolor painting",
  "image_urls": [
    "https://example.com/photo.jpg"
  ]
}
Image-to-image (reference = base64)
{
  "model": "gpt-image-2",
  "prompt": "Turn this photo into a watercolor painting",
  "image_urls": [
    "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."
  ]
}
Image-to-image (multi-reference fusion, URL + base64 mixed)
{
  "model": "gpt-image-2",
  "prompt": "Fuse these two photos into a single poster",
  "size": "4:3",
  "resolution": "2k",
  "image_urls": [
    "https://example.com/photo-a.jpg",
    "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."
  ]
}

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_01KPQ7J7DWB7QZ3WCEK3YVPBRA",
    "status": "completed",
    "progress": 100,
    "created": 1776748674,
    "completed": 1776748726,
    "actual_time": 52,
    "cost": 0.05279,
    "estimated_time": 100,
    "result": {
      "images": [
        {
          "url": [
            "https://upload.apimart.ai/f/image/xxxxxxxx-gpt_image_2_task_xxx_0.png"
          ],
          "expires_at": 1776835126
        }
      ]
    }
  }
}
Image access: data.result.images[0].url[0]

Task Status

StatusMeaning
submittedSubmitted
processingBeing processed upstream
completedSuccess, result.images available
failedFailed, check error.message

Polling Recommendations

  • Initial query delay: Wait 10~20 seconds after submission before first query
  • Query interval: 3~5 seconds recommended, avoid millisecond-level polling
  • Timeout reference: A single image typically completes in 3060 seconds (observed actual_time 4453s)
  • Batch query: To query multiple tasks at once, use POST /v1/tasks/batch with body {"task_ids": ["task_xxx", "task_yyy"]}

Notes

  1. Asynchronous processing: Submission returns task_id, poll /v1/tasks/{task_id} to get the final image URL
  2. Content moderation: prompt is reviewed first — violations are rejected with no billing
  3. Result URL: The platform mirrors upstream temporary signed links to its own R2 object storage, returning a stable link that clients can access directly
  4. URL validity: expires_at = completed + 24h in the response is a hint field, please download or mirror to your own CDN promptly
  5. Ratio conflict: Use the size field for aspect ratio — avoid repeating it in prompt to prevent upstream ambiguity
  6. Billing: Billed by resolution tier (1K / 2K / 4K), no charge on failure or moderation rejection
  7. 4K supported ratios: All 15 ratios above support 4K; you can also pass the corresponding pixel dimensions directly via size
  8. Task retention: task_id is retained in the database for several days by default (configured by TASK_RETENTION_DAYS) — expired queries return “task does not exist or has expired”