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

# Create task

> Creates a MAGI-2 video generation task: `model` picks the model, the generation parameters go in `input`, and the optional `callBackUrl` receives a completion callback. On success `data.taskId` is returned and the task runs asynchronously; poll the query endpoint for the result. Every response has HTTP status 200; check `code`.



## OpenAPI

````yaml /openapi/en/magi-2-image-to-video.json post /api/v1/jobs/createTask
openapi: 3.1.0
info:
  description: >-
    MAGI-2 image-to-video: a 4–30 second 1080p video with sound that starts from
    a first-frame image, optionally ending on a last frame.
  title: MAGI-2 Image to Video
  version: v1
servers:
  - url: https://api.dreamto.ai
security:
  - bearerAuth: []
tags:
  - name: MAGI-2 Image to Video
paths:
  /api/v1/jobs/createTask:
    post:
      tags:
        - MAGI-2 Image to Video
      summary: Create task
      description: >-
        Creates a MAGI-2 video generation task: `model` picks the model, the
        generation parameters go in `input`, and the optional `callBackUrl`
        receives a completion callback. On success `data.taskId` is returned and
        the task runs asynchronously; poll the query endpoint for the result.
        Every response has HTTP status 200; check `code`.
      operationId: magi2CreateTask
      requestBody:
        content:
          application/json:
            examples:
              First-frame image to video:
                description: >-
                  `first_frame_url` is the first frame and sets the aspect
                  ratio; 5 seconds with sound.
                summary: First-frame image to video
                value:
                  model: magi-2/image-to-video
                  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
              First and last frame:
                description: >-
                  With `last_frame_url` the video starts on the first frame and
                  ends on the last one; 8 seconds, fixed `seed`, with a
                  completion callback.
                summary: First and last frame
                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: >-
                      The street slowly turns from day to night as the
                      streetlights come on one by one; the camera stays still.
                      Sound: fading traffic and a distant dog barking
                    duration: 8
                    seed: 42
            schema:
              $ref: >-
                #/components/schemas/Magi2CreateTaskRequestMagi2ImageToVideoInput
        required: true
      responses:
        '200':
          content:
            application/json:
              examples:
                Created:
                  description: '`data.taskId` is the task ID.'
                  summary: Created
                  value:
                    code: 200
                    msg: success
                    data:
                      taskId: 4b9e2d7a0c1f48e6a3d5b7c9e1f20a84
                Invalid request (422):
                  description: The request is invalid; no task is created or charged.
                  summary: Invalid request (422)
                  value:
                    code: 422
                    msg: input.duration must be an integer between 4 and 30.
                    data: null
                Unauthorized (401):
                  description: Missing or invalid API Key.
                  summary: Unauthorized (401)
                  value:
                    code: 401
                    msg: >-
                      Unauthorized - Authentication credentials are missing or
                      invalid
                    data: null
                Insufficient balance (402):
                  description: The balance does not cover the task.
                  summary: Insufficient balance (402)
                  value:
                    code: 402
                    msg: >-
                      Insufficient Credits - Account does not have enough
                      credits to perform the operation
                    data: null
                Rate limited (429):
                  description: Rate limit exceeded; retry later.
                  summary: Rate limited (429)
                  value:
                    code: 429
                    msg: >-
                      Rate Limited - Request limit has been exceeded for this
                      resource
                    data: null
                Server error (500):
                  description: >-
                    The service is temporarily unavailable; retry later. Not
                    charged.
                  summary: Server error (500)
                  value:
                    code: 500
                    msg: >-
                      Server Error - An unexpected error occurred while
                      processing the request
                    data: null
              schema:
                $ref: '#/components/schemas/Magi2CreateTaskResponse'
          description: >-
            Always HTTP 200. With `code` `200` the task was created and
            `data.taskId` is its ID; any other `code` is an error with the
            reason in `msg` and `data` `null`.
          headers:
            X-Request-Id:
              description: ID of this request; include it when reporting issues.
              schema:
                type: string
