> ## 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-text-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: 1080p、5 秒、16:9，同步生成对白和环境声（`generate_audio` 默认 `true`）。
                summary: 有声文生视频
                value:
                  model: magi-2/text-to-video
                  input:
                    prompt: >-
                      黄昏时分，老灯塔看守人沿着螺旋楼梯往上爬，镜头从下方缓缓跟随上升。他停在窗边，低声说：“今晚风很大。”声音：呼啸的海风、木楼梯吱呀作响
                    duration: 5
                    aspect_ratio: '16:9'
                    resolution: 1080p
                    generate_audio: true
              竖版长镜头（无声）:
                description: >-
                  9:16、20 秒，`generate_audio: false` 输出无声视频（价格不变），固定
                  `seed`，完成后回调。
                summary: 竖版长镜头（无声）
                value:
                  model: magi-2/text-to-video
                  callBackUrl: https://your-domain.com/api/callback
                  input:
                    prompt: 一镜到底：清晨的花市，镜头从一束向日葵起步，穿过人群和摊位，最后停在一位正在包花的女孩手上，柔和的侧逆光
                    duration: 20
                    aspect_ratio: '9:16'
                    generate_audio: false
                    seed: 20261124
            schema:
              $ref: '#/components/schemas/Magi2CreateTaskRequestMagi2TextToVideoInput'
        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:
    Magi2CreateTaskRequestMagi2TextToVideoInput:
      additionalProperties: false
      description: 创建任务的请求体。
      properties:
        model:
          default: magi-2/text-to-video
          description: |-
            模型名称，决定 `input` 的字段。

            **可选值：**
            - `magi-2/text-to-video`：MAGI-2 文生视频
          enum:
            - magi-2/text-to-video
          type: string
        callBackUrl:
          description: >-
            可选，任务完成（成功或失败）后接收回调的地址，须为公网可访问的 `http` / `https`
            地址；推荐生产环境使用，也可以只轮询查询任务接口。回调格式和签名见“任务完成回调”。
          type: string
        input:
          $ref: '#/components/schemas/Magi2TextToVideoInput'
          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
    Magi2TextToVideoInput:
      additionalProperties: false
      description: '`magi-2/text-to-video` 的生成参数。'
      properties:
        prompt:
          description: 提示词，必填，1 ~ 15000 个字符。写清主体、动作、镜头运动和声音，对白放在引号里。
          maxLength: 15000
          minLength: 1
          type: string
        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.