Chuyển đến nội dung chính
GET
/
v1
/
videos
/
generations
/
{id}
curl "https://api.lemondata.cc/v1/videos/generations/video_abc123" \
  -H "Authorization: Bearer sk-your-api-key"
{
  "task_id": "video_abc123",
  "status": "pending",
  "progress": 0,
  "model": "kling-v2.6-pro",
  "created_at": 1706000000
}

Tham số Đường dẫn

task_id
string
bắt buộc
ID tác vụ được trả về từ yêu cầu tạo video.

Phản hồi

task_id
string
Định danh tác vụ.
status
string
Trạng thái tác vụ: pending, processing, completed, failed.
progress
number
Phần trăm tiến độ (0-100).
video_url
string
URL của video đã tạo (khi hoàn tất).
error
string
Thông báo lỗi (nếu thất bại).
created_at
integer
Dấu thời gian tạo.
completed_at
integer
Dấu thời gian hoàn tất (khi xong).
curl "https://api.lemondata.cc/v1/videos/generations/video_abc123" \
  -H "Authorization: Bearer sk-your-api-key"
{
  "task_id": "video_abc123",
  "status": "pending",
  "progress": 0,
  "model": "kling-v2.6-pro",
  "created_at": 1706000000
}

Các phương pháp Polling tốt nhất

  • Thực hiện poll mỗi 5-10 giây
  • Triển khai exponential backoff cho các tác vụ dài
  • Thiết lập thời gian chờ tối đa (ví dụ: 10 phút)
  • Xử lý trạng thái failed một cách khéo léo
import time

def wait_for_video(task_id, max_wait=600, interval=5):
    """Wait for video with timeout."""
    start = time.time()

    while time.time() - start < max_wait:
        response = requests.get(
            f"https://api.lemondata.cc/v1/videos/generations/{task_id}",
            headers={"Authorization": "Bearer sk-your-api-key"}
        )
        data = response.json()

        if data["status"] == "completed":
            return data["video_url"]
        elif data["status"] == "failed":
            raise Exception(data.get("error", "Video generation failed"))

        time.sleep(interval)

    raise TimeoutError("Video generation timed out")