> ## Documentation Index
> Fetch the complete documentation index at: https://docs.eigenai.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Generate Video

> Submit an image-to-video generation job and retrieve the result asynchronously.

Video generation is an asynchronous workflow. You submit a job, poll until it completes, then download the result.

| Step            | Method | Endpoint                  |
| --------------- | ------ | ------------------------- |
| Submit job      | `POST` | `/api/v1/generate`        |
| Poll status     | `GET`  | `/api/v1/generate/status` |
| Download result | `GET`  | `/api/v1/generate/result` |

**Content-Type (submission):** `multipart/form-data`

<Warning>
  Parameter support can differ depending on the model used. Check the Model Library for model-specific compatibility. [Open Model Library](https://app.eigenai.com/model-library).
</Warning>

## Authentication

Send your API key in the `Authorization` header as a Bearer token.

```bash theme={null}
Authorization: Bearer YOUR_API_KEY
```

## Step 1 — Submit job

`POST /api/v1/generate`

### Parameters

| Name          | Type      | Required        | Description                                             |
| ------------- | --------- | --------------- | ------------------------------------------------------- |
| `model`       | `string`  | Required        | The model ID (e.g. `wan2p2-i2v-14b-turbo`).             |
| `prompt`      | `string`  | Required        | Text describing the desired video motion and animation. |
| `image`       | `file`    | One of required | Source image to animate (multipart file upload).        |
| `image_url`   | `string`  | One of required | URL of the source image to animate.                     |
| `infer_steps` | `integer` | Optional        | Number of inference steps (default 5, range 1–20).      |
| `seed`        | `integer` | Optional        | Random seed for reproducible results.                   |

### Response

```json theme={null}
{
  "task_id": "XXXX-XXXX-XXXX-XXXX-XXXX",
  "task_status": "pending"
}
```

## Step 2 — Poll status

`GET /api/v1/generate/status?jobId={task_id}&model={model}`

Poll this endpoint until `status` is `completed` or `failed`.

### Response

```json theme={null}
{
  "task_id": "XXXX-XXXX-XXXX-XXXX-XXXX",
  "status": "completed",
  "start_time": "2024-01-01T00:00:00.000Z",
  "end_time": "2024-01-01T00:01:00.000Z",
  "error": null
}
```

| Field    | Description                                             |
| -------- | ------------------------------------------------------- |
| `status` | `pending`, `processing`, `completed`, or `failed`       |
| `error`  | Error message if `status` is `failed`, otherwise `null` |

## Step 3 — Download result

`GET /api/v1/generate/result?jobId={task_id}&model={model}`

Returns the generated MP4 file as binary content.

## Examples

### Full workflow

<CodeGroup>
  ```bash cURL theme={null}
  # Step 1: Submit job
  curl -X POST https://api-web.eigenai.com/api/v1/generate \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -F "model=wan2p2-i2v-14b-turbo" \
    -F "prompt=A person waving hello" \
    -F "image=@/path/to/image.jpg" \
    -F "infer_steps=5" \
    -F "seed=42"

  # Step 2: Poll status (replace TASK_ID)
  curl "https://api-web.eigenai.com/api/v1/generate/status?jobId=TASK_ID&model=wan2p2-i2v-14b-turbo" \
    -H "Authorization: Bearer YOUR_API_KEY"

  # Step 3: Download result
  curl "https://api-web.eigenai.com/api/v1/generate/result?jobId=TASK_ID&model=wan2p2-i2v-14b-turbo" \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -o output.mp4
  ```

  ```python Python theme={null}
  import time
  import requests

  API_KEY = "YOUR_API_KEY"
  BASE_URL = "https://api-web.eigenai.com"
  MODEL = "wan2p2-i2v-14b-turbo"

  # Step 1: Submit job
  with open("image.jpg", "rb") as image_file:
      response = requests.post(
          f"{BASE_URL}/api/v1/generate",
          headers={"Authorization": f"Bearer {API_KEY}"},
          data={"model": MODEL, "prompt": "A person waving hello", "infer_steps": "5", "seed": "42"},
          files={"image": image_file},
      )
  response.raise_for_status()
  task_id = response.json()["task_id"]
  print(f"Job submitted: {task_id}")

  # Step 2: Poll status
  while True:
      status_response = requests.get(
          f"{BASE_URL}/api/v1/generate/status",
          params={"jobId": task_id, "model": MODEL},
          headers={"Authorization": f"Bearer {API_KEY}"},
      )
      status_data = status_response.json()
      status = status_data.get("status")
      print(f"Status: {status}")
      if status == "completed":
          break
      elif status == "failed":
          raise RuntimeError(f"Job failed: {status_data.get('error')}")
      time.sleep(2)

  # Step 3: Download result
  result_response = requests.get(
      f"{BASE_URL}/api/v1/generate/result",
      params={"jobId": task_id, "model": MODEL},
      headers={"Authorization": f"Bearer {API_KEY}"},
  )
  result_response.raise_for_status()
  with open("output.mp4", "wb") as f:
      f.write(result_response.content)
  print("Video saved to output.mp4")
  ```

  ```javascript JavaScript theme={null}
  import fs from "node:fs";
  import FormData from "form-data";
  import axios from "axios";

  const API_KEY = "YOUR_API_KEY";
  const BASE_URL = "https://api-web.eigenai.com";
  const MODEL = "wan2p2-i2v-14b-turbo";

  // Step 1: Submit job
  const form = new FormData();
  form.append("model", MODEL);
  form.append("prompt", "A person waving hello");
  form.append("image", fs.createReadStream("image.jpg"));
  form.append("infer_steps", "5");
  form.append("seed", "42");

  const submitResponse = await axios.post(`${BASE_URL}/api/v1/generate`, form, {
    headers: { ...form.getHeaders(), Authorization: `Bearer ${API_KEY}` },
  });
  const taskId = submitResponse.data.task_id;
  console.log("Job submitted:", taskId);

  // Step 2: Poll status
  while (true) {
    const statusResponse = await axios.get(`${BASE_URL}/api/v1/generate/status`, {
      params: { jobId: taskId, model: MODEL },
      headers: { Authorization: `Bearer ${API_KEY}` },
    });
    const status = statusResponse.data.status;
    console.log("Status:", status);
    if (status === "completed") break;
    if (status === "failed") throw new Error(statusResponse.data.error);
    await new Promise((resolve) => setTimeout(resolve, 2000));
  }

  // Step 3: Download result
  const videoResponse = await axios.get(`${BASE_URL}/api/v1/generate/result`, {
    params: { jobId: taskId, model: MODEL },
    headers: { Authorization: `Bearer ${API_KEY}` },
    responseType: "arraybuffer",
  });
  fs.writeFileSync("output.mp4", Buffer.from(videoResponse.data));
  console.log("Video saved to output.mp4");
  ```
</CodeGroup>
