Qwen Image Task Query API Integration Guide

The Qwen Image Task Query API is used to retrieve the execution results of image generation or editing tasks and supports single-task and batch queries. With it, you can obtain the final image after submitting a generation request asynchronously, or retrieve the results of a completed task again.

The endpoint is POST https://api.acedata.cloud/qwen-image/tasks. Task queries do not incur additional API charges; generation fees are still charged to the original generation task.

Application and Usage

  1. Open the Ace Data Cloud Console, log in, open Universal Application, and click the copy button to the right of the API KEY field.
  2. Users who have already called the Qwen Image Generation and Editing API can continue using the same Token and do not need to apply separately for task query credentials; please confirm that the credentials have permission to call the corresponding endpoint.
  3. If you have not yet created a generation task, first submit a request according to the Qwen Image Generation and Editing API Integration Guide, and save the task_id in the response.

Get an API Token in the Ace Data Cloud Console

Replace YOUR_API_TOKEN below with the Token obtained from the console, and replace YOUR_TASK_ID with the task ID returned by your own generation request. The Token should be stored on the server and must not be placed in public code. Generation requires available credits; if your balance is insufficient, click the “Recharge” button.

Full parameters and online debugging: Qwen Image Task Query API.

Obtain a Task ID

Set async: true in the image generation request, and the API will first return a task_id without requiring you to keep the connection open while waiting for image generation to complete. For example:

curl -X POST 'https://api.acedata.cloud/qwen-image/images' \
  -H 'Authorization: Bearer YOUR_API_TOKEN' \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -d '{
    "model": "qwen-image-3.0",
    "prompt": "A simple red circle centered on a clean white background.",
    "size": "1024*1024",
    "n": 1,
    "async": true
  }'

The parameter name in the task query request is id, and its value is the task_id returned by the generation API. Do not use the image URL or trace_id in place of the task ID, and do not directly copy the historical task ID from the response example in this article.

Request Headers and Parameters

Request Header Value Description
Authorization Bearer YOUR_API_TOKEN API Token; retain the space after Bearer
Content-Type application/json The request body uses JSON format
Accept application/json Accept responses in JSON format
Parameter Type Usage
action string retrieve queries a single task, retrieve_batch queries tasks in batches; defaults to retrieve
id string For a single-task query, enter the task_id returned by the generation API
ids string[] For a batch query, enter an array of task IDs

Query a Single Task

cURL

curl -X POST 'https://api.acedata.cloud/qwen-image/tasks' \
  -H 'Authorization: Bearer YOUR_API_TOKEN' \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -d '{
    "action": "retrieve",
    "id": "YOUR_TASK_ID"
  }'

Python

First run pip install requests to install the dependency, and set ACEDATACLOUD_API_TOKEN and QWEN_IMAGE_TASK_ID in the runtime environment to your Token and task ID, respectively.

import os

import requests

response = requests.post(
    "https://api.acedata.cloud/qwen-image/tasks",
    headers={
        "Authorization": f"Bearer {os.environ['ACEDATACLOUD_API_TOKEN']}",
        "Content-Type": "application/json",
        "Accept": "application/json",
    },
    json={"action": "retrieve", "id": os.environ["QWEN_IMAGE_TASK_ID"]},
    timeout=60,
)
response.raise_for_status()
task = response.json()
print(task)

Response Example and Field Descriptions

The following is an excerpt of the main fields from a real completed task. The image uses a public example URL for the same image, and the cost is provided only to illustrate the response format:

{
  "id": "565a7f55-72c6-43ed-b274-268ff046e5b4",
  "created_at": 1787658940.912,
  "started_at": 1787658940.911,
  "finished_at": 1787658951.254,
  "elapsed": 10.343,
  "response": {
    "success": true,
    "task_id": "565a7f55-72c6-43ed-b274-268ff046e5b4",
    "trace_id": "bb923cec-1550-43b4-8df2-288ac0977b4b",
    "data": [
      {
        "image_url": "https://cdn.acedata.cloud/assets/examples/qwen-image/40d5c76b-2f84-4b04-9ea0-b706417ae622-bac6a9e9de22.png"
      }
    ],
    "usage": {
      "input_image_count": 0,
      "output_image_count": 1,
      "output_width": 1024,
      "output_height": 1024
    },
    "cost": {
      "amount": 0.322,
      "currency": "credit",
      "list_amount": 0.35
    }
  }
}
Field Description
id Task ID, corresponding to the task_id returned by the generation API
request Parameters recorded in the original generation request; not shown in the excerpt above
created_at Task creation time, Unix timestamp in seconds
started_at Processing start time, Unix timestamp in seconds
finished_at Processing completion time in seconds; may be absent or empty when incomplete
elapsed Processing duration in seconds, may include decimals; may be absent or empty when incomplete
response Final response of the original generation task; this field may not yet be present while processing
response.success Whether the original generation task succeeded
response.data List of successfully generated images; get the image from each item's image_url
response.usage Usage such as the actual number of input reference images, number of output images, and dimensions
response.cost Cost information for the original generation task; currency: "credit" means Credits
response.error Error code and message when the original generation task fails
response.trace_id Trace ID of the original generation request; retain it for troubleshooting

