# 视频编辑

**这是什么**：基于源视频和编辑指令生成修改后的视频，支持纯指令编辑（改风格）与参考图局部替换（如换装）。

**什么时候用**：想对已有视频改风格、改画面或做局部编辑时用。

## 接口地址
- POST `/v1/videos`
- GET `/v1/videos/{id}`
- GET `/v1/videos/{id}/content`

> 本页已按统一 API 改写：创建用 `POST /v1/videos`，轮询用 `GET /v1/videos/{id}`，认证用 `Authorization: Bearer <key>`，错误为 OpenAI 格式。

创建后立即返回视频对象（`status: queued`）。轮询 `GET /v1/videos/{id}`，直到 `status` 为 `completed` 或 `failed`；完成后 `url` 是成片地址，也可用 `GET /v1/videos/{id}/content` 下载。

## 请求参数
| 参数 | 类型 | 必填 | 说明 |
| --- | --- | --- | --- |
| model | string | 是 | wan2.7-videoedit / happyhorse-1.0-video-edit |
| prompt | string | 是 | 编辑指令 |
| imageUrls | string[] | — | 第一项为源视频 URL（必传，2~10s、mp4/mov、≤100MB），其余为参考图（局部替换用，jpg/png；wan2.7 ≤4 张、happyhorse ≤5 张） |
| duration | integer | — | 输出时长（秒）；缺省=与输入等长，仅 [2,10] 截断。后付费按真实用时结算，此值不决定最终扣费 |
| aspectRatio | string | — | 比例/分辨率映射 |
| webhookUrl | string | — | 完成回调地址 |

`model`、`prompt`、`seconds`、`size`、`input_reference` 是统一接口的通用字段；其余字段是该模型渠道的专属字段，按原名放在同一个请求体里。`seconds` / `size`（必须是 `宽x高`）只有在没有传对应专属字段时才会被翻译。

## 请求示例
```bash
curl https://api.novapi.ai/v1/videos \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "wan2.7-videoedit",
  "prompt": "把视频改成冬季雪景氛围",
  "imageUrls": [
    "https://example.com/source-video.mp4"
  ],
  "duration": 5
}'
```

```python
import os, requests

r = requests.post(
    "https://api.novapi.ai/v1/videos",
    headers={"Authorization": "Bearer " + os.environ["API_KEY"]},
    json={
        "model": "wan2.7-videoedit",
        "prompt": "把视频改成冬季雪景氛围",
        "imageUrls": [
            "https://example.com/source-video.mp4",
        ],
        "duration": 5,
    },
)
print(r.json())  # poll GET /v1/videos/{id} until status is completed
```

```ts
const resp = await fetch("https://api.novapi.ai/v1/videos", {
  method: "POST",
  headers: {
    Authorization: "Bearer " + process.env.API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "model": "wan2.7-videoedit",
    "prompt": "把视频改成冬季雪景氛围",
    "imageUrls": [
      "https://example.com/source-video.mp4"
    ],
    "duration": 5
  }),
});
console.log(await resp.json()); // poll GET /v1/videos/{id} until status is completed
```

## 响应示例
```json
{
  "id": "video_<task-id>",
  "object": "video",
  "model": "wan2.7-videoedit",
  "status": "queued",
  "progress": 0,
  "created_at": <unix-seconds>,
  "completed_at": null,
  "expires_at": null,
  "error": null
}
```

```json
{
  "id": "video_<task-id>",
  "object": "video",
  "model": "wan2.7-videoedit",
  "status": "completed",
  "progress": 100,
  "created_at": <unix-seconds>,
  "completed_at": <unix-seconds>,
  "expires_at": null,
  "error": null,
  "url": "https://..."
}
```

```bash
curl https://api.novapi.ai/v1/videos/video_<task-id> \
  -H "Authorization: Bearer $API_KEY"

# completed: "status": "completed", "progress": 100, and a "url" field with the result
curl -L https://api.novapi.ai/v1/videos/video_<task-id>/content \
  -H "Authorization: Bearer $API_KEY" \
  --output result.mp4
```
