> ## 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.

# HappyWan API：生成最長 45 秒的影片

> 使用 HappyWan API，透過文字、關鍵影格或影像、影片及音訊參考素材，產生最長 45 秒的 480p 或 720p 影片。

## 概覽

HappyWan 可產生 4 至 45 秒的 480p 或 720p 影片。你可以依文字描述產生場景、用首尾影格產生動態畫面，也可以混用不同類型的參考素材來引導影片生成。啟用聲音後，可產生與畫面同步的對白、音效或音樂。

| 設定 | 值 |
| - | - |
| 模型 ID | `happywan` |
| Base URL | `https://api.apixo.ai/api/v1` |

## 端點與身分驗證

每次請求都須傳送 `Authorization: Bearer YOUR_API_KEY`。建立任務時還須傳送 `Content-Type: application/json`。

| 方法 | 端點 | 用途 |
| - | - | - |
| `POST` | `/generateTask/happywan` | 送出影片生成任務 |
| `GET` | `/statusTask/happywan?taskId={taskId}` | 查詢狀態並取得結果 |

## 產生影片

### 文生影片

這個請求會產生一段 45 秒的影片，音訊與畫面同步。

```bash theme={null}
curl -X POST "https://api.apixo.ai/api/v1/generateTask/happywan" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "request_type": "async",
    "input": {
      "mode": "text-to-video",
      "prompt": "First 15 seconds: follow a cyclist in a yellow raincoat along a wet riverside path. Next 15 seconds: show the cyclist ringing the bell on a bridge. Final 15 seconds: pull back to reveal the bridge lights reflected in the river. Include light rain and a clear bell ring.",
      "resolution": "720p",
      "aspect_ratio": "16:9",
      "duration": 45,
      "sound": true
    }
  }'
```

### 首尾影格

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "first_and_last_frames",
    "prompt": "Move smoothly from the street-level view to the wide skyline.",
    "image_urls": ["https://example.com/first-frame.jpg", "https://example.com/last-frame.jpg"],
    "duration": 8,
    "aspect_ratio": "auto"
  }
}
```

### 多模態參考

```json theme={null}
{
  "request_type": "callback",
  "callback_url": "https://example.com/webhooks/apixo",
  "input": {
    "mode": "omni_reference",
    "prompt": "Keep the product from the image recognizable, follow the camera movement in the video, and time the reveal to the audio cue.",
    "image_urls": ["https://example.com/product.jpg"],
    "video_urls": ["https://example.com/camera-movement.mp4"],
    "audio_urls": ["https://example.com/reveal-cue.mp3"],
    "duration": 12,
    "resolution": "480p"
  }
}
```

## 參數

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

結果傳送方式。`async` 表示透過輪詢取得結果，`callback` 表示透過 Webhook 接收結果。

**callback\_url** `string`

用於接收任務最終資料的公開 HTTPS URL。`request_type` 為 `callback` 時必填。

**input** `object` *required*

HappyWan 的生成參數。

**屬性**

**mode** `string` *required*

生成模式。可用值為 `text-to-video`、`first_and_last_frames`、`omni_reference`。

**prompt** `string` *required*

描述所需影片的文字，不可為空，最多 10,000 個字元。

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

輸出影片的長度，單位為秒。請填入 4 到 45 之間的整數，含端點。

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

輸出解析度。可用值為 `480p`、`720p`。

**aspect\_ratio** `string` (default: auto)

輸出長寬比。支援 `auto`、`16:9`、`4:3`、`1:1`、`3:4`、`9:16` 和 `21:9`。在 `first_and_last_frames` 模式下，設為 `auto` 或省略此欄位。

**sound** `boolean` (default: true)

設為 `false` 可產生無聲影片。

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

設為 `true` 可加入可見水印。

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

可公開存取的影像 URL。在 `first_and_last_frames` 模式下，可提供一張起始影格，或依首格至尾格順序提供兩張影像；在 `omni_reference` 模式下，最多提供 10 張參考影像。

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

在 `omni_reference` 模式下，最多提供五個可公開存取的參考影片 URL。每段參考影片長度須為 2 至 30 秒，所有參考影片總長度不得超過 30 秒。

**audio\_urls** `string[]`

在 `omni_reference` 模式下，最多提供五個可公開存取的參考音訊 URL。每段參考音訊長度須為 2 至 30 秒，所有參考音訊總長度不得超過 30 秒。提供音訊時，必須同時提供至少一張參考影像或一段參考影片。

### 各模式的輸入要求

| 模式 | 需求 |
| - | - |
| `text-to-video` | 提供提示詞，並省略媒體欄位。 |
| `first_and_last_frames` | 提供提示詞，並在 `image_urls` 中填入一個或兩個 URL。`aspect_ratio` 設為 `auto` 或省略該欄位。 |
| `omni_reference` | 提供提示詞，並在 `image_urls` 或 `video_urls` 中至少填入一個 URL。可搭配 `audio_urls` 來引導聲音生成。 |

## 耗時與輪詢

建立任務後會傳回 `data.taskId`。使用此 ID 呼叫狀態查詢端點。

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

| 結果傳送方式 | 如何取得結果 |
| - | - |
| 輪詢 | `data.state` 為 `pending` 或 `processing` 時繼續輪詢。狀態為 `success` 時，將 `data.resultJson` 解析為 JSON，從 `resultUrls` 讀取影片 URL。狀態為 `failed` 時，讀取 `data.failCode` 和 `data.failMsg`。 |
| Webhook | 將 `request_type` 設為 `callback`，並提供 `callback_url`，以接收任務的最終資料。 |

較長的影片或參考素材較多的請求可能需要更多時間。使用回呼模式可在任務完成時收到結果。結果 URL 為暫時連結。如需保留，請下載 MP4 檔案。共用的任務生命週期與結果格式請見 [查詢任務狀態](https://apixo.ai/docs/zh-hant/api-reference/status-task.md) 和 [Webhook](https://apixo.ai/docs/zh-hant/api-reference/webhooks.md)。

## 計費

每秒費用取決於解析度及請求是否包含參考影片。費率請見 [API 定價](https://apixo.ai/pricing/api)，每次請求的總費用進位方式請見[點數換算與進位](https://apixo.ai/docs/zh-hant/pricing.md#credit-conversion-and-rounding)。

## MCP 整合

[模型 Schema](https://apixo.ai/docs/models/schemas/video/happywan.json) 在 `mcp.result` 中定義影片結果的解碼方式，並在 `mcp.attachments` 中定義 `image_urls`、`video_urls` 和 `audio_urls` 的有序附件繫結。請保留影格圖片的順序。


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