apimaxDocs
DocsPricingConsole
API ReferenceIntegration GuideUser GuideChangelog

Music Series

Image Series

POSTGPT Image 2.5 Image GenerationPOSTGPT Image 2 Image GenerationPOSTGPT Image Web Image GenerationPOSTGPT Image 2.6 Image Generation

Video series

Task Management

Error Code ReferenceQuery Task StatusGET

Account Management

Query Quota UsageGET

Docs / Image Series / GPT Image / Async

AsyncPOSTImage GenerationGPT-ImageOpenAIAsync

GPT Image 2 Image Generation

POSThttps://api.apimax.ai/v1/images/async-generations
Try it
Bearer API KeyJSONServer-side call

GPT Image 2 (gpt-image-2) is OpenAI's next-generation image generation model, supporting text-to-image, image-to-image, and image editing (inpainting). This API is fully compatible with the OpenAI Images API format and uses an async task mode: it returns a task ID immediately after submission, and you then poll the query endpoint for the result.

- The async mode uses a dedicated endpoint, POST /v1/images/async-generations: it returns a task_id after submission, and you retrieve the result with the task query API. - Generated image links are pre-signed URLs valid for about 24 hours; save them promptly.

Authentication#

All endpoints require Bearer token authentication. Create your key on the API Key management page and add it to the request header:

text
Authorization: Bearer YOUR_API_KEY

Create a task#

POST /v1/images/async-generations

Request parameters#

ParameterTypeRequiredDefaultDescription
modelstringYesgpt-image-2Model name; must be gpt-image-2
promptstringYes—Prompt describing the image to generate or edit. Up to 32000 characters
image_urlsarrayNo—List of reference image URLs for image-to-image / image editing. 1–16 images, each < 20MB
sizestringNoautoImage size; supports ratio format (e.g. 16:9) or pixel format (e.g. 1024x1024)
resolutionstringNo1KResolution tier 1K/2K/4K; only takes effect when `size` uses the ratio format
qualitystringNoautoImage quality: low, medium, high; medium is the balanced quality-and-speed option
backgroundstringNoautoBackground mode: auto, opaque, transparent
callback_urlstringNo—HTTPS callback URL invoked when the task finishes

quality#

Supported values are low, medium, high, and auto. medium is the officially supported medium quality tier, striking a balance between quality, speed, and cost.

json
{
  "model": "gpt-image-2",
  "prompt": "A cute cat",
  "quality": "medium"
}

size#

Two notations are supported; the default is auto (the model decides automatically, and resolution has no effect in that case).

① Ratio format (recommended, 15 options):

1:1, 1:2, 2:1, 1:3, 3:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 9:21, 21:9

② Explicit pixel format: WxH (or W×H), e.g. 1024x1024, 1536x1024, 3840×2160

  • Width and height must each be a multiple of 16, with each side in the range [16, 3840]
  • Pixel budget: 655,360 ≤ width × height ≤ 8,294,400 (about 0.65MP ~ 8.29MP)
  • Aspect ratio ≤ 3:1
If a ratio + resolution combination exceeds the pixel budget, it is automatically scaled proportionally to the maximum size (for example, 4K + 2:1 → 3840×1920).

resolution#

Only takes effect when size uses the ratio format; it is ignored with the explicit pixel format.

TierTarget pixels1:116:92:1
1K~1MP1024×10241360×7681456×720
2K~4MP2048×20482736×15362896×1456
4K~8.29MP2880×28803840×21603840×1920

Values are case-insensitive.

background (transparent background)#

GPT Image 2 now supports generating images with transparent backgrounds. Set background to transparent to enable a transparent background; the output is png or webp. The default value of background is auto; you can also explicitly set it to opaque to generate an opaque background.

json
{
  "model": "gpt-image-2",
  "prompt": "A minimalist white cat icon with a transparent background",
  "background": "transparent"
}

Request examples#

The request body is structurally identical to the synchronous OpenAI Images API. The simplest text-to-image request needs only model and prompt:

json
{
  "model": "gpt-image-2",
  "prompt": "A beautiful, colorful sunset over the sea"
}

HD landscape (ratio + resolution tier + quality):

json
{
  "model": "gpt-image-2",
  "prompt": "A cinematic wide-angle shot of a futuristic city skyline at dusk",
  "size": "16:9",
  "resolution": "4K",
  "quality": "high"
}

Image-to-image / image editing (with reference images):

json
{
  "model": "gpt-image-2",
  "prompt": "Add a cute kitten next to her",
  "size": "1:1",
  "resolution": "1K",
  "image_urls": ["https://example.com/input.png"],
  "callback_url": "https://your-domain.com/webhook/image-done"
}

