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

# 创建任务

> 创建 MAGI-2 视频生成任务：`model` 选择模型，生成参数放在 `input` 中，可选 `callBackUrl` 接收完成回调。成功后返回 `data.taskId`，任务在后台异步执行，用查询任务接口轮询结果。所有响应的 HTTP 状态码都是 200，以 `code` 判断结果。



## OpenAPI

````yaml /openapi/zh/magi-2-reference-to-video.json post /api/v1/jobs/createTask
openapi: 3.1.0
info:
  description: MAGI-2 参考生视频：参考图片、视频和音频生成 4 ~ 30 秒的 1080p 有声视频，人物外观、动作和嗓音跟随参考素材。
  title: MAGI-2 参考生视频
  version: v1
servers:
  - url: https://api.dreamto.ai
security:
  - bearerAuth: []
tags:
  - name: MAGI-2 参考生视频
paths:
  /api/v1/jobs/createTask:
    post:
      tags:
        - MAGI-2 参考生视频
      summary: 创建任务
      description: >-
        创建 MAGI-2 视频生成任务：`model` 选择模型，生成参数放在 `input` 中，可选 `callBackUrl`
        接收完成回调。成功后返回 `data.taskId`，任务在后台异步执行，用查询任务接口轮询结果。所有响应的 HTTP 状态码都是 200，以
        `code` 判断结果。
      operationId: magi2CreateTask
      requestBody:
        content:
          application/json:
            examples:
              人物与声音参考:
                description: >-
                  `reference_image_urls` 提供人物外观，`reference_audio_urls`
                  提供声音；16:9、5 秒。
                summary: 人物与声音参考
                value:
                  model: magi-2/reference-to-video
                  input:
                    prompt: 以参考图中的女士为主角，她站在雨后的天台上，转身对镜头说：“我们终于到了。”声音沿用参考音频中的嗓音
                    reference_image_urls:
                      - https://cdn.example.com/lead.jpg
                    reference_audio_urls:
                      - https://cdn.example.com/voice.wav
                    duration: 5
                    aspect_ratio: '16:9'
                    resolution: 1080p
                    generate_audio: true
              动作参考视频:
                description: 只传 `reference_video_urls`，按参考视频的动作和运镜生成新画面；9:16、10 秒，完成后回调。
                summary: 动作参考视频
                value:
                  model: magi-2/reference-to-video
                  callBackUrl: https://your-domain.com/api/callback
                  input:
                    prompt: 一只穿宇航服的柴犬在月球表面跳参考视频里的舞，动作和运镜与参考视频一致，地球挂在远处的天空
                    reference_video_urls:
                      - https://cdn.example.com/dance.mp4
                    duration: 10
                    aspect_ratio: '9:16'
              多图参考:
                description: 人物、商品和场景三张参考图同框，外观保持一致；1:1、6 秒。
                summary: 多图参考
                value:
                  model: magi-2/reference-to-video
                  input:
                    prompt: 第一张图的男生坐在第三张图的咖啡馆窗边，拿起第二张图的耳机戴上，微笑着闭上眼睛。声音：轻柔的爵士乐和咖啡馆环境声
                    reference_image_urls:
                      - https://cdn.example.com/man.jpg
                      - https://cdn.example.com/headphones.png
                      - https://cdn.example.com/cafe.webp
                    duration: 6
                    aspect_ratio: '1:1'
            schema:
              $ref: >-
                #/components/schemas/Magi2CreateTaskRequestMagi2ReferenceToVideoInput
        required: true
      responses:
        '200':
          content:
            application/json:
              examples:
                创建成功:
                  description: '`data.taskId` 为任务 ID。'
                  summary: 创建成功
                  value:
                    code: 200
                    msg: success
                    data:
                      taskId: 4b9e2d7a0c1f48e6a3d5b7c9e1f20a84
                参数错误（422）:
                  description: 参数不合法，不建任务、不扣费。
                  summary: 参数错误（422）
                  value:
                    code: 422
                    msg: input.duration must be an integer between 4 and 30.
                    data: null
                未授权（401）:
                  description: API Key 缺失或无效。
                  summary: 未授权（401）
                  value:
                    code: 401
                    msg: >-
                      Unauthorized - Authentication credentials are missing or
                      invalid
                    data: null
                余额不足（402）:
                  description: 余额不足以支付本次任务。
                  summary: 余额不足（402）
                  value:
                    code: 402
                    msg: >-
                      Insufficient Credits - Account does not have enough
                      credits to perform the operation
                    data: null
                请求过于频繁（429）:
                  description: 超过频率限制，请稍后重试。
                  summary: 请求过于频繁（429）
                  value:
                    code: 429
                    msg: >-
                      Rate Limited - Request limit has been exceeded for this
                      resource
                    data: null
                服务器错误（500）:
                  description: 服务暂时不可用，可稍后重试，不扣费。
                  summary: 服务器错误（500）
                  value:
                    code: 500
                    msg: >-
                      Server Error - An unexpected error occurred while
                      processing the request
                    data: null
              schema:
                $ref: '#/components/schemas/Magi2CreateTaskResponse'
          description: >-
            HTTP 状态码始终为 200。`code` 为 `200` 时创建成功，`data.taskId` 为任务 ID；其他 `code`
            为错误，`msg` 为原因，`data` 为 `null`。
          headers:
            X-Request-Id:
              description: 本次请求的 ID，排查问题时请提供。
              schema:
                type: string
