> ## Documentation Index
> Fetch the complete documentation index at: https://apixo.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# HappyHorse API：视频生成与编辑

> 阿里巴巴 HappyHorse 视频生成和编辑 API，用于文本、图像、参考和视频编辑工作流程

## 概览

要编辑素材，请使用 [视频编辑请求](#video-edit) 并指定模型 ID `happyHorse`。在 `video_urls` 中提供一个源剪辑，并在 `prompt` 中描述更改。例如，以下请求更改视觉样式，并使用 `audio_setting: "origin"` 保留原始音频。对于此操作，参考图像可选。

从静止开始？使用 [图像转视频](#image-to-video) 功能并提供一张源图像。

| 功能 | 值 |
| - | - |
| 模型 ID | `happyHorse` |
| 模式 | `text-to-video`, `image-to-video`, `reference-to-video`, `video-edit` |
| 提示词 | `text-to-video`、`reference-to-video` 和 `video-edit` 必需；`image-to-video` 可选 |
| 提示词长度 | 最多 2500 个字符 |
| 输入图像 | Exactly 1 URL 为 `image-to-video`；1-9 个 `reference-to-video` 的 URL；0-5 个 `video-edit` 的可选参考图像 URL |
| 输入视频 | 恰好 1 URL 为 `video-edit` |
| 纵横比 | `16:9`、`9:16`、`1:1`、`4:3`、`3:4` 用于 `text-to-video` 和 `reference-to-video` |
| 分辨率档位 | `720p`, `1080p` |
| 时长 | 3-15 秒（`text-to-video`、`image-to-video` 和 `reference-to-video`） |

HappyHorse 默认输出带音频的视频。公共 API 不提供完全禁用生成音频的开关。对于 `video-edit`，可通过 `audio_setting` 选择自动音频行为或保留原始输入音频。

## 接口与身份验证

API 基础地址：

```text theme={null}
https://api.apixo.ai/api/v1
```

| 方法 | 端点 | 用途 |
| - | - | - |
| `POST` | `/generateTask/happyHorse` | 提交生成或编辑任务 |
| `GET` | `/statusTask/happyHorse?taskId={taskId}` | 查询任务状态并获取结果 |

每个请求都必须携带 APIXO API 密钥：

```http theme={null}
Authorization: Bearer YOUR_API_KEY
```

提交任务时，还需要设置以下请求头：

```http theme={null}
Content-Type: application/json
```

## 异步请求示例

以下示例提交一个最简单的文生视频任务，响应中会返回 `taskId`。

```bash theme={null}
curl -X POST "https://api.apixo.ai/api/v1/generateTask/happyHorse" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "request_type": "async",
    "input": {
      "mode": "text-to-video",
      "prompt": "a cinematic rainy night in tokyo, slow dolly shot, reflective streets",
      "resolution": "720p",
      "ratio": "16:9",
      "duration": 5
    }
  }'
```

成功响应：

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678"
  }
}
```

保存 `taskId`；您需要它来轮询最终视频

## 轮询结果

```bash theme={null}
curl -X GET "https://api.apixo.ai/api/v1/statusTask/happyHorse?taskId=task_12345678" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

任务处理中的响应示例：

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "state": "processing",
    "createTime": 1767965610929
  }
}
```

成功响应：

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "state": "success",
    "resultJson": "{\"resultUrls\":[\"https://file.apixo.ai/video.mp4\"]}",
    "createTime": 1767965610929,
    "completeTime": 1767965652317,
    "costTime": 41388
  }
}
```

任务失败时的响应示例：

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "state": "failed",
    "failCode": "PromptInvalid",
    "failMsg": "Prompt is invalid or rejected",
    "createTime": 1767965610929,
    "completeTime": 1767965620132
  }
}
```

等 `state` 变为 `success` 后，再解析 `resultJson`：

```javascript theme={null}
const payload = JSON.parse(data.resultJson);
const videoUrls = payload.resultUrls;
```

## 请求体

### 文生视频

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "text-to-video",
    "prompt": "a cinematic rainy night in tokyo, slow dolly shot, reflective streets",
    "resolution": "1080p",
    "ratio": "16:9",
    "duration": 5,
    "watermark": false
  }
}
```