Create task response#

Task information is returned immediately after a successful submission (HTTP 200):

json
{
  "id": "task_V1StGXR8_Z5jdHi6B",
  "object": "image.generation.task",
  "type": "image",
  "status": "queued",
  "progress": 0,
  "created": 1757156493,
  "model": "gpt-image-2",
  "task_info": {
    "can_cancel": true,
    "estimated_time": 100
  }
}

id is the task identifier (task_ prefix), used for subsequent queries.

Query a task#

GET /v1/tasks/{id}

bash
curl 'https://api.apimax.ai/v1/tasks/task_V1StGXR8_Z5jdHi6B' \
  --header 'Authorization: Bearer <token>'

We recommend polling every 2–5 seconds until status becomes completed or failed.

The generated result is determined by what data actually returns: individual images may fail to generate, in which case the task still ends as completed, returning only the successful images, billed by the number of successfully generated images.

Completed (`completed`):

json
{
  "id": "task_V1StGXR8_Z5jdHi6B",
  "object": "image.generation.task",
  "type": "image",
  "status": "completed",
  "progress": 100,
  "created": 1757156493,
  "completed_at": 1757156593,
  "model": "gpt-image-2",
  "data": [
    {
      "url": "https://cdn.example.com/img/.../0.png?X-Amz-Signature=...",
      "url_expires_at": 1757160193
    }
  ],
  "usage": {
    "input_tokens": 12,
    "output_tokens": 4160,
    "total_tokens": 4172
  }
}

The pre-signed URL is re-signed on every query, so polling also "refreshes" expired links.

Failed (`failed`):

json
{
  "id": "task_V1StGXR8_Z5jdHi6B",
  "object": "image.generation.task",
  "type": "image",
  "status": "failed",
  "failed_at": 1757156593,
  "model": "gpt-image-2",
  "error": {
    "code": "upstream_error",
    "message": "openai returned 400: content_policy_violation"
  }
}

status#

StatusMeaning
queuedQueued, waiting to execute
in_progressGenerating
completedGeneration completed; data contains the image links
failedGeneration failed; see error

error.code#

CodeMeaning
upstream_errorUpstream returned 4xx (content policy / invalid prompt)
upstream_unavailableUpstream still returned 5xx after multiple retries
storage_errorFailed to upload the result to cloud storage
internal_errorInternal gateway error

When a task fails, the pre-deducted quota is automatically refunded.

Error codes (HTTP)#

Status codecodeMeaning
400invalid_requestMissing prompt/model, or a parameter has an invalid format
400model_not_supportedThe model is not in the gpt-image-* family
401unauthorizedInvalid or expired token
403insufficient_user_quotaInsufficient quota; please top up
403(empty string)The token does not have access to this model
429rate_limit_exceededToo many requests
500internal_errorInternal server error

Callback (callback_url)#

After callback_url is set, the gateway POSTs a callback whenever the task completes / fails / is canceled. The callback body uses the same format as the task query API.

  • HTTPS only; callbacks to internal IP addresses are not allowed; URL ≤ 2048 characters
  • 10-second timeout; failed deliveries are retried up to 3 times (after 1s / 2s / 4s respectively)
  • A 2xx response is treated as success; any other status code triggers a retry

Next steps

All docs
Midjourney API OverviewMidjourney MJ Proxy-compatible API: endpoints, actions, per-call pricing, task states and error codes.Nano Banana 2.1 Image GenerationGoogle Nano Banana 2.1 (Gemini) async image generation. Excels at multi-image blending, real-person references, and text rendering, with a thinking level option.Nano Banana 2 Lite Image GenerationAsynchronous image generation with Google Nano Banana 2 (Gemini), excelling at multi-image fusion, real-person references, and text rendering, with support for reasoning levels.Nano Banana Pro Image GenerationAsynchronous image generation with Google Nano Banana 2 (Gemini), excelling at multi-image fusion, real-person references, and text rendering, with support for reasoning levels.Nano Banana 2 Image GenerationGoogle Nano Banana 2 (Gemini) async image generation. Excels at multi-image blending, real-person references, and text rendering, with support for thinking levels.Nano Banana Synchronous Image GenerationGemini image models (the nano-banana series) support OpenAI-compatible synchronous image generation and multipart image editing, return base64 by default, and work with the OpenAI SDK.
On this page
OverviewAuthenticationCreate a taskRequest parametersqualitysizeresolutionbackground (transparent background)Request examplesCreate task responseQuery a taskstatuserror.codeError codes (HTTP)Callback (callbackurl)Next steps
API

POST /v1/images/async-generations