> ## 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-image-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: '`first_frame_url` 作为首帧，画面比例跟随图片；5 秒，同步生成声音。'
                summary: 首帧图生视频
                value:
                  model: magi-2/image-to-video
                  input:
                    first_frame_url: https://cdn.example.com/first-frame.jpg
                    prompt: 咖啡师把奶缸倾斜，在拿铁表面拉出一片叶子，镜头缓慢推近。声音：蒸汽声、杯碟轻碰
                    duration: 5
                    resolution: 1080p
                    generate_audio: true
              首尾帧:
                description: 同时传 `last_frame_url`，视频从首帧开始、以尾帧结束；8 秒，固定 `seed`，完成后回调。
                summary: 首尾帧
                value:
                  model: magi-2/image-to-video
                  callBackUrl: https://your-domain.com/api/callback
                  input:
                    first_frame_url: https://cdn.example.com/street-day.jpg
                    last_frame_url: https://cdn.example.com/street-night.jpg
                    prompt: 白天的街道慢慢入夜，路灯一盏盏亮起，镜头保持不动。声音：渐弱的车流声和远处的狗叫
                    duration: 8
                    seed: 42
            schema:
              $ref: >-
                #/components/schemas/Magi2CreateTaskRequestMagi2ImageToVideoInput
        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:
    Magi2CreateTaskRequestMagi2ImageToVideoInput:
      additionalProperties: false
      description: 创建任务的请求体。
      properties:
        model:
          default: magi-2/image-to-video
          description: |-
            模型名称，决定 `input` 的字段。

            **可选值：**
            - `magi-2/image-to-video`：MAGI-2 图生视频（首帧，可选尾帧）
          enum:
            - magi-2/image-to-video
          type: string
        callBackUrl:
          description: >-
            可选，任务完成（成功或失败）后接收回调的地址，须为公网可访问的 `http` / `https`
            地址；推荐生产环境使用，也可以只轮询查询任务接口。回调格式和签名见“任务完成回调”。
          type: string
        input:
          $ref: '#/components/schemas/Magi2ImageToVideoInput'
          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
    Magi2ImageToVideoInput:
      additionalProperties: false
      description: '`magi-2/image-to-video` 的生成参数。画面比例跟随首帧图片，没有 `aspect_ratio`。'
      properties:
        first_frame_url:
          description: >-
            首帧图片地址，必填。支持 JPG、PNG、WEBP，须为公网可访问的 `http` / `https`
            地址。输出视频的画面比例跟随这张图片。
          type: string
        last_frame_url:
          description: 尾帧图片地址，可选。支持 JPG、PNG、WEBP，须为公网可访问的 `http` / `https` 地址。传入后视频以这张图片结束。
          type: string
        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
        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:
        - first_frame_url
        - 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.