### 图生视频

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "image-to-video",
    "image_urls": [
      "https://example.com/first-frame.png"
    ],
    "prompt": "animate the scene with a gentle camera move",
    "resolution": "720p",
    "duration": 5,
    "watermark": false
  }
}
```

### 参考生成视频

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "reference-to-video",
    "prompt": "keep the character style consistent across all references",
    "image_urls": [
      "https://example.com/ref-1.png",
      "https://example.com/ref-2.png"
    ],
    "resolution": "1080p",
    "ratio": "16:9",
    "duration": 6,
    "watermark": false
  }
}
```

### 视频编辑

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "video-edit",
    "video_urls": [
      "https://example.com/input.mp4"
    ],
    "image_urls": [
      "https://example.com/reference.png"
    ],
    "prompt": "change the scene to watercolor style",
    "resolution": "1080p",
    "audio_setting": "origin",
    "watermark": false
  }
}
```

## 参数

**request\_type** `string` *required* (default: async)

结果获取方式。选择 `async` 时，通过 `statusTask` 轮询结果；选择 `callback` 时，通过 Webhook 接收结果。

**callback\_url** `string`

当 `request_type` 为 `callback` 时必填。请提供公网可访问的 HTTPS 地址，用于接收任务的最终结果。详见 [Webhook](https://apixo.ai/docs/zh/api-reference/webhooks.md)。

**input** `object` *required*

HappyHorse 的输入参数。

**属性**

**mode** `string` *required*

生成模式。可选值为 `text-to-video`、`image-to-video`、`reference-to-video`、`video-edit`。

**prompt** `string`

描述视频或编辑的文本提示。`text-to-video`、`reference-to-video` 和 `video-edit` 必需；`image-to-video` 可选。修剪后必填提示不能为空。最多 2500 个字符。

**image\_urls** `string[]`

可公开访问的图像 URL。需要恰好 1 个 URL 用于 `image-to-video`；需要 1-9 个 URL 用于 `reference-to-video`；可选 0-5 个参考图像 URL 用于 `video-edit`。所有模式均支持 JPEG、JPG、PNG 或 WEBP 图像，单文件大小不超过 20 MB。每张图像的长边和宽边均需至少 300 px。在 `reference-to-video` 模式下，长边和宽边至少为 400 px。

**video\_urls** `string[]`

公共视频 URL。`video-edit` 模式下必需，且必须恰好包含 1 个 URL。视频格式必须为 MP4 或 MOV，时长 3-60 秒，帧率 8-60 fps，文件大小不超过 100 MB，分辨率每边在 360 至 4096 像素之间，宽高比需在 0.4 到 2.5 之间。

**resolution** `string` (default: 1080p)

输出分辨率档位。可选值为 `720p`、`1080p`。

**ratio** `string` (default: 16:9)

`text-to-video` 和 `reference-to-video` 的输出纵横比。支持的值：`16:9`、`9:16`、`1:1`、`4:3`、`3:4`。

**duration** `integer` (default: 5)

`text-to-video`、`image-to-video` 和 `reference-to-video` 的输出持续时间（以秒为单位）。支持从 3 到 15 的整数。`video-edit` 被忽略。

**audio\_setting** `string` (default: auto)

仅 `video-edit`。支持的值：`auto`、`origin`。当您想要保留原始输入音频时，请使用 `origin`。

**watermark** `boolean` (default: false)

是否添加水印。

**seed** `integer`

可选的随机种子。支持从 0 到 2147483647 的整数。如果省略，则会自动生成随机种子。

**nsfw\_checker** `boolean` (default: false)

设为 `true` 可在支持的生成路由上启用上游内容审核。API 默认值为 `false`。

## 响应格式

### 提交任务时的响应

任务受理后，`POST /generateTask/happyHorse` 会返回任务 ID：

**code** `integer`

API 状态码。`200` 表示任务已受理。

**message** `string`

状态说明。

**data.taskId** `string`

任务的唯一 ID，用于查询任务状态。

### 状态响应字段

**taskId** `string`

任务的唯一标识符。

**state** `string`

当前任务状态，可能的值为 `processing`、`success`、`failed`。

**resultJson** `string`

当 `state` 为 `success` 时返回。解析此 JSON 字符串后，可从 `resultUrls` 读取生成的视频链接。

**failCode** `string`

供程序处理的错误码，仅在 `state` 为 `failed` 时返回。

**failMsg** `string`

失败原因说明，仅在 `state` 为 `failed` 时返回。

**createTime** `integer`

任务创建时的 Unix 时间戳，单位为毫秒。

**completeTime** `integer`

任务完成时的 Unix 时间戳，单位为毫秒。任务完成后返回。

**costTime** `integer`

处理耗时，单位为毫秒。任务成功后，如有该数据便会返回。

## Webhook 回调模式

如果希望服务端自动收到最终结果，可以使用回调模式，无需轮询。

```bash theme={null}
curl -X POST "https://api.apixo.ai/api/v1/generateTask/happyHorse" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "request_type": "callback",
    "callback_url": "https://your-server.com/webhooks/apixo",
    "input": {
      "mode": "video-edit",
      "video_urls": [
        "https://example.com/input.mp4"
      ],
      "image_urls": [
        "https://example.com/reference.png"
      ],
      "prompt": "change the scene to watercolor style",
      "resolution": "1080p",
      "audio_setting": "origin",
      "watermark": false
    }
  }'
