OpenAI Tasks API Integration and Usage

The OpenAI Tasks API is used to retrieve the results of tasks previously submitted to the OpenAI Images API in callback mode. Use this API when you cannot wait for a synchronous HTTP response or want to retrieve a task again later.

In callback mode, the original Images API immediately returns a task_id after accepting the request. You can retain this task_id and use it to query this API when needed, without passing a custom trace_id separately (which is only needed if you want to correlate tasks using your own business identifier).

Tasks are persisted only when the original image request includes a callback_url. Requests made synchronously (without a callback) are not stored.

Application Process

Log in to the Applications List, open the General Application, and click the copy button to the right of the API KEY field. Save the Key on the server for use as {token} in the examples below.

Obtain an Ace Data Cloud API Key

You can use the Key used to create the image task; please confirm that it also permits task retrieval.

API Endpoint

POST https://api.acedata.cloud/openai/tasks

Supported action values:

Action Description
retrieve Retrieve a single task by id or trace_id
retrieve_batch Retrieve tasks in batches by ids / trace_ids / application_id / user_id

Request Headers

  • accept: application/json
  • authorization: Bearer {token}
  • content-type: application/json

Single Task Retrieval (retrieve)

Request Body

Field Type Required Description
action string Yes Fixed as retrieve
id string One of the two Task ID returned in the synchronous response when the image request was submitted (recommended)
trace_id string One of the two Needed only if you explicitly passed a custom trace_id in the original request

Pass at least one of id and trace_id. In general, you can use the id from the submission response directly; pass trace_id only when you want to correlate tasks using a custom business identifier.

Code Examples

CURL

curl -X POST 'https://api.acedata.cloud/openai/tasks' \
  -H 'accept: application/json' \
  -H 'authorization: Bearer {token}' \
  -H 'content-type: application/json' \
  -d '{
    "action": "retrieve",
    "id": "7489df4c-ef03-4de0-b598-e9a590793434"
  }'

Python

import requests

url = "https://api.acedata.cloud/openai/tasks"
headers = {
    "accept": "application/json",
    "authorization": "Bearer {token}",
    "content-type": "application/json",
}
payload = {
    "action": "retrieve",
    "id": "7489df4c-ef03-4de0-b598-e9a590793434",
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())

Response Example

When the task exists:

{
  "_id": "67a1b2c3d4e5f6a7b8c9d0e1",
  "id": "7489df4c-ef03-4de0-b598-e9a590793434",
  "trace_id": "my-custom-trace-001",
  "type": "images",
  "application_id": "9dec7b2a-1cad-41ff-8536-d4ddaf2525d4",
  "user_id": "5d8e7f6a-1234-4abc-9def-0123456789ab",
  "credential_id": "68253cc8-505d-47f4-97ad-0050a62e4975",
  "created_at": 1763142607.967,
  "started_at": 1763142607.97,
  "finished_at": 1763142637.404,
  "elapsed": 29.437,
  "request": {
    "model": "gpt-image-1",
    "prompt": "A cat sitting on a table",
    "size": "1024x1024",
    "callback_url": "https://your.server/callback"
  },
  "response": {
    "created": 1763142637,
    "data": [
      { "url": "https://platform.cdn.acedata.cloud/openai/...png" }
    ],
    "success": true
  }
}

When no task matches, an empty object is returned:

{}

Field Descriptions

  • id: The task ID generated when the original image request was accepted.
  • trace_id: The custom tracking identifier passed in the original request, used for correlation in client-side business processes.
  • type: The task type. Tasks created by the gpt-image series (such as gpt-image-2) use images; gpt-image-1, nano-banana, and others use images_generations / images_edits, and some chat APIs use chat_completions_image.
  • request: The complete request body of the original request.
  • response: The final response body returned when the callback completes.
  • created_at / started_at / finished_at: Unix timestamps (seconds, floating-point).
  • elapsed: Execution time (seconds, floating-point).
  • application_id / user_id / credential_id: The IDs of the associated application, end user, and credential.

Batch Retrieval (retrieve_batch)

Request Body

Field Type Description
action string Fixed as retrieve_batch
ids string[] Retrieve by a list of task IDs
trace_ids string[] Retrieve by a list of trace_id values
application_id string Retrieve all tasks by application
user_id string Retrieve all tasks by end user
type string Filter by task type (values: images, images_generations, images_edits)
offset int Pagination starting point, defaults to 0
limit int Number of items per page, defaults to 12
created_at_min float Starting timestamp (Unix seconds)
created_at_max float Ending timestamp (Unix seconds)

Pass one of ids / trace_ids / application_id / user_id or a created_at_* time window.

CURL Example

curl -X POST 'https://api.acedata.cloud/openai/tasks' \
  -H 'authorization: Bearer {token}' \
  -H 'content-type: application/json' \
  -d '{
    "action": "retrieve_batch",
    "trace_ids": ["my-trace-001", "my-trace-002"]
  }'

Response Example

{
  "items": [
    {
      "_id": "67a1b2c3d4e5f6a7b8c9d0e1",
      "id": "7489df4c-ef03-4de0-b598-e9a590793434",
      "trace_id": "my-trace-001",
      "type": "images",
      "request": {
        "model": "gpt-image-2",
        "prompt": "A cat"
      },
      "response": {
        "data": [
          {
            "url": "https://...png"
          }
        ]
      },
      "created_at": 1763142607.967,
      "started_at": 1763142608.027,
      "finished_at": 1763142637.404,
      "elapsed": 29.377
    }
  ],
  "count": 1
}

End-to-End Example: Submit and Poll

The Tasks API primarily supports asynchronous workflows in callback mode. In callback mode, the submission endpoint immediately returns a task_id synchronously (i.e., the task ID), after which you can simply use this task_id to poll the Tasks API directly, without generating a trace_id yourself.

import os, time, requests

API = "https://api.acedata.cloud"
HEADERS = {
    "authorization": f"Bearer {os.environ['ACEDATA_API_KEY']}",
    "content-type": "application/json",
}

# 1. 提交图片生成任务(callback 模式:带上 callback_url 即可立即返回 task_id)
submit = requests.post(
    f"{API}/openai/images/generations",
    headers=HEADERS,
    json={
        "model": "gpt-image-1",
        "prompt": "一只水彩风格的猫坐在桌子上",
        "callback_url": "https://webhook.site/your-uuid",
    },
).json()
print("submitted:", submit)

task_id = submit["task_id"]

# 2. 直接用提交响应中的 task_id 轮询 Tasks 接口,直到任务完成
while True:
    task = requests.post(
        f"{API}/openai/tasks",
        headers=HEADERS,
        json={"action": "retrieve", "id": task_id},
    ).json()
    if task and task.get("response"):
        print("finished:", task["response"])
        break
    time.sleep(3)

Notes

  • The Tasks API itself is free of charge, so you can poll it without concern. Only the original image generation/editing request incurs a charge.
  • A task record is written only when the original request includes callback_url; synchronous calls do not produce queryable tasks.
  • Task records beyond the platform's retention period may be deleted.