# 图生视频

**这是什么**：把一张参考图变成动态视频。wan2.7-i2v 支持三大任务：首帧生视频、首尾帧生视频（传 lastFrameUrl）、视频续写（imageUrls 传 .mp4/.mov 首段视频）。

**什么时候用**：已有图片，想让画面动起来时用；或想用首尾帧控制起止画面、用首段视频做续写。

## 接口地址
- 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-i2v / wan2.5-i2v-preview（默认有声）/ happyhorse-1.0-i2v / happyhorse-1.1-i2v / wan3.0-video / wan3.0-video-prime（全能：传 imageUrls 即图生视频，传 lastFrameUrl 走首尾帧）/ vidu/viduq3-pro_img2video（⚠ 账号未开通，暂不可用） |
| imageUrls | string[] | 是 | 输入图片 URL 数组，通常取第一张作为首帧。⚠️ 仅支持 jpg / png，不可用 webp（否则会判 Required body invalid）。wan2.7-i2v 视频续写时第一项可为 .mp4/.mov 首段视频。 |
| lastFrameUrl | string | — | 尾帧图 URL（wan2.7-i2v 首尾帧 / 视频续写时作为结尾画面） |
| prompt | string | — | 运动/镜头描述 |
| duration | integer | — | 时长（秒），默认 5，影响计费；wan2.5-preview 仅支持 5 / 10；happyhorse 取 3~15；wan3.0-video/prime 取 2~30（传 -1 为智能时长） |
| aspectRatio | string | — | 比例/分辨率映射：16:9、9:16 通常为 1080P，1:1 为 720P，4:3/3:4 为 480P |
| audio | boolean | — | 是否生成有声视频（支持时使用） |
| audioUrl | string | — | 可选音频驱动 URL |
| 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-i2v",
  "prompt": "镜头缓慢推进，光影自然变化",
  "imageUrls": [
    "https://example.com/first-frame.jpg"
  ],
  "aspectRatio": "16:9",
  "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-i2v",
        "prompt": "镜头缓慢推进，光影自然变化",
        "imageUrls": [
            "https://example.com/first-frame.jpg",
        ],
        "aspectRatio": "16:9",
        "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-i2v",
    "prompt": "镜头缓慢推进，光影自然变化",
    "imageUrls": [
      "https://example.com/first-frame.jpg"
    ],
    "aspectRatio": "16:9",
    "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-i2v",
  "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-i2v",
  "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
```
