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

# MAGI-2 API：使用文字、圖片或參考素材生成影片

> 從文字、關鍵影格或多模式參考產生 4–30 秒的 MAGI-2 影片，支援選用的同步音訊與依賴寬高比的輸出尺寸。

## 概覽

使用模型 ID `magi-2` 從提示、帶有可選最後一影格的第一影格，或帶有可選影像、影片和音訊參考的提示生成影片。

### 輸出尺寸

`1080p` 為輸出等級，實際像素尺寸取決於 `aspect_ratio`。

| 縱橫比 | 驗證輸出（寬×高） |
| - | - |
| `16:9` | 1920 × 1080 像素 |
| `1:1` | 1440 × 1440 像素 |

明確設定 `aspect_ratio` 以控製畫面比例。若未指定，文生影片與參考至影片將使用 `16:9`，圖生影片則使用與第一影格最接近的支援比例。

## 端點和身分驗證

API 基底網址：

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

| 方法 | 端點 | 用途 |
| - | - | - |
| POST | `/generateTask/magi-2` | 送出生成任務 |
| GET | `/statusTask/magi-2?taskId={taskId}` | 檢索任務狀態和結果 |

兩種請求都要在請求頭中加入 `Authorization: Bearer YOUR_API_KEY`。傳送 POST 請求主體時，還要設定 `Content-Type: application/json`。

## 請求範例

### 文生影片

```bash theme={null}
curl -X POST "https://api.apixo.ai/api/v1/generateTask/magi-2" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "request_type": "async",
    "input": {
      "mode": "text-to-video",
      "prompt": "A slow push through an evening market, with rain and quiet footsteps.",
      "duration": 5,
      "aspect_ratio": "16:9"
    }
  }'
```

### 圖生影片

此範例請求方形輸出，並使用第一影格和最後一影格；若要為單一影像產生動畫，僅需傳遞第一個 URL。

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "image-to-video",
    "duration": 4,
    "aspect_ratio": "1:1",
    "image_urls": ["https://example.com/first.jpg", "https://example.com/last.jpg"],
    "sound": false
  }
}
```

### 參考生成影片

```json theme={null}
{
  "request_type": "callback",
  "callback_url": "https://example.com/webhook",
  "input": {
    "mode": "reference-to-video",
    "prompt": "Keep the product design from the reference image as the camera circles it. Use the audio reference to guide the soundtrack.",
    "duration": 8,
    "image_urls": ["https://example.com/product.png"],
    "audio_urls": ["https://example.com/music.wav"]
  }
}
```

## 參數

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

支援的值：`async`、`callback`。使用 `async` 時，輪詢直到 `data.state` 為 `success` 或 `failed`；使用 `callback` 時，讀取最終的 Webhook 負載。成功時，將 `data.resultJson` 解析為 JSON 並讀取 `resultUrls`；失敗時，讀取 `data.failCode` 與 `data.failMsg`。

**callback\_url** `string`

當 `request_type` 為 `callback` 時必須提供。請使用可接收最終任務負載的公開 HTTPS URL。詳情請見 [Webhooks](https://apixo.ai/docs/zh-hant/api-reference/webhooks.md)。

**input** `object` *required*

MAGI-2 生成參數

**屬性**

**mode** `string` *required*

可用值為 `text-to-video`、`image-to-video`、`reference-to-video`。

**prompt** `string`

文字轉影片與引用轉影片需提供非空白提示，圖像轉影片為可選。最大長度為 15,000 個字元。

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

請求的輸出持續時間（以整秒為單位），範圍為 `4` 至 `30`，支援數字字串。

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

支援的值：`1080p`。這是輸出層。像素尺寸取決於 `aspect_ratio`。驗證範例包含 `16:9` 在 1920 × 1080 與 `1:1` 在 1440 × 1440。

**aspect\_ratio** `string`

輸出分影格。支援的值為：`21:9`、`16:9`、`4:3`、`1:1`、`3:4`、`9:16`。文生影片與參考到影片預設為 `16:9`；圖生影片則預設為與第一影格最接近的支援比例。

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

使用 `true` 產生同步音訊；使用 `false` 則生成無聲影片。

**seed** `integer|string`

可選的整數，範圍為 `0` 至 `2147483647`，支援數字字串。

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

公開的 HTTP(S) 影像 URL。圖生影片需提供索引 0 的第一影格，並可選提供索引 1 的最後一影格；參考到影片最多可提供 10 個可選的參考影像。

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

最多支援 5 個公開的 HTTP(S) 參考影片 URL，用於參考影片。建議使用長度為 2 至 30 秒的片段，總影片長度不超過 30 秒；若輸入過長，將自動修剪。

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

最多 5 個公用 HTTP(S) 個參考音訊 URL，用於引用影片。使用 2–30 秒的剪輯，組合音訊持續時間最長為 30 秒。較長的輸入可能會被修剪。

在任務運行時保持媒體 URL 可存取。可以裁剪第一影格以適合所選的輸出比率。

## 任務狀態和結果

建立回應傳回`data.taskId`。

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

對於非同步請求，使用 ID 呼叫狀態端點並繼續輪詢，直到 `data.state` 為 `success` 或 `failed`。對於回呼請求，從最終的 [webhook 負載](https://apixo.ai/docs/zh-hant/api-reference/webhooks.md) 中讀取相同的結果欄位。

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "YOUR_TASK_ID",
    "state": "success",
    "resultJson": "{\"resultUrls\":[\"https://example.com/output.mp4\"]}"
  }
}
```

成功後，解析 `data.resultJson` 作為 JSON 並閱讀 MP4 網址來自 `resultUrls`。失敗時，請閱讀 `data.failCode` 和 `data.failMsg`。見 [狀態任務](https://apixo.ai/docs/zh-hant/api-reference/status-task.md) 和 [錯誤代碼](https://apixo.ai/docs/zh-hant/api-reference/errors.md) 關於共用回應欄位。

## 計費

所有三種模式的標準價格為每請求輸出秒 **\$0.080**。寬高比、聲音設定和參考媒體不會影響速率。以標準費率，4 秒請求的費用為 **\$0.32**。有關當前費率，請參閱 [API 定價](https://apixo.ai/pricing/api)。

## MCP 整合

[模型架構](https://apixo.ai/docs/models/schemas/video/magi-2.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.