# MAGI-2 官方原生与 Ark 兼容协议说明

若客户端已集成 Sand.ai 官方接口或火山方舟（Ark）SDK，直接将 Base URL 指向本平台并替换 API 密钥即可调用。[Sand.ai 官方文档](https://platform.sand.ai/docs/get-started)

> [!NOTE]
> 示例中的模型 ID 仅供参考，实际调用请以 [模型广场](/models) 对应的真实 ID 为准。

### 1. 官方路由端点
* **原生提交 / 轮询**：`POST /v2/generations` · `GET /v2/generations/{id}`
* **Ark 兼容提交 / 轮询**：`POST /compatible/ark/api/v3/contents/generations/tasks` · `GET /compatible/ark/api/v3/contents/generations/tasks/{id}`
* **鉴权头部**：`Authorization: Bearer sk-your_token_here`

### 2. 状态值与关键约束
* **原生状态（`/v2/generations/{id}`）**：`queued`、`processing`、`succeeded`（成片位于 `output.videoUrl`）、`failed`、`canceled`。
* **Ark 状态（`/compatible/ark/.../{id}`）**：`queued`、`running`、`succeeded`（成片位于 `content.video_url`）、`failed`、`cancelled`、`expired`。
* **规格约束**：固定 `1080p`，时长 `4`–`30` 秒整数，默认开启音频，参考素材须为公网 `https://` 直链；禁传 `watermark` 及非兼容扩展字段；查询成功均返回免鉴权直链。

### 3. 调用示例

#### A. Sand.ai 原生多模态参考 (`POST /v2/generations`)
```bash
curl -X POST https://www.roookey.com/v2/generations \
  -H "Authorization: Bearer sk-your_token_here" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "magi-2",
    "parts": [
      { "type": "text", "text": "穿红衣的舞者在古巷石板路上起舞，配合背景古琴声" },
      { "type": "reference_image", "image": { "url": "https://example.com/dancer.png" } },
      { "type": "reference_audio", "audio": { "url": "https://example.com/guqin.mp3" } }
    ],
    "duration": 6,
    "aspectRatio": "16:9",
    "generateAudio": true
  }'
```

#### B. Ark 兼容首尾帧 (`POST /compatible/ark/api/v3/contents/generations/tasks`)
```bash
curl -X POST https://www.roookey.com/compatible/ark/api/v3/contents/generations/tasks \
  -H "Authorization: Bearer sk-your_token_here" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "magi-2",
    "content": [
      { "type": "text", "text": "薄雾散去，镜头平滑过渡至阳光下的湖面" },
      { "type": "image_url", "image_url": { "url": "https://example.com/start.png" }, "role": "first_frame" },
      { "type": "image_url", "image_url": { "url": "https://example.com/end.png" }, "role": "last_frame" }
    ],
    "duration": 5,
    "ratio": "16:9"
  }'
```

> [!TIP]
> 使用 Ark 官方 SDK 时，将 `base_url` 设为 `https://www.roookey.com/compatible/ark/api/v3` 即可；轮询直接 `GET /v2/generations/{id}` 或 `/compatible/ark/api/v3/contents/generations/tasks/{id}`。
