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

# MAGI-2

> 通过文本、首尾帧或多模态参考生成 4–30 秒 1080p 带声音视频。

## 参数与输入模式

请求必填 `model` 与 `input`，省略的可选字段使用模型默认值。完整字段定义见下方 Body 区域。

| 请求场景 | 必填 input 字段 |
| - | - |
| 文生视频 | `mode: "text_to_video"`、`prompt`（不可传素材字段） |
| 首尾帧图生视频 | `mode: "image_to_video"`、`prompt`、`first_frame_url`（可选 `last_frame_url`） |
| 多模态参考生视频 | `mode: "reference_to_video"`、`prompt`，以及参考图/视频/音频至少一项 |

## 特殊模式

* **多模态参考限制与指代**：`reference_to_video` 最多 10 图、5 视频（单段 2–30 秒且合计 ≤30 秒）、5 音频（单段 2–30 秒且合计 ≤30 秒）；提示词可用 `@Image1`/`@Video1`/`@Audio1` 指代，建议使用英文。

## 使用场景示例

将下方示例提交至 `POST /api/v1/tasks/create_task`，并将提示词与素材链接替换为你的内容。

```json 文生视频 theme={null}
{
  "model": "magi-2",
  "input": {
    "mode": "text_to_video",
    "prompt": "A wooden train glides along a misty coastal viaduct at golden hour, ocean waves crashing below.",
    "resolution": "1080p",
    "aspect_ratio": "16:9",
    "duration": 5,
    "generate_audio": true
  }
}
```

```json 首尾帧图生视频 theme={null}
{
  "model": "magi-2",
  "input": {
    "mode": "image_to_video",
    "prompt": "Smooth tracking shot as twilight lanterns illuminate the quiet courtyard.",
    "first_frame_url": "https://cdn.example.com/start.jpg",
    "last_frame_url": "https://cdn.example.com/end.jpg",
    "aspect_ratio": "16:9",
    "duration": 8
  }
}
```

```json 多模态参考生视频 theme={null}
{
  "model": "magi-2",
  "input": {
    "mode": "reference_to_video",
    "prompt": "Follow the character appearance from @Image1, camera movement from @Video1, and ambient rhythm from @Audio1.",
    "reference_image_urls": [
      "https://cdn.example.com/character.jpg"
    ],
    "reference_video_urls": [
      "https://cdn.example.com/camera.mp4"
    ],
    "reference_audio_urls": [
      "https://cdn.example.com/ambience.mp3"
    ],
    "aspect_ratio": "16:9",
    "duration": 6
  }
}
```

