Skip to content

Async Image Tasks

Async image tasks are designed for long-running production image generation. The client submits a task, receives a task ID, and then reads the result later through polling or SSE.

The same /v1/images/tasks endpoint dispatches by model. One task accepts one model, one prompt, and n images.

Async image tasks require an image API key. The key must be bound to an image batch group. See Create API Keys before integrating this endpoint.

Currently supported:

ModelImage batch group model platformUpstream protocol
gpt-image-*, image2OpenAIOpenAI Images API
gemini-2.5-flash-imageGeminiGemini native generateContent
gemini-3.1-flash-imageGeminiGemini native generateContent

For Gemini image generation, use the official model names. Do not use aliases such as banana or nano-banana.

Submit a Task

Interface details:

ItemValue
MethodPOST
Path/v1/images/tasks
Content-Typeapplication/json
Success status202
AuthenticationAuthorization: Bearer YOUR_API_KEY
Key requirementUse an image API key bound to an image batch group; the requested model must exist in that image batch group

Request parameters:

ParameterTypeRequiredDescription
modelstringNoImage model. Defaults to gpt-image-2. image2 is normalized to gpt-image-2; Gemini uses official model names.
promptstringYesImage prompt. Must be a non-empty string.
sizestringNoOutput size. OpenAI forwards it to the Images API; Gemini uses it to infer imageConfig.imageSize and common aspect ratios.
nintegerNoNumber of images. Defaults to 1, must be greater than 0, and is limited by server configuration.
streambooleanNoMust be false or omitted; async image tasks do not support streaming upstream responses.
response_formatstringNoOpenAI only. Defaults to b64_json when omitted.
qualitystringNoNative OpenAI image parameter, forwarded when supported upstream.
backgroundstringNoNative OpenAI image parameter, forwarded when supported upstream.
output_formatstringNoNative OpenAI image parameter, forwarded when supported upstream.
moderationstringNoNative OpenAI image parameter, forwarded when supported upstream.

Gemini optional parameters:

ParameterTypeDescription
image_size / imageSizestringImage size tier. Supports 1K, 2K, 4K; common dimension strings are normalized by the server.
aspect_ratio / aspectRatiostringSupports 1:1, 16:9, 9:16, 4:3, 3:4.
temperature, top_p / topP, top_k / topK, seed, max_output_tokens / maxOutputTokensnumberWritten into Gemini generationConfig.
generation_config / generationConfigobjectForwarded and merged into Gemini generationConfig. The server ensures image output modality is included.
image_config / imageConfigobjectForwarded and merged into generationConfig.imageConfig.
system_instruction / systemInstructionstring/objectOptional Gemini system instruction.
safety_settings / safetySettingsarrayOptional Gemini safety settings.

Unsupported request formats:

FormatNotes
multipart/form-dataAsync tasks currently support JSON generation requests only.
Image editsAsync tasks currently map to /v1/images/generations only.
Multiple promptsOne task accepts only one prompt.
General API keysGeneral-group keys cannot submit async image tasks.

OpenAI request example:

bash
curl https://llmapi.site/v1/images/tasks \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "image2",
    "prompt": "a clean studio product photo of a matte black water bottle",
    "size": "1024x1024",
    "n": 2
  }'

Response example:

json
{
  "id": "8b17fd33b0e947a08cb417e81e9ea9da",
  "task_id": "8b17fd33b0e947a08cb417e81e9ea9da",
  "object": "image.task",
  "status": "queued",
  "created_at": "2026-05-14T05:13:00Z",
  "model": "gpt-image-2",
  "n": 2,
  "size": "1024x1024",
  "estimated_cost": 0.12,
  "poll_url": "/v1/images/tasks/8b17fd33b0e947a08cb417e81e9ea9da",
  "event_url": "/v1/images/tasks/events"
}

Gemini request example:

bash
curl https://llmapi.site/v1/images/tasks \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "gemini-2.5-flash-image",
    "prompt": "a clean studio product photo of a matte black water bottle",
    "image_size": "1K",
    "aspect_ratio": "1:1",
    "n": 1
  }'

Retrieve a Task

Interface details:

ItemValue
MethodGET
Path/v1/images/tasks/{task_id}
AuthenticationAuthorization: Bearer YOUR_API_KEY
PermissionThe task must have been created by the current API key

Path parameters:

ParameterTypeRequiredDescription
task_idstringYesTask ID returned by the submit endpoint.

Request example:

bash
curl https://llmapi.site/v1/images/tasks/8b17fd33b0e947a08cb417e81e9ea9da \
  -H 'Authorization: Bearer YOUR_API_KEY'

Status values:

StatusDescription
queuedTask is queued and waiting for a worker.
runningTask is running.
succeededTask completed and result contains image data.
failedTask failed and error contains the reason; no charge is applied and the reservation is released.
timeoutTask timed out; no charge is applied, the reservation is released, and the server does not retry automatically.
canceledTask was canceled; no charge is applied and the reservation is released.

Successful task response:

json
{
  "id": "8b17fd33b0e947a08cb417e81e9ea9da",
  "task_id": "8b17fd33b0e947a08cb417e81e9ea9da",
  "object": "image.task",
  "status": "succeeded",
  "created_at": "2026-05-14T05:13:00Z",
  "started_at": "2026-05-14T05:13:02Z",
  "finished_at": "2026-05-14T05:13:42Z",
  "model": "gpt-image-2",
  "n": 2,
  "size": "1024x1024",
  "estimated_cost": 0.12,
  "actual_cost": 0.12,
  "result": {
    "data": [
      {
        "index": 0,
        "url": "https://oss.example.com/images/task-0.png?signature=...",
        "content_type": "image/png",
        "size_bytes": 1048576,
        "expires_at": "2026-05-21T05:13:42Z"
      }
    ]
  },
  "poll_url": "/v1/images/tasks/8b17fd33b0e947a08cb417e81e9ea9da",
  "event_url": "/v1/images/tasks/events"
}

Gemini tasks use the same response shape. model preserves the official Gemini model name:

json
{
  "id": "8b17fd33b0e947a08cb417e81e9ea9da",
  "task_id": "8b17fd33b0e947a08cb417e81e9ea9da",
  "object": "image.task",
  "status": "queued",
  "created_at": "2026-05-14T05:13:00Z",
  "model": "gemini-2.5-flash-image",
  "n": 1,
  "size": "1K",
  "poll_url": "/v1/images/tasks/8b17fd33b0e947a08cb417e81e9ea9da",
  "event_url": "/v1/images/tasks/events"
}

Failed task response:

json
{
  "id": "8b17fd33b0e947a08cb417e81e9ea9da",
  "task_id": "8b17fd33b0e947a08cb417e81e9ea9da",
  "object": "image.task",
  "status": "failed",
  "model": "gpt-image-2",
  "n": 1,
  "error": {
    "code": "upstream_error",
    "message": "image generation failed"
  }
}

Cancel a Task

Interface details:

ItemValue
MethodPOST
Path/v1/images/tasks/{task_id}/cancel
AuthenticationAuthorization: Bearer YOUR_API_KEY
PermissionThe task must have been created by the current API key
Cancellable statusqueued

Request example:

bash
curl -X POST https://llmapi.site/v1/images/tasks/8b17fd33b0e947a08cb417e81e9ea9da/cancel \
  -H 'Authorization: Bearer YOUR_API_KEY'

Notes:

  • Only queued tasks can be canceled.
  • A running task may already be executing upstream and is not interrupted by this endpoint.
  • Canceling a terminal task returns a conflict error.

Billing Behavior

StageBehavior
Before submissionValidates balance, API key status, group permission, and content moderation.
EnqueueReserves estimated balance from model, size, and image count.
SuccessSettles actual cost from the generated result. If actual cost is lower than the reservation, the difference is returned; if it is higher, the difference is deducted and the user balance may become negative.
Usage recordWritten after a task is successfully settled. A usage-record write failure does not change the task's successful status.
Failure, timeout, or cancelNo charge is applied and the full reserved balance is released.

Failed and timed-out tasks are not retried automatically. Submit a new task if the caller wants to retry.

Async image tasks currently do not support regular subscription-billing groups. Use an image API key bound to an image batch group. Regular subscription groups receive IMAGE_TASK_SUBSCRIPTION_UNSUPPORTED.