components:
  schemas:
    Magi2CreateTaskRequestMagi2ReferenceToVideoInput:
      additionalProperties: false
      description: 创建任务的请求体。
      properties:
        model:
          default: magi-2/reference-to-video
          description: |-
            模型名称，决定 `input` 的字段。

            **可选值：**
            - `magi-2/reference-to-video`：MAGI-2 参考生视频（参考图片、视频、音频）
          enum:
            - magi-2/reference-to-video
          type: string
        callBackUrl:
          description: >-
            可选，任务完成（成功或失败）后接收回调的地址，须为公网可访问的 `http` / `https`
            地址；推荐生产环境使用，也可以只轮询查询任务接口。回调格式和签名见“任务完成回调”。
          type: string
        input:
          $ref: '#/components/schemas/Magi2ReferenceToVideoInput'
          description: 生成参数，字段由 `model` 决定。
      required:
        - model
        - input
      type: object
    Magi2CreateTaskResponse:
      additionalProperties: false
      description: 创建任务的响应。HTTP 状态码始终为 200。
      properties:
        code:
          description: |-
            结果代码：
            - `200`：成功
            - `401`：API Key 缺失或无效
            - `402`：余额不足
            - `404`：模型不存在或未开通
            - `405`：请求方法错误
            - `422`：参数错误，`msg` 为原因，不建任务、不扣费
            - `429`：请求过于频繁，请稍后重试
            - `455`：服务维护中
            - `500`：服务器错误，可稍后重试
            - `501`：生成失败
            - `505`：功能已停用
          format: int64
          type: integer
        msg:
          description: 结果说明：成功时为 `success`，错误时为英文原因。
          type: string
        data:
          $ref: '#/components/schemas/Magi2CreateTaskData'
          description: 成功时为任务信息；错误时为 `null`。
      required:
        - code
        - msg
        - data
      type: object
    Magi2ReferenceToVideoInput:
      additionalProperties: false
      description: >-
        `magi-2/reference-to-video`
        的生成参数。`reference_image_urls`、`reference_video_urls`、`reference_audio_urls`
        至少提供一类。
      properties:
        prompt:
          description: >-
            提示词，必填，1 ~ 15000
            个字符。写清主体、动作、镜头运动和声音，并说明各参考素材的用途（如“以第一张图的人物为主角”），对白放在引号里。
          maxLength: 15000
          minLength: 1
          type: string
        reference_image_urls:
          description: >-
            参考图片地址，最多 10 张，支持 JPG、PNG、WEBP，须为公网可访问的 `http` / `https`
            地址。用于保持人物、商品和场景的外观。
          items:
            type: string
          maxItems: 10
          type: array
        reference_video_urls:
          description: >-
            参考视频地址，最多 5 段，支持 MP4、MOV，每段 2 ~ 30 秒、合计不超过 30 秒，须为公网可访问的 `http` /
            `https` 地址。用于参考动作和运镜。
          items:
            type: string
          maxItems: 5
          type: array
        reference_audio_urls:
          description: >-
            参考音频地址，最多 5 段，支持 MP3、WAV，每段 2 ~ 30 秒、合计不超过 30 秒，须为公网可访问的 `http` /
            `https` 地址。用于参考嗓音或声音。
          items:
            type: string
          maxItems: 5
          type: array
        duration:
          default: 5
          description: 视频时长（秒），`4` ~ `30` 的整数，默认 `5`，按秒计费。
          format: int64
          maximum: 30
          minimum: 4
          type: integer
        aspect_ratio:
          default: '16:9'
          description: |-
            输出视频的画面比例，默认 `16:9`。

            **可选值：**
            - `21:9`：超宽银幕
            - `16:9`：横屏宽画幅（默认），适合影视和横版视频
            - `4:3`：传统横屏
            - `1:1`：方形
            - `3:4`：传统竖屏
            - `9:16`：竖屏全屏，适合手机短视频
          enum:
            - '21:9'
            - '16:9'
            - '4:3'
            - '1:1'
            - '3:4'
            - '9:16'
          type: string
        resolution:
          default: 1080p
          description: |-
            输出分辨率，目前仅支持 `1080p`（默认）。

            **可选值：**
            - `1080p`：1080p 全高清（默认）
          enum:
            - 1080p
          type: string
        generate_audio:
          default: true
          description: 是否同步生成声音（对白、音效和环境声），默认 `true`。`false` 时输出无声视频，价格不变。
          type: boolean
        seed:
          description: 随机种子，`0` ~ `2147483647`；不传时随机。相同参数和种子有助于复现结果。
          format: int64
          maximum: 2147483647
          minimum: 0
          type: integer
      required:
        - prompt
      type: object
    Magi2CreateTaskData:
      additionalProperties: false
      description: 新建的任务。
      properties:
        taskId:
          description: 任务 ID（32 位十六进制），用于查询任务。
          type: string
      required:
        - taskId
      type: object
  securitySchemes:
    bearerAuth:
      description: 'DreamTo 控制台创建的 API Key，格式 `Authorization: Bearer <API Key>`。'
      scheme: bearer
      type: http

````

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