الانتقال إلى المحتوى الرئيسي
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"
    }
  ]
}

معاملات المسار

task_id
string
مطلوب
معرف المهمة المُرجع من طلب إنشاء الصورة الأولي.

الاستجابة

created
integer
الطابع الزمني Unix للإنشاء.
task_id
string
معرف المهمة.
status
string
حالة المهمة: pending، processing، completed، أو failed.
data
array
مصفوفة الصور المُنشأة (تُملأ عندما تكون status هي completed).كل عنصر يحتوي على:
  • url (string): رابط الصورة المُنشأة
  • revised_prompt (string): الوصف المستخدم للإنشاء
error
string
رسالة الخطأ (موجودة فقط عندما تكون status هي failed).
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"
    }
  ]
}

أفضل ممارسات الاستعلام

فترة الاستعلام الموصى بها: 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/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")

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

معلمات المسار

task_id
string
مطلوب

معرف المهمة المُرجع من طلب إنشاء الصورة الأولي.

الاستجابة

200 - application/json

Response 200

created
integer

الطابع الزمني Unix للإنشاء.

task_id
string

معرف المهمة.

status
string

حالة المهمة: pending ، processing ، completed ، أو failed .

data
object[]

مصفوفة الصور المُنشأة (تُملأ عندما تكون status هي completed ). كل عنصر يحتوي على: url (string): رابط الصورة المُنشأة revised_prompt (string): الوصف المستخدم للإنشاء

error
string

رسالة الخطأ (موجودة فقط عندما تكون status هي failed ).