Chuyển đến nội dung chính
GET
/
v1
/
images
/
generations
/
{task_id}
curl "https://api.lemondata.cc/v1/images/generations/img_abc123def456" \
  -H "Authorization: Bearer sk-your-api-key"
{
  "created": 1706000000,
  "task_id": "img_abc123def456",
  "status": "pending",
  "data": [
    {
      "url": "",
      "revised_prompt": "a beautiful sunset over mountains"
    }
  ]
}

Tham số đường dẫn

task_id
string
bắt buộc
ID tác vụ được trả về từ yêu cầu tạo hình ảnh ban đầu.

Phản hồi

created
integer
Dấu thời gian Unix khi tạo.
task_id
string
Mã định danh tác vụ.
status
string
Trạng thái tác vụ: pending, processing, completed, hoặc failed.
data
array
Mảng các hình ảnh đã tạo (được điền khi statuscompleted).Mỗi đối tượng chứa:
  • url (string): URL của hình ảnh đã tạo
  • revised_prompt (string): Prompt đã sử dụng để tạo
error
string
Thông báo lỗi (chỉ xuất hiện khi statusfailed).
curl "https://api.lemondata.cc/v1/images/generations/img_abc123def456" \
  -H "Authorization: Bearer sk-your-api-key"
{
  "created": 1706000000,
  "task_id": "img_abc123def456",
  "status": "pending",
  "data": [
    {
      "url": "",
      "revised_prompt": "a beautiful sunset over mountains"
    }
  ]
}

Thực hành tốt nhất khi Polling

Khoảng thời gian polling khuyến nghị: 3-5 giây. Hầu hết các tác vụ tạo hình ảnh hoàn thành trong vòng 30-120 giây tùy thuộc vào mô hình.
import requests
import time

def poll_image_task(task_id, api_key, max_wait=300, interval=3):
    """Polling kết quả tạo hình ảnh với timeout."""
    url = f"https://api.lemondata.cc/v1/images/generations/{task_id}"
    headers = {"Authorization": f"Bearer {api_key}"}

    start_time = time.time()
    while time.time() - start_time < max_wait:
        response = requests.get(url, headers=headers)
        data = response.json()

        if data["status"] == "completed":
            return data["data"][0]["url"]
        elif data["status"] == "failed":
            raise Exception(data.get("error", "Generation failed"))

        time.sleep(interval)

    raise TimeoutError(f"Task {task_id} did not complete within {max_wait}s")

# Sử dụng
image_url = poll_image_task("img_abc123def456", "sk-your-api-key")
print(f"Generated image: {image_url}")

Tham số đường dẫn

task_id
string
bắt buộc

ID tác vụ được trả về từ yêu cầu tạo hình ảnh ban đầu.

Phản hồi

200 - application/json

Response 200

created
integer

Dấu thời gian Unix khi tạo.

task_id
string

Mã định danh tác vụ.

status
string

Trạng thái tác vụ: pending , processing , completed , hoặc failed .

data
object[]

Mảng các hình ảnh đã tạo (được điền khi statuscompleted ). Mỗi đối tượng chứa: url (string): URL của hình ảnh đã tạo revised_prompt (string): Prompt đã sử dụng để tạo

error
string

Thông báo lỗi (chỉ xuất hiện khi statusfailed ).