components:
  schemas:
    Magi2CreateTaskRequestMagi2ImageToVideoInput:
      additionalProperties: false
      description: Request body of createTask.
      properties:
        model:
          default: magi-2/image-to-video
          description: >-
            Model name; it decides the fields of `input`.


            **Allowed values:**

            - `magi-2/image-to-video`: MAGI-2 image-to-video (first frame,
            optional last frame)
          enum:
            - magi-2/image-to-video
          type: string
        callBackUrl:
          description: >-
            Optional URL that receives a callback when the task finishes
            (success or failure); it must be a public `http` / `https` URL.
            Recommended in production; you can also just poll the query
            endpoint. See Task callback for the body and signature.
          type: string
        input:
          $ref: '#/components/schemas/Magi2ImageToVideoInput'
          description: Generation parameters; the fields depend on `model`.
      required:
        - model
        - input
      type: object
    Magi2CreateTaskResponse:
      additionalProperties: false
      description: Response of createTask; always HTTP 200.
      properties:
        code:
          description: >-
            Result code:

            - `200`: success

            - `401`: missing or invalid API Key

            - `402`: insufficient balance

            - `404`: the model does not exist or is not enabled

            - `405`: wrong HTTP method

            - `422`: invalid request, with the reason in `msg`; no task is
            created or charged

            - `429`: too many requests; retry later

            - `455`: service under maintenance

            - `500`: server error; retry later

            - `501`: generation failed

            - `505`: feature disabled
          format: int64
          type: integer
        msg:
          description: 'Message: `success`, or the English reason of an error.'
          type: string
        data:
          $ref: '#/components/schemas/Magi2CreateTaskData'
          description: The task on success; `null` on error.
      required:
        - code
        - msg
        - data
      type: object
    Magi2ImageToVideoInput:
      additionalProperties: false
      description: >-
        Generation parameters of `magi-2/image-to-video`. The aspect ratio
        follows the first-frame image; there is no `aspect_ratio`.
      properties:
        first_frame_url:
          description: >-
            First-frame image URL, required. JPG, PNG or WEBP at a public `http`
            / `https` URL. The output video follows this image's aspect ratio.
          type: string
        last_frame_url:
          description: >-
            Last-frame image URL, optional. JPG, PNG or WEBP at a public `http`
            / `https` URL. When given, the video ends on this image.
          type: string
        prompt:
          description: >-
            Prompt, required, 1–15,000 characters. Describe the action, camera
            movement and sound that follow the first frame, with dialogue in
            quotes.
          maxLength: 15000
          minLength: 1
          type: string
        duration:
          default: 5
          description: >-
            Video duration in seconds, an integer from `4` to `30`; default `5`.
            Billed per second.
          format: int64
          maximum: 30
          minimum: 4
          type: integer
        resolution:
          default: 1080p
          description: |-
            Output resolution; only `1080p` (the default) is available.

            **Allowed values:**
            - `1080p`: 1080p Full HD (default)
          enum:
            - 1080p
          type: string
        generate_audio:
          default: true
          description: >-
            Whether to generate sound with the picture (dialogue, sound effects
            and ambience); default `true`. With `false` the video is silent; the
            price is the same.
          type: boolean
        seed:
          description: >-
            Random seed, `0`–`2147483647`; random when omitted. The same
            parameters and seed help reproduce a result.
          format: int64
          maximum: 2147483647
          minimum: 0
          type: integer
      required:
        - first_frame_url
        - prompt
      type: object
    Magi2CreateTaskData:
      additionalProperties: false
      description: The created task.
      properties:
        taskId:
          description: Task ID (32 hex digits), used to query the task.
          type: string
      required:
        - taskId
      type: object
  securitySchemes:
    bearerAuth:
      description: >-
        API Key created in the DreamTo console, sent as `Authorization: Bearer
        <API Key>`.
      scheme: bearer
      type: http

````

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