# 图生 / 首尾帧视频

**这是什么**：给定首帧图（可再加尾帧），生成从首帧出发、过渡到尾帧的视频。

**什么时候用**：想让一张图动起来、或精确控制开头 / 结尾画面时用。画面比例跟随首帧图，aspectRatio 传了也不生效。

## 接口地址
- 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 | 是 | 子模型：pixverse-v5.6 / pixverse-v6 / pixverse-c1（见下方子模型对照表） |
| prompt | string | — | 视频描述（可留空，由素材驱动） |
| firstFrameUrl | string | 是 | 首帧图 URL（须公网可直连）；不能与 imageUrls / videoUrls 同时使用 |
| lastFrameUrl | string | — | 尾帧图 URL（可选；需同时传首帧，生成首→尾过渡） |
| negativePrompt | string | — | 反向提示词（可选） |
| duration | integer | — | 时长（秒），范围随子模型（见对照表），缺省 5 |
| resolution | string | — | 540P / 720P / 1080P / 2K / 4K（可选档位随子模型），缺省 720P（无 720P 时取最低档）；2K / 4K 为超分输出 |
| generateAudio | boolean | — | 是否生成声音，默认 false（仅 pixverse-v6 / pixverse-c1 生效，按有声档计费） |
| enhancePrompt | boolean | — | 是否自动优化提示词（可选） |
| seed | integer | — | 随机种子（可选） |
| returnFirstFrame / returnLastFrame / returnFrameAtSecond | boolean / boolean / number | — | 额外返回成品视频的首帧 / 末帧 / 指定秒帧图（可选），每帧另计 1 积分 |

`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": "pixverse-v5.6",
  "prompt": "smooth transition between the two frames",
  "firstFrameUrl": "https://example.com/first.jpg",
  "lastFrameUrl": "https://example.com/last.jpg",
  "duration": 5,
  "resolution": "720P"
}'
```

```python
import os, requests

r = requests.post(
    "https://api.novapi.ai/v1/videos",
    headers={"Authorization": "Bearer " + os.environ["API_KEY"]},
    json={
        "model": "pixverse-v5.6",
        "prompt": "smooth transition between the two frames",
        "firstFrameUrl": "https://example.com/first.jpg",
        "lastFrameUrl": "https://example.com/last.jpg",
        "duration": 5,
        "resolution": "720P",
    },
)
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": "pixverse-v5.6",
    "prompt": "smooth transition between the two frames",
    "firstFrameUrl": "https://example.com/first.jpg",
    "lastFrameUrl": "https://example.com/last.jpg",
    "duration": 5,
    "resolution": "720P"
  }),
});
console.log(await resp.json()); // poll GET /v1/videos/{id} until status is completed
```

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

```json
{
  "id": "video_<task-id>",
  "object": "video",
  "model": "pixverse-v5.6",
  "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
```
