Skip to main content
GET
/
v1
/
images
/
generations
/
{task_id}
cURL
TASK_ID="<task_id>"

while true; do
  RESPONSE=$(curl -s "https://api.cometapi.com/v1/images/generations/$TASK_ID" \
    -H "Authorization: Bearer $COMETAPI_KEY")
  STATUS=$(printf "%s" "$RESPONSE" | python3 -c "import json,sys; print(json.load(sys.stdin)['data']['status'])")
  echo "status: $STATUS"
  case "$STATUS" in success | failure) break;; esac
  sleep 3
done

printf "%s\n" "$RESPONSE"
import os
import time
import requests

task_id = "<task_id>"
headers = {"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]}

while True:
task = requests.get(
f"https://api.cometapi.com/v1/images/generations/{task_id}",
headers=headers,
).json()
status = task["data"]["status"]
print(status)
if status in ("success", "failure"):
break
time.sleep(3)

if status == "success":
print(task["data"]["data"][0].keys())
const taskId = "<task_id>";
const headers = { Authorization: `Bearer ${process.env.COMETAPI_KEY}` };

let task;
while (true) {
const response = await fetch(
`https://api.cometapi.com/v1/images/generations/${taskId}`,
{ headers },
);
task = await response.json();
const status = task.data.status;
console.log(status);
if (status === "success" || status === "failure") break;
await new Promise((resolve) => setTimeout(resolve, 3000));
}

if (task.data.status === "success") {
console.log(Object.keys(task.data.data[0]));
}
<?php

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://api.cometapi.com/v1/images/generations/{task_id}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
package main

import (
"fmt"
"net/http"
"io"
)

func main() {

url := "https://api.cometapi.com/v1/images/generations/{task_id}"

req, _ := http.NewRequest("GET", url, nil)

req.Header.Add("Authorization", "Bearer <token>")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.get("https://api.cometapi.com/v1/images/generations/{task_id}")
.header("Authorization", "Bearer <token>")
.asString();
require 'uri'
require 'net/http'

url = URI("https://api.cometapi.com/v1/images/generations/{task_id}")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'

response = http.request(request)
puts response.read_body
{
  "code": "success",
  "data": {
    "task_id": "<task_id>",
    "status": "pending",
    "data": []
  }
}
Use this endpoint after you create an image with POST /v1/images/generations and async: true. The create request returns data.task_id, and this endpoint returns the task state plus final image data when the task succeeds.

Poll an image task

1

Create the task

Send POST /v1/images/generations with async: true, then store data.task_id.
2

Poll the task

Call this endpoint with the stored task ID until data.status is success or failure.
3

Read the image data

When data.status is success, read the first item in data.data. Depending on the selected model, the item can include b64_json, url, or revised_prompt.

Status values

  • pending: The task is queued or generating.
  • success: The task finished and data.data contains the generated image data.
  • failure: The task failed. Check data.fail_reason when it is returned.

Authorizations

Authorization
string
header
required

Bearer token authentication. Use your CometAPI key.

Path Parameters

task_id
string
required

Task ID returned in data.task_id by the async create request.

Response

200 - application/json

Current image generation task state.

code
string
required

Request status code. Successful task lookups return success.

Example:

"success"

data
object
required
message
string

Optional status message.