> ## 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.

# 查询任务

> 按 `taskId` 查询任务状态和结果。`data.state` 为 `success` 时从 `data.response.resultUrls` 下载视频，为 `fail` 时 `data.failCode` / `data.failMsg` 为失败原因。建议每 10 秒左右查询一次；生成通常需要 1 到数分钟，长视频更久。



## OpenAPI

````yaml /openapi/zh/magi-2-image-to-video.json get /api/v1/jobs/recordInfo
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/recordInfo:
    get:
      tags:
        - MAGI-2 图生视频
      summary: 查询任务
      description: >-
        按 `taskId` 查询任务状态和结果。`data.state` 为 `success` 时从
        `data.response.resultUrls` 下载视频，为 `fail` 时 `data.failCode` /
        `data.failMsg` 为失败原因。建议每 10 秒左右查询一次；生成通常需要 1 到数分钟，长视频更久。
      operationId: magi2RecordInfo
      parameters:
        - description: 任务 ID，即创建任务返回的 `data.taskId`。
          example: 4b9e2d7a0c1f48e6a3d5b7c9e1f20a84
          explode: false
          in: query
          name: taskId
          required: true
          schema:
            examples:
              - 4b9e2d7a0c1f48e6a3d5b7c9e1f20a84
            type: string
      responses:
        '200':
          content:
            application/json:
              examples:
                排队中:
                  description: 任务已创建，等待生成。
                  summary: 排队中
                  value:
                    code: 200
                    msg: success
                    data:
                      taskId: 4b9e2d7a0c1f48e6a3d5b7c9e1f20a84
                      model: magi-2/image-to-video
                      state: waiting
                      param: >-
                        {"input":"{\"first_frame_url\":\"https://cdn.example.com/first-frame.jpg\",\"prompt\":\"The
                        barista tilts the milk pitcher and pours a leaf onto the
                        latte as the camera slowly pushes in. Sound: steam
                        hissing and cups
                        clinking\",\"duration\":5,\"resolution\":\"1080p\",\"generate_audio\":true}","model":"magi-2/image-to-video"}
                      resultJson: null
                      failCode: null
                      failMsg: null
                      costTime: null
                      completeTime: null
                      createTime: 1795046540000
                      updateTime: 1795046550000
                生成中:
                  description: 视频生成中，请稍后再查。
                  summary: 生成中
                  value:
                    code: 200
                    msg: success
                    data:
                      taskId: 4b9e2d7a0c1f48e6a3d5b7c9e1f20a84
                      model: magi-2/image-to-video
                      state: generating
                      param: >-
                        {"input":"{\"first_frame_url\":\"https://cdn.example.com/first-frame.jpg\",\"prompt\":\"The
                        barista tilts the milk pitcher and pours a leaf onto the
                        latte as the camera slowly pushes in. Sound: steam
                        hissing and cups
                        clinking\",\"duration\":5,\"resolution\":\"1080p\",\"generate_audio\":true}","model":"magi-2/image-to-video"}
                      resultJson: null
                      failCode: null
                      failMsg: null
                      costTime: null
                      completeTime: null
                      createTime: 1795046540000
                      updateTime: 1795046550000
                生成成功:
                  description: '`response.resultUrls` 为视频下载地址。'
                  summary: 生成成功
                  value:
                    code: 200
                    msg: success
                    data:
                      taskId: 4b9e2d7a0c1f48e6a3d5b7c9e1f20a84
                      model: magi-2/image-to-video
                      state: success
                      param: >-
                        {"input":"{\"first_frame_url\":\"https://cdn.example.com/first-frame.jpg\",\"prompt\":\"The
                        barista tilts the milk pitcher and pours a leaf onto the
                        latte as the camera slowly pushes in. Sound: steam
                        hissing and cups
                        clinking\",\"duration\":5,\"resolution\":\"1080p\",\"generate_audio\":true}","model":"magi-2/image-to-video"}
                      resultJson: >-
                        {"resultUrls":["https://api.dreamto.ai/v1/tasks/4b9e2d7a0c1f48e6a3d5b7c9e1f20a84/artifacts/8d2c41f0b7e94a6fa1c3d/content?access=Xq3vR8sK1mN6pT2wY9bC4dF7gH0jL5zA8eU1iO3rS6t"]}
                      failCode: null
                      failMsg: null
                      costTime: 56
                      completeTime: 1795046596000
                      createTime: 1795046540000
                      updateTime: 1795046596000
                      response:
                        resultUrls:
                          - >-
                            https://api.dreamto.ai/v1/tasks/4b9e2d7a0c1f48e6a3d5b7c9e1f20a84/artifacts/8d2c41f0b7e94a6fa1c3d/content?access=Xq3vR8sK1mN6pT2wY9bC4dF7gH0jL5zA8eU1iO3rS6t
                生成失败:
                  description: '`failCode` / `failMsg` 为失败原因，不扣费。'
                  summary: 生成失败
                  value:
                    code: 200
                    msg: success
                    data:
                      taskId: 4b9e2d7a0c1f48e6a3d5b7c9e1f20a84
                      model: magi-2/image-to-video
                      state: fail
                      param: >-
                        {"input":"{\"first_frame_url\":\"https://cdn.example.com/first-frame.jpg\",\"prompt\":\"The
                        barista tilts the milk pitcher and pours a leaf onto the
                        latte as the camera slowly pushes in. Sound: steam
                        hissing and cups
                        clinking\",\"duration\":5,\"resolution\":\"1080p\",\"generate_audio\":true}","model":"magi-2/image-to-video"}
                      resultJson: ''
                      failCode: '500'
                      failMsg: Internal Error, Please try again later.
                      costTime: 0
                      completeTime: 1795046596000
                      createTime: 1795046540000
                      updateTime: 1795046596000
                任务不存在（422）:
                  description: 任务 ID 不存在、不属于当前账号或已过期。
                  summary: 任务不存在（422）
                  value:
                    code: 422
                    msg: recordInfo is null
                    data: null
              schema:
                $ref: '#/components/schemas/Magi2RecordInfoResponse'
          description: >-
            HTTP 状态码始终为 200。`code` 为 `200` 时 `data` 为任务信息（任务本身是否成功看
            `data.state`）；其他 `code` 为错误，`data` 为 `null`。
          headers:
            X-Request-Id:
              description: 本次请求的 ID，排查问题时请提供。
              schema:
                type: string
