> ## 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 個字元 |
| 輸入影像 | 恰好 1 個 URL 用於 `image-to-video`；1 至 9 個 URL 用於 `reference-to-video`；0 至 5 個可選的參考圖片 URL 用於 `video-edit` |
| 輸入影片 | 確切地 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-hant/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。`image-to-video` 必需且須 exactly 1 個 URL；`reference-to-video` 必需且須 1-9 個 URL；`video-edit` 可選，最多 0-5 個參考影像 URL。所有模式均支援 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-hant/api-reference/webhooks.md)。

## 計費

新提交的非 LLM 請求按 **1 點 = `$0.001`** 計費。先依用量和加購項目計算總額，再套用帳戶折扣，最後將請求總額無條件進位至整數點數。若已約定固定單價，則保留該單價的精度，不再使用標準價或另行打折；最終點數仍須進位。詳見[積分換算與進位](https://apixo.ai/docs/zh-hant/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-hant/api-reference/system.md)。

## 錯誤與排查

### HTTP 錯誤

| 代碼 | 含義 | 處理方式 |
| - | - | - |
| `400` | 請求主體、模式、參數、媒體 URL 形狀或請求拒絕無效 | 修正請求後再試 |
| `401` | 缺少 API 金鑰，或金鑰無效 | 檢查 `Authorization` 請求標頭 |
| `402` | 餘額或配額不足 | 充值或更換帳號或金鑰 |
| `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`，僅傳送一張影像 URL。
* 對於 `reference-to-video`，發送 1-9 影像 URL 並包含非空提示。
* 對於 `video-edit`，僅發送一個影片 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-hant/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-hant/models.md)
* [影片模型](https://apixo.ai/docs/zh-hant/models/video)
* [送出生成任務](https://apixo.ai/docs/zh-hant/api-reference/generate-task.md)
* [查詢任務狀態](https://apixo.ai/docs/zh-hant/api-reference/status-task.md)
* [Webhook](https://apixo.ai/docs/zh-hant/api-reference/webhooks.md)
* [錯誤碼](https://apixo.ai/docs/zh-hant/api-reference/errors.md)
* [參數規範](https://apixo.ai/docs/zh-hant/api-reference/parameters.md)
* [路由策略](https://apixo.ai/docs/zh-hant/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.