> ## Documentation Index
> Fetch the complete documentation index at: https://docs.poyo.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# MAGI-2

> MAGI-2 API 可根据文本、首尾帧，或图片、视频和音频参考，生成 4–30 秒、带同步音频的 1080p 视频。

> [!TIP]
>
> 1. 提交后会返回 `task_id`。如果提供了 `callback_url`，当任务状态变为 `finished` 或 `failed` 时，系统会向 `callback_url` 发送 POST 请求。
> 2. 无论是否提供 `callback_url`，都可以通过统一的[查询任务状态](https://docs.poyo.ai/zh/api-manual/task-management/status.md)接口获取结果。

MAGI-2 是 Sand AI 的视频生成模型，一次可生成最长 30 秒的 1080p 视频，对白、音效和环境声与画面同步生成。适合需要长镜头、人物台词和角色一致性的短剧、广告、产品展示和社交短视频。

## 模型

* **magi-2** - 文生视频、首尾帧生成和多模态参考生视频，同步生成音频

## 功能

* 单次生成 4 到 30 秒的 1080p 视频
* 同步生成对白、音效和环境声
* 六种宽高比：16:9、9:16、1:1、4:3、3:4 和 21:9
* 支持首帧控制，以及首帧加尾帧控制
* 单个任务最多传入 10 张参考图片、5 个参考视频和 5 段参考音频
* 提示词最多 15,000 个字符，可写详细的剧本和分镜

## 输入模式

* **文生视频**：在 `prompt` 中描述场景、动作、镜头和声音。
* **首尾帧**：在 `image_urls` 中传入一张图片作为起始帧，或传入两张图片分别作为起始帧和结束帧。视频沿用首帧的宽高比。
* **参考生视频**：任意组合 `reference_image_urls`、`reference_video_urls` 和 `reference_audio_urls`，也可以只传参考音频，并在 `prompt` 中说明每个参考的用法。

## 必填参数

* `prompt` (string)：场景、主体、动作、镜头和声音，最多 15,000 个字符。台词放在引号里。

## 可选参数

* `duration` (integer)：时长，整数秒，`4` 到 `30`。默认 `5`。
* `resolution` (string)：`1080p`。
* `aspect_ratio` (string)：文生视频和参考生视频使用 `16:9`（默认）、`9:16`、`1:1`、`4:3`、`3:4` 或 `21:9`；首尾帧使用 `auto`。
* `image_urls` (string\[])：一到两张图片：起始帧和可选的结束帧。支持 JPG、PNG、WEBP。
* `reference_image_urls` (string\[])：最多 10 张参考图片。
* `reference_video_urls` (string\[])：最多 5 个 MP4 或 MOV 视频，每段 2–30 秒，合计最多 30 秒。
* `reference_audio_urls` (string\[])：最多 5 段 MP3 或 WAV 音频，每段 2–30 秒，合计最多 30 秒。
* `generate_audio` (boolean)：`true`（默认）同步生成音频；`false` 返回只含画面的视频文件。
* `seed` (integer)：随机种子，取值 `0` 到 `2147483647`。

## 分辨率

所有视频均为 1080p 级别，画面尺寸随宽高比变化，例如 16:9 为 1920×1080，9:16 为 1080×1920，21:9 为 2182×950。

## 输出

任务完成后返回一个 MP4 文件：H.264 视频，25 fps；`generate_audio` 为 `true` 时带 AAC 立体声音轨。

## 示例

* **带台词的文生视频**：描述场景，把台词放在引号里，角色会在生成的音频中说出这句话。
* **首尾帧**：在 `image_urls` 中传入起始帧，或再加一张图片指定结束帧。
* **参考生视频**：传入一张角色图片和一段音乐，并在 `prompt` 中描述新场景；同一个角色会出现在新场景中，随音乐演奏。

## 注意事项

* 首尾帧使用 `image_urls`，参考使用 `reference_*` 字段；每个任务使用这两种模式之一。
* 所有媒体 URL 都必须可公开访问并可直接下载。


## OpenAPI

````yaml zh/api-manual/video-series/magi-2.json POST /api/generate/submit
openapi: 3.0.0
info:
  title: PoYo AI - MAGI-2 API
  description: MAGI-2 API 可根据文本、首尾帧，或图片、视频和音频参考，生成 4–30 秒、带同步音频的 1080p 视频。
  version: 1.0.0
servers:
  - url: https://api.poyo.ai
    description: Production server
security:
  - BearerAuth: []
paths:
  /api/generate/submit:
    post:
      tags:
        - MAGI-2
      summary: 提交 MAGI-2 视频任务
      operationId: submitMagi2Task
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SubmitRequest'
            examples:
              text-to-video:
                summary: 带台词的文生视频
                value:
                  model: magi-2
                  input:
                    prompt: >-
                      In a rainy neon-lit Tokyo alley at night, an elderly
                      street musician plays a slow saxophone melody. The camera
                      slowly pushes in. He lowers the saxophone, smiles at the
                      camera and says: "Thanks for staying till the last song."
                      Rain patters on the wet pavement.
                    duration: 5
                    aspect_ratio: '16:9'
              first-last-frame:
                summary: 首帧生视频
                value:
                  model: magi-2
                  input:
                    prompt: >-
                      The pangolin rolls the paint roller down the windmill
                      sail, leaving a fresh coral stripe, while the sails begin
                      to turn in the breeze. Soft wind and birdsong.
                    image_urls:
                      - >-
                        https://storage.poyo.ai/models/magi-2/examples/first-frame-f29912c3eb5f.jpg
                    duration: 5
              reference-to-video:
                summary: 角色图片和音频参考
                value:
                  model: magi-2
                  input:
                    prompt: >-
                      The elderly street musician from the reference image walks
                      along a sunlit seaside boardwalk in the morning, playing
                      the saxophone melody from the reference audio. Seagulls
                      glide overhead and gentle waves roll in. He stops, turns
                      to the camera and says: "Morning light suits this tune."
                    reference_image_urls:
                      - >-
                        https://storage.poyo.ai/models/magi-2/examples/reference-character-6586977013a0.jpg
                    reference_audio_urls:
                      - >-
                        https://storage.poyo.ai/models/magi-2/examples/reference-audio-5bf2add370f4.mp3
                    duration: 8
                    aspect_ratio: '16:9'
      responses:
        '200':
          description: 任务提交成功
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SubmitResponse'
        '400':
          description: 请求参数无效
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: 未授权：API Key 无效
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  schemas:
    SubmitRequest:
      type: object
      required:
        - model
        - input
      additionalProperties: false
      properties:
        model:
          type: string
          enum:
            - magi-2
          description: 对外模型标识。
        callback_url:
          type: string
          format: uri
          description: 任务完成或失败时接收通知的 Webhook 地址。
        input:
          type: object
          additionalProperties: false
          required:
            - prompt
          properties:
            prompt:
              type: string
              minLength: 1
              maxLength: 15000
              description: 描述场景、主体、动作、镜头和声音。台词放在引号里。最多 15,000 个字符，且须包含非空白文字。
            duration:
              type: integer
              minimum: 4
              maximum: 30
              default: 5
              description: 视频时长，整数秒，4 到 30。默认 `5`。
            resolution:
              type: string
              enum:
                - 1080p
              default: 1080p
              description: 输出分辨率：`1080p`。
            aspect_ratio:
              type: string
              enum:
                - auto
                - '16:9'
                - '9:16'
                - '1:1'
                - '4:3'
                - '3:4'
                - '21:9'
              description: >-
                视频宽高比。文生视频和参考生视频使用 `16:9`（默认）、`9:16`、`1:1`、`4:3`、`3:4` 或
                `21:9`。传入 `image_urls` 时，视频沿用首帧的宽高比，此字段留空或传 `auto`。
            image_urls:
              type: array
              minItems: 1
              maxItems: 2
              items:
                type: string
                format: uri
              description: >-
                首尾帧模式。第 1 张图片为起始帧，可选的第 2 张为结束帧。支持 JPG、PNG、WEBP。每个 URL 都必须是可公开访问的
                HTTP 或 HTTPS 链接。
            reference_image_urls:
              type: array
              minItems: 1
              maxItems: 10
              items:
                type: string
                format: uri
              description: >-
                参考模式。最多 10 张图片，用于参考角色、物体、场景或风格。每个 URL 都必须是可公开访问的 HTTP 或 HTTPS
                链接。
            reference_video_urls:
              type: array
              minItems: 1
              maxItems: 5
              items:
                type: string
                format: uri
              description: >-
                参考模式。最多 5 个 MP4 或 MOV 视频，用于参考动作、运镜或角色，每段 2–30 秒，合计最多 30 秒。每个 URL
                都必须是可公开访问的 HTTP 或 HTTPS 链接。
            reference_audio_urls:
              type: array
              minItems: 1
              maxItems: 5
              items:
                type: string
                format: uri
              description: >-
                参考模式。最多 5 段 MP3 或 WAV 音频，用于参考人声、音乐或节奏，每段 2–30 秒，合计最多 30 秒。每个 URL
                都必须是可公开访问的 HTTP 或 HTTPS 链接。
            generate_audio:
              type: boolean
              default: true
              description: '`true`（默认）同步生成对白、音效和环境声；`false` 返回只含画面的视频文件。'
            seed:
              type: integer
              minimum: 0
              maximum: 2147483647
              description: 随机种子，取值 `0` 到 `2147483647`。相同输入配合相同种子可得到相近结果；留空则随机。
    SubmitResponse:
      type: object
      required:
        - code
        - data
      properties:
        code:
          type: integer
          example: 200
          enum:
            - 200
            - 400
            - 401
            - 402
            - 403
            - 404
            - 408
            - 429
            - 500
            - 502
            - 503
          description: >-
            业务状态码。`200` 表示成功，其他值都表示请求失败。请务必检查这个字段：部分参数校验错误会以 HTTP 200 返回，响应体里的
            `code` 为 `400`。


            - `200`：成功

            - `400`：请求参数无效

            - `401`：API Key 缺失或无效

            - `402`：积分不足

            - `403`：没有权限

            - `404`：资源不存在

            - `408`：请求超时

            - `429`：请求频率超限

            - `500`：服务器内部错误

            - `502`：上游服务错误

            - `503`：服务暂不可用


            详见[错误码](/zh/api-manual/error-codes)。
        data:
          type: object
          required:
            - task_id
            - status
            - created_time
          properties:
            task_id:
              type: string
            status:
              type: string
              enum:
                - not_started
                - running
                - finished
                - failed
              example: not_started
              description: >-
                任务状态。提交后立即返回时始终为
                `not_started`。后续状态请通过[查询任务状态](/zh/api-manual/task-management/status)接口或
                `callback_url` 获取。


                - `not_started`：排队中，等待处理

                - `running`：生成中

                - `finished`：已完成，结果在 `files` 或 `output` 中

                - `failed`：失败，详情见 `error_message`
            created_time:
              type: string
              format: date-time
    ErrorResponse:
      type: object
      required:
        - code
        - error
      properties:
        code:
          type: integer
          example: 400
          enum:
            - 200
            - 400
            - 401
            - 402
            - 403
            - 404
            - 408
            - 429
            - 500
            - 502
            - 503
          description: >-
            业务状态码。`200` 表示成功，其他值都表示请求失败。请务必检查这个字段：部分参数校验错误会以 HTTP 200 返回，响应体里的
            `code` 为 `400`。


            - `200`：成功

            - `400`：请求参数无效

            - `401`：API Key 缺失或无效

            - `402`：积分不足

            - `403`：没有权限

            - `404`：资源不存在

            - `408`：请求超时

            - `429`：请求频率超限

            - `500`：服务器内部错误

            - `502`：上游服务错误

            - `503`：服务暂不可用


            详见[错误码](/zh/api-manual/error-codes)。
        error:
          type: object
          required:
            - message
            - type
          properties:
            message:
              type: string
              example: Invalid request parameters
            type:
              type: string
              example: invalid_request_error
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: >-
        所有 API 接口都需要 Bearer Token 认证。


        创建 API Key：登录 PoYo，进入 **仪表盘 → API
        密钥**（[poyo.ai/zh/dashboard/api-key](https://poyo.ai/zh/dashboard/api-key)），点击创建
        Key。


        在请求头中添加：


        ```

        Authorization: Bearer YOUR_API_KEY

        ```

````

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