```

Webhook 接收要求和重试规则见 [Webhook 文档](https://apixo.ai/docs/zh/api-reference/webhooks.md)。

## 计费

新提交的非 LLM 请求按 **1 积分 = `$0.001`** 计费。先按用量和附加项目计算总额，再应用账号折扣，最后将请求总额向上取整到整数积分。如果约定了固定单价，则按该单价的原始精度计算，不再使用标准价或另行打折；最终积分仍向上取整。详见[积分换算与取整](https://apixo.ai/docs/zh/pricing.md#credit-conversion-and-rounding)。

HappyHorse 按秒计费。所选的`resolution`决定单价。

| 分辨率 | APIXO 官方价格 | 市场参考价 |
| - | - | - |
| `720p` | `$0.125 / second` | `$0.1625 / second` |
| `1080p` | `$0.225 / second` | `$0.2875 / second` |

计费公式：

| 模式 | 公式 |
| - | - |
| `text-to-video` | `duration * unitPrice` |
| `image-to-video` | `duration * unitPrice` |
| `reference-to-video` | `duration * unitPrice` |
| `video-edit` | `(input video seconds + output video seconds) * unitPrice` |

对于`video-edit`，计费时长由输入视频确定；`duration` 参数被忽略。计费使用输入视频秒数加上生成的输出视频秒数；APIXO 将计费输入端限制为 15 秒，并且生成的输出端在相同的上限持续时间内计费。

最新的美元费率见 [API 价目表](https://apixo.ai/pricing/api)。

## 延迟与轮询

HappyHorse 任务是异步的。后端不强制执行固定的公共延迟 SLA；实际时间因模式、分辨率、持续时间、提示复杂性、媒体获取速度和队列负载而异。

| 工作流程 | 什么影响延迟 | 建议首次查询时间 | 轮询间隔 |
| - | - | - | - |
| `text-to-video` | 分辨率、持续时间、提示复杂性、队列负载 | 任务创建 30 秒后 | 10s |
| `image-to-video` | 图像获取时间、分辨率、持续时间、队列负载 | 任务创建 30 秒后 | 10s |
| `reference-to-video` | 引用数量、分辨率、持续时间、队列负载 | 任务创建 45 秒后 | 10s-15s |
| `video-edit` | 输入视频获取/探测时间、输入持续时间、引用、队列负载 | 任务创建 60 秒后 | 10s-15s |

> [!TIP]
>
> 对于生产工作负载，请使用回调模式以避免频繁轮询长时间运行的视频作业。

请求频率和并发上限因账号、API 密钥和路由而异。收到 `429` 时，请降低请求频率，逐步延长重试间隔。账号级限制见[系统 API](https://apixo.ai/docs/zh/api-reference/system.md)。

## 错误与排查

### HTTP 错误

| 代码 | 含义 | 处理方式 |
| - | - | - |
| `400` | 请求体、模式、参数、媒体 URL 形状或请求被拒绝 | 在重试前修复请求 |
| `401` | 缺少 API 密钥，或密钥无效 | 检查 `Authorization` 请求头 |
| `402` | 余额或配额不足 | 充值或更换账号或API密钥 |
| `403` | 密钥或路由无权访问该模型 | 检查权限和路由策略 |
| `429` | 已达到速率或并发限制 | 按指数退避策略重试 |
| `500` | 服务器错误 | 逐步延长间隔后重试 |
| `502` | 服务错误 | 逐步延长间隔后重试 |
| `504` | 服务超时 | 重试；耗时较长的任务可改用回调模式 |

### 任务失败错误码

| 错误码 | 含义 | 处理方式 |
| - | - | - |
| `PromptInvalid` | 提示词无效或被拒绝 | 使用更清晰、策略安全的说明重写提示 |
| `SensitiveContent` / `SensitiveContentDetected` | 提示、输入媒体或输出未通过安全检查 | 更改提示或媒体 |
| `MissingParameter` / `BadRequest` | 缺少或格式错误的必需模式特定字段 | 检查`mode`、`prompt`、`image_urls`、`video_urls`、`resolution`、`ratio`和`duration` |
| `RateLimited` / `RateLimitExceeded` | 请求频率达到上限 | 按指数退避策略重试 |
| `Timeout` / `Task TimeOut` | 任务超时 | 重试、降低输入复杂度或使用回调模式 |
| `Unknown error` | 任务因未知原因失败 | 逐步延长间隔后重试，或联系支持团队并提供 `taskId` |

### 故障排除提示

* 对 `image_urls` 和 `video_urls` 使用公共、直接、可获取的 URL。
* 对于 `image-to-video`，需发送 exactly 一个图像 URL。
* 对于 `reference-to-video`，需发送 1-9 个图像 URL 并提供非空提示。
* 对于 `video-edit`，需发送 exactly 一个视频 URL；可选参考图像最多 5 张。
* `ratio` 仅能与 `text-to-video` 和 `reference-to-video` 一起使用。
* `duration` 仅能与 `text-to-video`、`image-to-video` 和 `reference-to-video` 一起使用；`video-edit` 的持续时间根据输入视频确定，并按输入视频秒数加上输出视频秒数计费。
* 如果您的应用程序需要长期访问结果，请及时存储结果 URL。

完整列表见[错误码](https://apixo.ai/docs/zh/api-reference/errors.md)。

## MCP 集成

[完整模型 Schema](https://apixo.ai/docs/models/schemas/video/happyhorse.json) 中的 `mcp.result` 指定了结果的解析方式，`mcp.attachments` 列出支持绑定文件的字段。这些元数据供客户端集成使用，无需作为生成参数提交。附件字段为 `image_urls`, `video_urls`。请保留用户指定的文件顺序。API 负责校验模型参数。

## 相关链接

* [生成 API 概览](https://apixo.ai/docs/zh/models.md)
* [视频模型](https://apixo.ai/docs/zh/models/video)
* [提交生成任务](https://apixo.ai/docs/zh/api-reference/generate-task.md)
* [查询任务状态](https://apixo.ai/docs/zh/api-reference/status-task.md)
* [Webhook](https://apixo.ai/docs/zh/api-reference/webhooks.md)
* [错误码](https://apixo.ai/docs/zh/api-reference/errors.md)
* [参数规范](https://apixo.ai/docs/zh/api-reference/parameters.md)
* [路由策略](https://apixo.ai/docs/zh/concepts/routing-strategies.md)
* [在 APIXO Playground 中尝试 HappyHorse](https://apixo.ai/models/happyhorse)
* [API定价](https://apixo.ai/pricing/api)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.