> ## 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/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/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，并从 `resultUrls` 中获取 MP4 URL；失败时，读取 `data.failCode` 和 `data.failMsg`。详情请参见 [状态任务](https://apixo.ai/docs/zh/api-reference/status-task.md) 和 [错误代码](https://apixo.ai/docs/zh/api-reference/errors.md) 中的公共响应字段。

## 计费

所有三种模式的标准价格为每请求输出秒 **\$0.080**。宽高比、声音设置和参考媒体使速率保持不变。按标准费率，4 秒请求的费用为 **\$0.32**。有关当前费率，请参阅 [API 定价](https://apixo.ai/pricing/api)。

## MCP 集成

[模型 schema](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.