components:
  schemas:
    Magi2RecordInfoResponse:
      additionalProperties: false
      description: 查询任务的响应。HTTP 状态码始终为 200。
      properties:
        code:
          description: |-
            结果代码：
            - `200`：查询成功（任务本身是否成功看 `data.state`）
            - `401`：API Key 缺失或无效
            - `405`：请求方法错误
            - `422`：`taskId` 缺失、不存在、属于其他账号或已过期（`msg` 为 `recordInfo is null`）
            - `429`：请求过于频繁
            - `500`：服务器错误，可稍后重试
          format: int64
          type: integer
        msg:
          description: 结果说明：成功时为 `success`，错误时为英文原因。
          type: string
        data:
          $ref: '#/components/schemas/Magi2TaskRecord'
          description: 任务信息；错误时为 `null`。
      required:
        - code
        - msg
        - data
      type: object
    Magi2TaskRecord:
      additionalProperties: false
      description: 任务信息，查询任务和回调共用。
      properties:
        taskId:
          description: 任务 ID。
          type: string
        model:
          description: 创建任务时的模型名称。
          type: string
        state:
          description: |-
            任务状态；`success` 和 `fail` 为终态。

            **可选值：**
            - `waiting`：已创建，等待开始
            - `queuing`：排队中
            - `generating`：生成中
            - `success`：生成成功（终态），视频地址在 `response.resultUrls`
            - `fail`：生成失败（终态），原因在 `failCode` / `failMsg`，不扣费
          enum:
            - waiting
            - queuing
            - generating
            - success
            - fail
          type: string
        param:
          description: >-
            创建任务时的请求，JSON 字符串，包含 `model`、`callBackUrl`（如有）和 `input`；其中 `input`
            也是 JSON 字符串，需要再解析一次。
          type: string
        resultJson:
          description: >-
            结果 JSON 字符串，形如 `{"resultUrls":["https://...mp4"]}`；任务结束前为
            `null`，失败时为空串。解析后的内容见 `response`。
          type:
            - string
            - 'null'
        failCode:
          description: 失败代码（数字字符串，如 `"500"`）；未失败时为 `null`。
          type:
            - string
            - 'null'
        failMsg:
          description: 失败原因（英文）；未失败时为 `null`。
          type:
            - string
            - 'null'
        costTime:
          description: 生成耗时（秒）；任务结束前为 `null`。
          format: int64
          type:
            - integer
            - 'null'
        completeTime:
          description: 完成时间，Unix 毫秒时间戳；任务结束前为 `null`。
          format: int64
          type:
            - integer
            - 'null'
        createTime:
          description: 创建时间，Unix 毫秒时间戳。
          format: int64
          type: integer
        updateTime:
          description: 最后更新时间，Unix 毫秒时间戳。
          format: int64
          type: integer
        response:
          $ref: '#/components/schemas/Magi2TaskResults'
          description: 解析后的结果，仅任务成功时返回。
      required:
        - taskId
        - model
        - state
        - param
        - resultJson
        - failCode
        - failMsg
        - costTime
        - completeTime
        - createTime
        - updateTime
      type: object
    Magi2TaskResults:
      additionalProperties: false
      description: 任务结果。
      properties:
        resultUrls:
          description: 生成视频的下载地址（MP4）。链接有效期有限（约 14 天），请及时下载保存。
          items:
            type: string
          type: array
      required:
        - resultUrls
      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.