> 通过[查询任务](https://docs.apistable.ai/zh/query-task.md)或 `callback_url`（[Webhook 验签](https://docs.apistable.ai/zh/webhook-secret.md)）获取结果，提交错误见[创建任务](https://docs.apistable.ai/zh/create-task.md)。生成链接保留 14 天；超过 24 小时未完成的任务自动失败且不扣费。

## 在线试用与价格

每个成功的 1080p 视频分别按请求的整数 `duration`（4–30 秒）统一计费；输出文件可能略长约 0.24 秒且不额外收费。音频、画幅与参考素材不加价，失败项扣费为 0。余额查询见[积分余额](https://docs.apistable.ai/zh/credits.md)。

| 分辨率 | 积分 / 秒 | 价格 / 秒 |
| - | - | - |
| `1080p`（全部模式） | 16.0 | 折合 ≈ \*\*$0.073** · 常规 $0.080 |

> [card] [在线试用](https://apistable.ai/zh/models/magi-2#try)
>
> 在工作台测试文生、首尾帧与多模态参考模式。

> [card] [查看价格](https://apistable.ai/zh/models/magi-2#pricing)
>
> 查看 1080p 每秒单价与充值折合价。


## OpenAPI

````yaml openapi-magi-2-zh.json POST /api/v1/tasks/create_task
openapi: 3.1.0
info:
  title: APIstable API
  version: 1.0.0-preview
  description: >-
    Public /api/v1 protocol. Valid API keys have the same account-scoped access.
    Read the selected model documentation for its ID, supported inputs, result
    format and availability before submitting. No client submission idempotency
    or max_credits. Availability, pricing, file retention and callback formats
    follow the selected model contract. Unconfigured operations return 503.
servers:
  - url: https://apistable.ai
    description: API Stable API
security: []
paths:
  /api/v1/tasks/create_task:
    post:
      summary: MAGI-2
      description: 通过文本、首尾帧或多模态参考生成 4–30 秒 1080p 带声音视频。
      operationId: magi-2
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - model
                - input
              additionalProperties: false
              properties:
                model:
                  type: string
                  enum:
                    - magi-2
                  example: magi-2
                  description: 本页对应的 APIstable 模型 ID。
                input:
                  description: MAGI-2 输入参数。先选 `mode`，再填写该模式使用的素材字段。
                  type: object
                  properties:
                    mode:
                      type: string
                      enum:
                        - text_to_video
                        - image_to_video
                        - reference_to_video
                      description: >-
                        必填显式模式：`text_to_video`、`image_to_video` 或
                        `reference_to_video`。传入其他模式的字段返回 HTTP 400。
                    nsfw_check:
                      type: boolean
                      description: >-
                        可选 APIstable 安全审核，默认 false。开启后审核失败会拒绝请求；仅审核文字及最多 20
                        张图片，不审核音视频；图片超限返回 HTTP 400。网站试用始终开启审核。
                    output_count:
                      default: 1
                      type: integer
                      minimum: 1
                      maximum: 4
                      description: 独立视频数量，1–4 的整数，默认 1。成功项分别计费，失败项不扣费。
                    prompt:
                      type: string
                      minLength: 1
                      maxLength: 8000
                      description: >-
                        必填非空场景描述（1–8,000 字符，建议使用英文）。`reference_to_video` 模式可用
                        `@Image1`、`@Video1`、`@Audio1` 指代参考素材。
                    resolution:
                      default: 1080p
                      type: string
                      const: 1080p
                      description: 输出分辨率，固定为 `1080p`（默认）。
                    aspect_ratio:
                      default: '16:9'
                      type: string
                      enum:
                        - '21:9'
                        - '16:9'
                        - '4:3'
                        - '1:1'
                        - '3:4'
                        - '9:16'
                      description: >-
                        输出画幅比例：`21:9`、`16:9`（默认）、`4:3`、`1:1`、`3:4` 或 `9:16`，不接受
                        `auto`（返回 HTTP 400）。
                    duration:
                      default: 5
                      type: integer
                      minimum: 4
                      maximum: 30
                      description: >-
                        请求输出时长，4–30 的整数秒（默认 `5`）。计费按请求秒数计算；输出文件可能略长约 0.24
                        秒，不额外收费。
                    generate_audio:
                      default: true
                      type: boolean
                      description: 是否同步生成音轨，默认 `true`，开启或关闭不改变每秒费率。
                    first_frame_url:
                      type: string
                      format: uri
                      description: 首帧图片，`image_to_video` 必填。
                    last_frame_url:
                      type: string
                      format: uri
                      description: 尾帧图片，`image_to_video` 可选，须同时提供 `first_frame_url`。
                    reference_image_urls:
                      minItems: 1
                      maxItems: 10
                      type: array
                      items:
                        type: string
                        format: uri
                      description: 仅 `reference_to_video` 可选（图/视频/音频合计须至少 1 项）。1–10 张参考图片。
                    reference_video_urls:
                      minItems: 1
                      maxItems: 5
                      type: array
                      items:
                        type: string
                        format: uri
                      description: >-
                        仅 `reference_to_video` 可选。1–5 段参考视频；单段须 2–30 秒且总时长 ≤30
                        秒。
                    reference_audio_urls:
                      minItems: 1
                      maxItems: 5
                      type: array
                      items:
                        type: string
                        format: uri
                      description: 仅 `reference_to_video` 可选。1–5 段参考音频，每段 2–30 秒；总时长 ≤30 秒。
                  required:
                    - mode
                    - prompt
                  additionalProperties: false
                  not:
                    anyOf:
                      - properties:
                          mode:
                            const: text_to_video
                        required:
                          - mode
                        anyOf:
                          - required:
                              - first_frame_url
                          - required:
                              - last_frame_url
                          - required:
                              - reference_image_urls
                          - required:
                              - reference_video_urls
                          - required:
                              - reference_audio_urls
                      - properties:
                          mode:
                            const: image_to_video
                        required:
                          - mode
                        not:
                          required:
                            - first_frame_url
                      - properties:
                          mode:
                            const: image_to_video
                        required:
                          - mode
                        anyOf:
                          - required:
                              - reference_image_urls
                          - required:
                              - reference_video_urls
                          - required:
                              - reference_audio_urls
                      - properties:
                          mode:
                            const: reference_to_video
                        required:
                          - mode
                        not:
                          anyOf:
                            - required:
                                - reference_image_urls
                            - required:
                                - reference_video_urls
                            - required:
                                - reference_audio_urls
                      - properties:
                          mode:
                            const: reference_to_video
                        required:
                          - mode
                        anyOf:
                          - required:
                              - first_frame_url
                          - required:
                              - last_frame_url
                callback_url:
                  type: string
                  format: uri
                  description: 任务完成时接收签名回调的公网 HTTPS 地址。须为可直接访问的地址，不能跳转到其他地址。省略时可轮询查询任务接口。
            example:
              model: magi-2
              input:
                mode: text_to_video
                prompt: >-
                  A wooden train glides along a misty coastal viaduct at golden
                  hour, ocean waves crashing below.
                resolution: 1080p
                aspect_ratio: '16:9'
                duration: 5
                generate_audio: true
      responses:
        '200':
          description: Accepted task. Poll the common task endpoint or use callback_url.
          content:
            application/json:
              schema:
                type: object
                required:
                  - code
                  - msg
                  - data
                additionalProperties: false
                properties:
                  code:
                    const: 200
                  msg:
                    const: success
                  data:
                    type: object
                    required:
                      - task_id
                    additionalProperties: false
                    properties:
                      task_id:
                        type: string
        '400':
          description: >-
            40001 invalid JSON, 40002 invalid input/callback or input rejected
            by screening, 40003 unsupported parameter.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Invalid or revoked API key.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '402':
          description: '40201: Insufficient credits (live acceptance).'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: '40301: Website session requests require the APIstable site origin.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: '40401: Unknown model or resource not found in this account.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          description: '40901: Resource incompatible with this operation.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '410':
          description: '41001: Source audio or temporary resource has expired.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '413':
          description: '41301: Request too large.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '422':
          description: '42201: Requested capability combination is not enabled.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          description: '42901: Rate/concurrency limit (live acceptance).'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '503':
          description: '50301: Service unavailable. No live submission or charge.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
      callbacks:
        Webhook:
          '{$request.body#/callback_url}':
            post:
              requestBody:
                required: true
                description: >-
                  任务成功或失败后，APIstable 向创建任务时传入的 `callback_url` 发送 JSON POST。验签后返回
                  HTTP 2xx 确认接收。


                  用 `data.status` 判断生成结果。成功时为 `succeeded`，生成视频链接位于
                  `data.result.urls`。全部失败时为 `failed`，`data.result` 为
                  `null`，`data.message` 提供失败原因。


                  签名和去重使用 `X-APIstable-Signature`、`X-APIstable-Timestamp` 和
                  `X-APIstable-Event-Id`。详见 [Webhook 安全与验签](/zh/webhook-secret)。


                  **Webhook 请求体示例**


                  ```json

                  {
                    "code": 200,
                    "msg": "success",
                    "data": {
                      "task_id": "c6adbc82-8b9a-4d6f-8b60-1114c8c4aafb",
                      "model": "magi-2",
                      "status": "succeeded",
                      "created_at": "2026-11-25T08:30:00.000Z",
                      "completed_at": "2026-11-25T08:45:00.000Z",
                      "duration": 900000,
                      "charged_credits": 80,
                      "message": "",
                      "input": "{\"mode\":\"text_to_video\",\"prompt\":\"A wooden train glides along a misty coastal viaduct at golden hour, ocean waves crashing below.\",\"resolution\":\"1080p\",\"aspect_ratio\":\"16:9\",\"duration\":5,\"generate_audio\":true}",
                      "result": {
                        "urls": [
                          "https://cdn.example.com/generated/video.mp4"
                        ],
                        "items": [
                          {
                            "id": "e7aacd19-819a-4747-bbbf-46fb6f2995a5",
                            "urls": [
                              "https://cdn.example.com/generated/video.mp4"
                            ],
                            "last_frame_url": null,
                            "draft": false,
                            "draft_expires_at": null
                          }
                        ]
                      }
                    }
                  }

                  ```
                content:
                  application/json:
                    schema:
                      type: object
                      required:
                        - code
                        - msg
                        - data
                      properties:
                        code:
                          type: integer
                          const: 200
                        msg:
                          type: string
                          const: success
                        data:
                          type: object
                          additionalProperties: false
                          required:
                            - task_id
                            - model
                            - status
                            - created_at
                            - completed_at
                            - duration
                            - charged_credits
                            - message
                            - input
                            - result
                          properties:
                            task_id:
                              type: string
                            model:
                              type: string
                              const: magi-2
                            status:
                              type: string
                              enum:
                                - succeeded
                                - failed
                            created_at:
                              type: string
                              format: date-time
                            completed_at:
                              type:
                                - string
                                - 'null'
                              format: date-time
                            duration:
                              type:
                                - integer
                                - 'null'
                              minimum: 0
                              description: >-
                                Total elapsed milliseconds; null while
                                processing.
                            charged_credits:
                              type:
                                - number
                                - 'null'
                              minimum: 0
                              description: Final charged Credits; null until completion.
                            message:
                              type: string
                              description: >-
                                Failure reason for failed tasks, or an
                                actionable pending-settlement message while
                                processing; empty on success.
                            input:
                              type: string
                              contentMediaType: application/json
                              description: JSON-serialized accepted model input.
                            result:
                              type:
                                - object
                                - 'null'
                              required:
                                - urls
                                - items
                              properties:
                                urls:
                                  type: array
                                  items:
                                    type: string
                                    format: uri
                                items:
                                  type: array
                                  maxItems: 1
                                  items:
                                    type: object
                                    required:
                                      - id
                                      - urls
                                      - last_frame_url
                                      - draft
                                      - draft_expires_at
                                    properties:
                                      id:
                                        type: string
                                        format: uuid
                                      urls:
                                        type: array
                                        items:
                                          type: string
                                          format: uri
                                      last_frame_url:
                                        type:
                                          - string
                                          - 'null'
                                        format: uri
                                      draft:
                                        type: boolean
                                      draft_expires_at:
                                        type:
                                          - string
                                          - 'null'
                                        format: date-time
                    example:
                      code: 200
                      msg: success
                      data:
                        task_id: c6adbc82-8b9a-4d6f-8b60-1114c8c4aafb
                        model: magi-2
                        status: succeeded
                        created_at: '2026-11-25T08:30:00.000Z'
                        completed_at: '2026-11-25T08:45:00.000Z'
                        duration: 900000
                        charged_credits: 80
                        message: ''
                        input: >-
                          {"mode":"text_to_video","prompt":"A wooden train
                          glides along a misty coastal viaduct at golden hour,
                          ocean waves crashing
                          below.","resolution":"1080p","aspect_ratio":"16:9","duration":5,"generate_audio":true}
                        result:
                          urls:
                            - https://cdn.example.com/generated/video.mp4
                          items:
                            - id: e7aacd19-819a-4747-bbbf-46fb6f2995a5
                              urls:
                                - https://cdn.example.com/generated/video.mp4
                              last_frame_url: null
                              draft: false
                              draft_expires_at: null
              responses:
                2XX:
                  description: 已接收 Webhook。
              method: post
              type: path
            path: '{$request.body#/callback_url}'
      security:
        - bearerAuth: []
components:
  schemas:
    Error:
      type: object
      required:
        - code
        - msg
        - data
      properties:
        code:
          type: integer
        msg:
          type: string
        data:
          type: 'null'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        登录 APIstable 后，在 [API Key 管理](https://apistable.ai/zh/console/keys)
        创建并复制密钥。


        每次调用都要在 HTTP 请求头传入：


        ```http

        Authorization: Bearer YOUR_API_KEY

        ```


        将 YOUR_API_KEY 替换为你创建的 API Key。

````

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