# Video Tasks

Create video tasks, poll their status, and download completed video files.

Video generation is asynchronous. Create a task, save its ID, poll the status, and download the result after completion.

## Task endpoints

The general video task endpoint is:

```http
POST /v1/video/generations
```

OpenAI-style video requests use:

```http
POST /v1/videos
```

Both endpoints return a task object rather than the final video file.

## Text-to-video

```bash
curl https://kaienapi.com/v1/video/generations \\
  -H "Authorization: Bearer <YOUR_API_KEY>" \\
  -H "Content-Type: application/json" \\
  -d '{
    "model": "kling-v2-master",
    "prompt": "A five-second product video with a slow camera push and a clean background",
    "duration": 5,
    "size": "1280x720"
  }'
```

## Image-to-video

```bash
curl https://kaienapi.com/v1/videos/generations \\
  -H "Authorization: Bearer <YOUR_API_KEY>" \\
  -H "Content-Type: application/json" \\
  -d '{
    "model": "veo-3.1",
    "prompt": "Animate the scene with a gentle forward camera movement",
    "image": "https://oss.example.com/first-frame.jpg"
  }'
```

## Polling

Poll every few seconds while the task is queued or running. Stop only at a terminal state such as `succeeded` or `failed`.

```bash
curl "https://kaienapi.com/v1/video/generations/<TASK_ID>" \\
  -H "Authorization: Bearer <YOUR_API_KEY>"
```

Save the task ID in your application so the user can resume after refreshing the page. Do not create a second task just because one polling request temporarily failed.

## Downloading results

When the task succeeds, read the returned video URL or file reference and download it to storage you control. Result URLs may be temporary; do not treat them as permanent asset storage.
