Path Parameters
The task ID returned from the initial image generation request.
Response
Unix timestamp of creation.
Task status: pending, processing, completed, or failed.
Array of generated images (populated when status is completed).Each object contains:
url (string): URL of the generated image
revised_prompt (string): The prompt used for generation
Error message (only present when status is 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"
}
]
}
Polling Best Practices
Recommended polling interval: 3-5 seconds. Most image generation tasks complete within 30-120 seconds depending on the model.
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}")
The task ID returned from the initial image generation request.
Unix timestamp of creation.
Task status: pending , processing , completed , or failed .
Array of generated images (populated when status is completed ). Each object contains: url (string): URL of the generated image revised_prompt (string): The prompt used for generation
Error message (only present when status is failed ).