메인 콘텐츠로 건너뛰기

경로 파라미터

id
string
필수
초기 이미지 생성 요청에서 반환된 작업 ID입니다.
생성 응답에 poll_url이 포함된 경우, 폴링을 위해 해당 URL을 호출하는 것을 권장합니다. 일부 이미지 작업은 이미지 전용 상태 경로 대신 /v1/tasks/{id} 아래에 poll_url을 표시할 수 있습니다.If the task no longer exists or can no longer be resolved through the public async-task contract, LemonData returns async_task_not_found with the message Task not found or no longer available.

응답

created
integer
생성 시점의 Unix 타임스탬프입니다.
task_id
string
작업 식별자입니다.
status
string
작업 상태: pending, processing, completed 또는 failed.
data
array
생성된 이미지 배열입니다 (statuscompleted인 경우 채워집니다).각 객체는 다음을 포함합니다:
  • url (string): 생성된 이미지의 URL
  • revised_prompt (string): 생성에 사용된 프롬프트
error
string
에러 메시지 (statusfailed인 경우에만 존재합니다).
curl "https://api.lemondata.cc/v1/tasks/ldtask_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" \
  -H "Authorization: Bearer sk-your-api-key"
{
  "created": 1706000000,
  "id": "ldtask_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "task_id": "ldtask_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "poll_url": "/v1/tasks/ldtask_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "status": "pending",
  "data": [
    {
      "url": "",
      "revised_prompt": "a beautiful sunset over mountains"
    }
  ]
}

폴링 권장 사항

권장 폴링 간격: 3-5초. 대부분의 이미지 생성 작업은 모델 및 라우팅된 제공자 경로에 따라 30-120초 이내에 완료됩니다.
import requests
import time

def poll_image_task(task_id, api_key, max_wait=300, interval=3):
    """Poll for image generation result with timeout."""
    url = f"https://api.lemondata.cc/v1/tasks/{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")

# Usage
image_url = poll_image_task("ldtask_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "sk-your-api-key")
print(f"Generated image: {image_url}")