# HappyHorse 视频生成
> 文生视频、图生视频、参考生视频
> 计费只看分辨率与时长，与模式无关
> 首帧图与参考图不能混用
`POST /v1/videos`
## 认证
- `Authorization` (string / 必填) — 所有接口均使用 Bearer Token 进行认证。 获取 API Key：[访问控制台](https://api.oairoute.com/keys) 创建。 请求时在请求头中添加： ```http Authorization: Bearer YOUR_OAIRoute_KEY ```
## 请求参数
> **Note:** 
> 提交成功只返回任务 ID，不含视频本身。拿成片用 `task_id` 轮询[获取任务状态](../tasks/status.html)，成片地址在 `result.videos[0].url`，该地址约 24 小时后过期，请及时转存。
- `model` (string / 必填) — 取值 `happyhorse-1.1` 或 `happyhorse-1.0`。
- `prompt` (string / 可选) — 画面描述，上限 2500 字符，不支持特殊标记。
- `first_frame_image` (string / 可选) — 首帧，公网 URL 或 Base64 data URI。 格式 jpeg、jpg、png、bmp、webp，最短边至少 300 像素，宽高比 1:2.5 到 2.5:1，不超过 10MB。与 `image_urls` 互斥。
- `image_urls` (string[] / 可选) — 参考图，1 到 9 张。格式同上，单张不超过 10MB。与 `first_frame_image` 互斥。
- `resolution` (string / 可选) — 取值 `720P`、`1080P`，默认 `1080P`。影响计费。
- `duration` (integer / 可选) — 时长，3 到 15 秒，默认 `5`。影响计费。
- `size` (string / 可选) — 输出画幅，取值 `16:9`、`9:16`、`1:1`、`4:3`、`3:4`，默认 `16:9`。 图生视频会忽略该字段，改用输入图片比例。
- `watermark` (boolean / 可选) — 是否添加水印，默认 `false`。
- `seed` (integer / 可选) — 随机种子，取值 0 到 2147483647。
- `nsfw_check` (boolean / 可选) — 为 `true` 时先做内容审查，默认 `false`。
## 模式判定
按以下优先级判定，命中即停：
1. 只有 `prompt` —— 文生视频
2. `prompt` 加 `first_frame_image` —— 图生视频
3. `prompt` 加 `image_urls`（1 到 9 张）—— 参考生视频
`first_frame_image` 与 `image_urls` 不能同时传，同时会出现返回 400 与错误码 `mixed_media_not_allowed`。
## 支持的模型列表
| 模型 ID | 定位 |
|---|---|
| `happyhorse-1.1` | 当前版本，三种模式统一入口 |
| `happyhorse-1.0` | 上一代，参数兼容 |
## 使用限制
- 首帧图与参考图互斥
- 5 到 10 秒是推荐区间：更短容易动作不连贯，更长会显著拉长上游处理时间
- 图生视频的画质高度依赖首帧：构图清晰、主体居中的首帧效果明显更好
## 响应
提交成功返回统一的受理结构：
```json
{
  "code": 200,
  "data": [
    {
      "status": "submitted",
      "task_id": "task_01K8SGYNNNVBQTXNR4MM964S7K"
    }
  ]
}
```
- `code` (integer / 总是返回) — 状态码，`200` 表示任务已受理。
- `data` (array / 总是返回) — 本次提交的任务列表，逐项提交时按顺序排列。
- `data[].status` (string / 总是返回) — 受理状态，提交成功时为 `submitted`。
- `data[].task_id` (string / 总是返回) — 任务 ID，用它轮询结果。
## 错误
| HTTP | type | 说明 |
|---|---|---|
| 400 | invalid_request_error | 请求参数无效，或参数组合冲突 |
| 401 | authentication_error | 身份验证失败，需检查 API Key |
| 402 | payment_required | 账户余额不足，需先充值 |
| 429 | rate_limit_error | 调用频率过高，稍后重试 |
参数错误在提交阶段同步返回，不创建任务、不扣费。
更多状态码与重试建议见[错误码与限流](../../support/errors.html)，常见报错的排查步骤见[常见问题](../../support/faq.html)。
## 查询任务
`GET /v1/tasks/{task_id}` 返回任务进度与结果，`status` 为 `completed` 时成片地址在 `result.videos[0].url`，元素带 `expires_at` 过期时间戳。
建议每 5 到 10 秒轮询一次，客户端总超时设为 10 到 15 分钟。`status` 取值 `pending`、`processing`、`completed`、`failed`、`cancelled`，以状态判定完成，不要依赖 `progress`。
失败任务自动退回费用，`error.message` 给出原因。
**文生视频{Text to video}::cURL**
```
curl --request POST \
  --url 'https://api.oairoute.com/v1/videos' \
  --header 'Authorization: Bearer YOUR_OAIRoute_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "happyhorse-1.1",
  "prompt": "古风庭院里，一位女子在雨中撑伞走过石桥，镜头缓慢跟随",
  "resolution": "1080P",
  "duration": 8,
  "size": "16:9"
}'
```
**文生视频{Text to video}::Python**
```
import requests
url = "https://api.oairoute.com/v1/videos"
headers = {
    "Authorization": "Bearer YOUR_OAIRoute_KEY",
    "Content-Type": "application/json",
}
payload = {
  "model": "happyhorse-1.1",
  "prompt": "古风庭院里，一位女子在雨中撑伞走过石桥，镜头缓慢跟随",
  "resolution": "1080P",
  "duration": 8,
  "size": "16:9"
}
res = requests.post(url, headers=headers, json=payload)
print(res.json())
```
**文生视频{Text to video}::JavaScript**
```
const res = await fetch("https://api.oairoute.com/v1/videos", {
  method: "POST",
  headers: {
    Authorization: "Bearer YOUR_OAIRoute_KEY",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
  "model": "happyhorse-1.1",
  "prompt": "古风庭院里，一位女子在雨中撑伞走过石桥，镜头缓慢跟随",
  "resolution": "1080P",
  "duration": 8,
  "size": "16:9"
}),
});
console.log(await res.json());
```
**200 文生视频{Text to video}**
```
{
  "code": 200,
  "data": [
    {
      "status": "submitted",
      "task_id": "task_01K8SGYNNNVBQTXNR4MM964S7K"
    }
  ]
}
```
**图生视频{Image to video}::cURL**
```
curl --request POST \
  --url 'https://api.oairoute.com/v1/videos' \
  --header 'Authorization: Bearer YOUR_OAIRoute_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "happyhorse-1.1",
  "prompt": "人物缓缓抬头，雨滴从伞沿滑落",
  "first_frame_image": "https://example.com/umbrella.png",
  "resolution": "1080P",
  "duration": 8
}'
```
**图生视频{Image to video}::Python**
```
import requests
url = "https://api.oairoute.com/v1/videos"
headers = {
    "Authorization": "Bearer YOUR_OAIRoute_KEY",
    "Content-Type": "application/json",
}
payload = {
  "model": "happyhorse-1.1",
  "prompt": "人物缓缓抬头，雨滴从伞沿滑落",
  "first_frame_image": "https://example.com/umbrella.png",
  "resolution": "1080P",
  "duration": 8
}
res = requests.post(url, headers=headers, json=payload)
print(res.json())
```
**图生视频{Image to video}::JavaScript**
```
const res = await fetch("https://api.oairoute.com/v1/videos", {
  method: "POST",
  headers: {
    Authorization: "Bearer YOUR_OAIRoute_KEY",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
  "model": "happyhorse-1.1",
  "prompt": "人物缓缓抬头，雨滴从伞沿滑落",
  "first_frame_image": "https://example.com/umbrella.png",
  "resolution": "1080P",
  "duration": 8
}),
});
console.log(await res.json());
```
**200 图生视频{Image to video}**
```
{
  "code": 200,
  "data": [
    {
      "status": "submitted",
      "task_id": "task_01K8SGYNNNVBQTXNR4MM964S7K"
    }
  ]
}
```
**参考生视频{Reference to video}::cURL**
```
curl --request POST \
  --url 'https://api.oairoute.com/v1/videos' \
  --header 'Authorization: Bearer YOUR_OAIRoute_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "happyhorse-1.1",
  "prompt": "参考图中的角色站在雪原上，风吹起披风",
  "image_urls": [
    "https://example.com/char-1.png",
    "https://example.com/char-2.png"
  ],
  "resolution": "1080P",
  "duration": 8
}'
```
**参考生视频{Reference to video}::Python**
```
import requests
url = "https://api.oairoute.com/v1/videos"
headers = {
    "Authorization": "Bearer YOUR_OAIRoute_KEY",
    "Content-Type": "application/json",
}
payload = {
  "model": "happyhorse-1.1",
  "prompt": "参考图中的角色站在雪原上，风吹起披风",
  "image_urls": [
    "https://example.com/char-1.png",
    "https://example.com/char-2.png"
  ],
  "resolution": "1080P",
  "duration": 8
}
res = requests.post(url, headers=headers, json=payload)
print(res.json())
```
**参考生视频{Reference to video}::JavaScript**
```
const res = await fetch("https://api.oairoute.com/v1/videos", {
  method: "POST",
  headers: {
    Authorization: "Bearer YOUR_OAIRoute_KEY",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
  "model": "happyhorse-1.1",
  "prompt": "参考图中的角色站在雪原上，风吹起披风",
  "image_urls": [
    "https://example.com/char-1.png",
    "https://example.com/char-2.png"
  ],
  "resolution": "1080P",
  "duration": 8
}),
});
console.log(await res.json());
```
**200 参考生视频{Reference to video}**
```
{
  "code": 200,
  "data": [
    {
      "status": "submitted",
      "task_id": "task_01K8SGYNNNVBQTXNR4MM964S7K"
    }
  ]
}
```