The query returns a task record, so the image URL is at response.data[].image_url, which differs from the data[].image_url path returned directly by the generation API. A successful query HTTP request does not mean that generation has succeeded; you still need to check whether the task has completed and inspect response.success.

Poll Until the Task Is Complete

A task may still be processing immediately after submission, with no final response yet. If no matching record is found, a single-task query returns an empty object {}. First check the task ID and credentials; if the task was just submitted, you can retry later and set a total waiting time limit. The following Python example uses the same environment variables, polls every 5 seconds, and waits for up to 10 minutes. It handles processing, successful generation, failed generation, and timeout separately:

import os
import time

import requests

task_id = os.environ["QWEN_IMAGE_TASK_ID"]
headers = {
    "Authorization": f"Bearer {os.environ['ACEDATACLOUD_API_TOKEN']}",
    "Content-Type": "application/json",
    "Accept": "application/json",
}
deadline = time.monotonic() + 600

while time.monotonic() < deadline:
    response = requests.post(
        "https://api.acedata.cloud/qwen-image/tasks",
        headers=headers,
        json={"action": "retrieve", "id": task_id},
        timeout=60,
    )
    response.raise_for_status()
    task = response.json()
    if task.get("error"):
        raise RuntimeError(task)

    result = task.get("response") or {}
    if task.get("finished_at") is not None or "success" in result:
        if not result.get("success"):
            raise RuntimeError(result.get("error") or result)
        for image in result.get("data", []):
            print(image["image_url"])
        break

    time.sleep(5)
else:
    raise TimeoutError(f"任务尚未完成,请保留任务 ID 后续查询:{task_id}")

Polling beyond the waiting limit does not mean the task has failed. You can continue querying after retaining the task ID, avoiding new generation charges from resubmitting the generation request. Production environments should also handle rate limiting and temporary network errors according to HTTP status codes, using delayed retries.

Batch Query Tasks

When you need to retrieve the results of multiple tasks at the same time, set action to retrieve_batch and pass an array of task IDs using ids. Replace the two placeholder values with actual task IDs:

curl -X POST 'https://api.acedata.cloud/qwen-image/tasks' \
  -H 'Authorization: Bearer YOUR_API_TOKEN' \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -d '{
    "action": "retrieve_batch",
    "ids": ["YOUR_TASK_ID_1", "YOUR_TASK_ID_2"]
  }'

Python

import os

import requests

response = requests.post(
    "https://api.acedata.cloud/qwen-image/tasks",
    headers={
        "Authorization": f"Bearer {os.environ['ACEDATACLOUD_API_TOKEN']}",
        "Content-Type": "application/json",
        "Accept": "application/json",
    },
    json={
        "action": "retrieve_batch",
        "ids": ["YOUR_TASK_ID_1", "YOUR_TASK_ID_2"],
    },
    timeout=60,
)
response.raise_for_status()
batch = response.json()
for task in batch.get("items", []):
    if task:
        print(task["id"], task.get("response"))

The batch response contains items and count: the task records in items have the same structure as those from a single-task query, and count is the number returned by that query. Match each record to the original task by its id, do not rely on the order of the list, and do not use count to determine whether all tasks have completed; instead, check the final response of each record separately.

How Task Queries and Callbacks Work Together

After you pass callback_url in the generation request, the platform sends the final result to that address when the task completes. The callback request body directly contains success, task_id, and image or error information, while a task query places this final result in the response field.

It is recommended to use callbacks as proactive notifications and retain task queries as a fallback when a notification is not received. Save processing results by task_id and ensure idempotency; repeated queries do not incur repeated generation charges. For a callback configuration example, see the Generation and Editing API Integration Guide.

Error Handling and FAQs

Situation Description and handling
Returns {} The current query did not match a task; check whether you used the task_id from the generation response and whether you used credentials with permission; if just submitted, wait briefly and retry
No final response yet The task may still be processing; continue querying at intervals
response.success: false The generation task has failed; read response.error and save response.trace_id for troubleshooting
400 Check the names and types of action, id, and ids
401 invalid_token / token_expired The token is invalid or expired; check the credentials and the Bearer prefix
429 too_many_requests Queries are too frequent; reduce concurrency and retry after a delay
500 api_error Save the error information and trace_id, then retry the query later

To view current generation prices, visit the Qwen Image pricing page. The cost in the task response is the original generation charge record; querying itself does not incur additional API usage charges.