주요 콘텐츠로 건너뛰기

비동기 작업 라이프사이클

AetherAI API의 모든 생성 작업은 비동기로 처리됩니다. 작업을 생성한 후 폴링을 통해 상태를 확인해야 합니다.

작업 생성

POST 요청을 보내면 즉시 job_id가 반환됩니다. 이미지 처리는 백그라운드에서 진행됩니다.

요청 예시

curl -X POST "https://api.aetherforgeai.com/public/v1/generate/image" \
-H "Authorization: Bearer your_api_key_here" \
-H "Content-Type: application/json" \
-d '{
"prompt": "A beautiful sunset over mountains",
"ai_model": "GPT Image 1.5"
}'

응답 예시

{
"job_id": "550e8400-e29b-41d4-a716-446655440000"
}

작업 상태 폴링

반환된 job_id로 GET 요청을 보내 작업 상태를 확인합니다.

curl -X GET "https://api.aetherforgeai.com/public/v1/job/{job_id}" \
-H "Authorization: Bearer your_api_key_here"

상태 값

상태설명
Pending작업이 대기 중이거나 처리 중입니다
Succeed작업이 성공적으로 완료되었습니다
Failed작업 처리 중 오류가 발생했습니다

상태별 응답 예시

Pending

{
"job_id": "550e8400-e29b-41d4-a716-446655440000",
"status": "Pending",
"image_urls": []
}

Succeed

{
"job_id": "550e8400-e29b-41d4-a716-446655440000",
"status": "Succeed",
"image_urls": [
"https://cdn.aetherforgeai.com/images/abc123.png",
"https://cdn.aetherforgeai.com/images/abc123.gif"
]
}

Failed

{
"job_id": "550e8400-e29b-41d4-a716-446655440000",
"status": "Failed",
"image_urls": []
}

폴링 전략

작업 완료를 확인하기 위해 다음 간격으로 폴링하는 것을 권장합니다.

  • 초기 폴링: 작업 생성 후 1초
  • 이후 간격: 2~5초
  • 최대 폴링 시간: 1분 (작업 유형에 따라 다름)

Python 예시

import time
import requests

def poll_job_status(job_id, api_key, max_attempts=60):
headers = {"Authorization": f"Bearer {api_key}"}

for attempt in range(max_attempts):
response = requests.get(
f"https://api.aetherforgeai.com/public/v1/job/{job_id}",
headers=headers
)
data = response.json()

if data["status"] == "Succeed":
return data["image_urls"]
elif data["status"] == "Failed":
raise Exception(f"Job failed: {data.get('error_message', 'Unknown error')}")

time.sleep(2)

raise TimeoutError("Job polling timed out")

관련 문서