# AI Video Montage API

> Turn one or more videos into a single finished montage cut by AI.

## AI Video Montage API

Submit one or more videos and receive one finished video. AI selects and cuts the best parts.

AI Video Montage requires a paid WayinVideo plan. The total length of the sources is limited by the plan.

## Supported Sources

Each item in `sources` has a `type`. Types can be mixed in one request.

| `type` | Fields | Description |
| ------ | ------ | ----------- |
| `url`  | `value` | A platform video link (YouTube, TikTok, Vimeo, and the other sources listed in the [Introduction](https://wayin.ai/api-docs/introduction/)). |
| `file` | `value` | The `identity` returned by the [Upload API](https://wayin.ai/api-docs/upload/). Local upload requires a **Starter** plan or above. |
| `clip` | `project_id`, `clip_index` | A clip from a [AI Clipping](https://wayin.ai/api-docs/ai-clipping/) or [Find Moments](https://wayin.ai/api-docs/find-moments/) project. `clip_index` is the clip's `idx` in that project's results. Only the clip's own range is used. |

### Workflow

1. **Submit** a montage with one or more sources
2. **Poll** the results until `status` is `DONE` or `ERROR`
3. When `status` is `DONE`, **export** the montage to render it as a video file
4. **Poll** the export results until `status` is `SUCCEEDED`, then read the clip's `export_link`

---

## Endpoints

| Method | Path                               | Description                  |
| ------ | ---------------------------------- | ---------------------------- |
| `POST` | `/api/v2/montage`                  | Submit a montage task        |
| `GET`  | `/api/v2/montage/results/{id}`     | Retrieve the task result     |
| `POST` | `/api/v2/montage/export`           | Render a finished montage as a video file |
| `GET`  | `/api/v2/clips/export/{taskId}`    | Retrieve the export result   |

All requests require:

```http
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json
x-wayinvideo-api-version: v2
```

---

## Submit Montage Task

```http
POST https://wayinvideo-api.wayin.ai/api/v2/montage
```

### Request Body

| Parameter        | Type     | Required | Default    | Description |
| ---------------- | -------- | -------- | ---------- | ----------- |
| `sources`        | object[] | Yes      | —          | One or more sources. See [Supported Sources](#supported-sources). |
| `prompt`         | string   | No       | —          | What the montage should focus on. |
| `ratio`          | string   | Yes      | —          | Output aspect ratio: `RATIO_16_9`, `RATIO_9_16`, `RATIO_1_1`, `RATIO_4_5`. To keep the original framing, use the ratio closest to the sources with `enable_ai_reframe` set to `false`. |
| `target_duration`| string   | No       | Auto       | Length range of the montage: `DURATION_0_30`, `DURATION_0_90`, `DURATION_30_60`, `DURATION_60_90`, `DURATION_90_180`, `DURATION_180_300` (in seconds, e.g. `DURATION_30_60` is 30–60 seconds). Omit to let the length be chosen automatically. |
| `main_video_speed` | number | No | `1.0` | Playback speed of the main video clips in the editable montage (0.5–10). At 1.5×, 30 seconds of source footage plays in 20 seconds. |
| `outra` | string | No | — | Video `identity` returned by [Upload](https://wayin.ai/api-docs/upload/). After uploading the file, pass its identity here to append the full video after the montage at its original speed. |
| `target_lang`    | string   | Yes      | —          | Lowercase language code the montage is made in (captions and AI text), for example `en` or `zh-cn`. When it differs from the language spoken in the sources, captions are translated into it. See [Supported Languages](https://wayin.ai/api-docs/supported-languages/). |
| `caption_display`| string   | No       | —          | `original`, `translation`, or `both`. Used when `target_lang` differs from the language spoken in the sources. |
| `enable_caption` | boolean  | No       | —          | Burn captions into the montage. |
| `cc_style_tpl`   | string   | No       | —          | Caption style. See [Subtitles Style](https://wayin.ai/api-docs/subtitles-style/). When `caption_display` is `both`, only `temp-static-1` to `temp-static-6` are allowed. |
| `enable_ai_reframe` | boolean | No    | `true`     | Track the subject and reframe to `ratio`. Set to `false` to fit the video into `ratio` without tracking. |
| `reframe_layout` | string   | No       | `Auto`     | Layout used when reframing to `ratio`. Default `Auto`: the model picks the best layout. Allowed values depend on `ratio`; see [Reframe layout values](https://wayin.ai/api-docs/ai-clipping/#reframe-layout-values). |
| `enable_ai_hook` | boolean  | No       | —          | Add an AI text hook. Uses extra API units. |
| `ai_hook_script_style` | string | No   | `serious`  | Tone of the hook when `enable_ai_hook` is true. |
| `ai_hook_position` | string | No     | `beginning`| `beginning` or `end`. |
| `ai_hook_keywords` | string | No | — | Instructions for writing the hook text. |
| `ai_hook_prompt_with_video_info` | boolean | No | `false` | With `enable_ai_hook=true` and nonblank `ai_hook_keywords`, set to `true` to use metadata from the first video in `sources`, including its original title. |
| `ai_hook_text_duration` | integer | No | —        | How long the hook text stays on screen, in milliseconds (1–60000). |
| `enable_broll`   | boolean  | No       | —          | Insert B-roll. Uses extra API units. |
| `broll_resource_type` | string | With `enable_broll` | — | `RESOURCE_VIDEO_AI_BROLL` or `RESOURCE_VIDEO_STOCK_BROLL`. |
| `enable_bgm`     | boolean  | No       | —          | Add background music. Requires a paid plan and uses extra API units. |
| `bgm_placement`  | string   | No       | `entire`   | `entire` or `parts`. |
| `bgm_style`      | string   | No       | `Auto`     | Music style. |
| `bgm_prompt`     | string   | No       | —          | Short description of the music. |

### Example Request

```bash
curl -X POST https://wayinvideo-api.wayin.ai/api/v2/montage \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "x-wayinvideo-api-version: v2" \
  -d '{
    "sources": [
      { "type": "url", "value": "https://www.youtube.com/watch?v=dQw4w9WgXcQ" },
      { "type": "file", "value": "EF_up_06wguq1afbwg1" },
      { "type": "clip", "project_id": "proj_01HQ2X8J3K4L5M6N7O8P9Q0A", "clip_index": 2 }
    ],
    "prompt": "product demo highlights",
    "ratio": "RATIO_9_16",
    "target_duration": "DURATION_30_60",
    "main_video_speed": 1.5,
    "outra": "EF_up_your_uploaded_outro",
    "target_lang": "en",
    "enable_ai_hook": true,
    "ai_hook_keywords": "Include the original title of the first source video.",
    "ai_hook_prompt_with_video_info": true
  }'
```

### Response

A newly submitted task is `START` or `WAIT_ASYNC` while it is still running.

```json
{
  "data": {
    "id": "proj_01HQ2X8J3K4L5M6N7O8P9Q0R",
    "status": "START"
  }
}
```

| Field        | Type   | Description |
| ------------ | ------ | ----------- |
| `id`         | string | Project id. Pass it in the results path and to the export endpoint. |
| `status`     | string | `START` or `WAIT_ASYNC` means still running. `DONE` means the montage is ready to export. `ERROR` means failed. |

---

## Retrieve Montage Result

Poll with the `id` from the submit response until `status` is `DONE` or `ERROR`. Montage can take longer than clipping. Wait at least 60 seconds between checks.

```http
GET https://wayinvideo-api.wayin.ai/api/v2/montage/results/{id}
```

### Example Request

```bash
curl -X GET https://wayinvideo-api.wayin.ai/api/v2/montage/results/proj_01HQ2X8J3K4L5M6N7O8P9Q0R \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "x-wayinvideo-api-version: v2"
```

### Response

```json
{
  "data": {
    "id": "proj_01HQ2X8J3K4L5M6N7O8P9Q0R",
    "status": "DONE"
  }
}
```

`DONE` means the montage has been made. It is not a video file yet: call the export endpoint to render it.

---

## Export Montage

Renders a montage whose status is `DONE` as a downloadable video file. The montage is exported as it was made; no edits are applied again.

```http
POST https://wayinvideo-api.wayin.ai/api/v2/montage/export
```

### Request Body

| Parameter    | Type   | Required | Default  | Description |
| ------------ | ------ | -------- | -------- | ----------- |
| `project_id` | string | Yes      | —        | The `id` returned when the montage was submitted. |
| `resolution` | string | No       | `SD_480` | Output resolution: `SD_480`, `HD_720`, `FHD_1080`, `QHD_2K`, `UHD_4K`. |

### Example Request

```bash
curl -X POST https://wayinvideo-api.wayin.ai/api/v2/montage/export \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "x-wayinvideo-api-version: v2" \
  -d '{
    "project_id": "proj_01HQ2X8J3K4L5M6N7O8P9Q0R",
    "resolution": "FHD_1080"
  }'
```

### Response

```json
{
  "data": {
    "export_task_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    "status": "CREATED"
  }
}
```

Poll `GET /api/v2/clips/export/{export_task_id}` until `status` is `SUCCEEDED` or `FAILED`, as described in the [Clips Export API](https://wayin.ai/api-docs/clips-export/). On `SUCCEEDED`, `clips` contains one item, and its `export_link` is the montage video. Calling the export endpoint before the montage is `DONE` returns an error.

---

## Billing

Montage consumes **2 API Units per minute** of the total length of the sources (4 on older plans); a clip counts only its own length, rounded up to the next whole minute. A total shorter than 1 minute is billed as 1 minute.

The following are charged on top, per minute of the finished video, rounded up:

| Item                  | API Units | When |
| --------------------- | --------- | ---- |
| Captions              | 0.5 per minute | Every montage |
| Caption translation   | 0.5 per minute | When `target_lang` differs from the language spoken in the sources |
| AI Reframe            | 0.5 per minute | On by default; not charged when `enable_ai_reframe` is `false` |

AI hook, B-roll and background music consume additional API units when enabled. Exporting the finished montage is free. If the account does not have enough API units, the task is not created. Failed tasks are refunded. See [Billing](https://wayin.ai/api-docs/pricing/) and [Status Codes](https://wayin.ai/api-docs/status-codes/).

---

## Errors

Failed requests use the standard status codes and response formats. See [Status Codes](https://wayin.ai/api-docs/status-codes/).
