メインコンテンツへスキップ

非同期ジョブライフサイクル

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")

関連ドキュメント