> ## 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 a video task

> Submits an asynchronous video generation task and returns a `task_id` immediately; the video is generated in the background. The body is `{"model": "...", "input": {...}}` with every generation parameter inside `input`. Poll `GET /v1/videos/{task_id}` with the `task_id` until `status` is `completed` or `failed`.



## OpenAPI

````yaml /openapi/en/kling-4-0.json post /v1/videos
openapi: 3.1.0
info:
  description: >-
    Kling 4.0: 3–30 second videos with synchronised audio in one generation;
    text-to-video, image-to-video and first/last frame, up to 4K.
  title: Kling 4.0
  version: v1
servers:
  - url: https://api.dreamto.ai
security:
  - bearerAuth: []
tags:
  - name: Kling 4.0
paths:
  /v1/videos:
    post:
      tags:
        - Kling 4.0
      summary: Create a video task
      description: >-
        Submits an asynchronous video generation task and returns a `task_id`
        immediately; the video is generated in the background. The body is
        `{"model": "...", "input": {...}}` with every generation parameter
        inside `input`. Poll `GET /v1/videos/{task_id}` with the `task_id` until
        `status` is `completed` or `failed`.
      operationId: videoCreateTask
      requestBody:
        content:
          application/json:
            examples:
              Text-to-video:
                description: A prompt only; `aspect_ratio` sets the frame.
                summary: Text-to-video
                value:
                  model: kling-4.0
                  input:
                    prompt: >-
                      A red panda walks slowly through fresh snow and looks back
                      at the camera, cinematic, shallow depth of field
                    resolution: 1080P
                    duration: 5
                    aspect_ratio: '16:9'
              Image-to-video (first frame):
                description: >-
                  `image_url` is the first frame of the video; the output
                  follows the image.
                summary: Image-to-video (first frame)
                value:
                  model: kling-4.0
                  input:
                    prompt: >-
                      The girl turns her head and smiles at the fox as a breeze
                      moves her hair
                    image_url: https://your-cdn.example.com/first-frame.png
                    resolution: 720P
                    duration: 5
              First and last frame:
                description: >-
                  Send `image_url` and `last_frame_url` together; the video
                  transitions from the first frame to the last.
                summary: First and last frame
                value:
                  model: kling-4.0
                  input:
                    prompt: >-
                      The camera pushes in slowly as day turns to night and the
                      city lights come on
                    image_url: https://your-cdn.example.com/first-frame.png
                    last_frame_url: https://your-cdn.example.com/last-frame.png
                    resolution: 1080P
                    duration: 8
              4K portrait, long clip:
                description: >-
                  A 15-second 9:16 portrait video in one generation, upscaled to
                  4K.
                summary: 4K portrait, long clip
                value:
                  model: kling-4.0
                  input:
                    prompt: >-
                      A neon street after rain: a pedestrian with an umbrella
                      walks towards the camera, which follows as the lights
                      reflect on the ground
                    resolution: 4K
                    duration: 15
                    aspect_ratio: '9:16'
            schema:
              $ref: '#/components/schemas/Kling40VideoRequest'
        required: true
      responses:
        '200':
          content:
            application/json:
              examples:
                example:
                  value:
                    task_id: job_02b88886c4fda5be35baff61
                    status: in_progress
                    model: kling-4.0
                    created_at: 1794846663
                    request_id: req_6a9a539502118ba1c33f1bfc
              schema:
                $ref: '#/components/schemas/VideoCreateTaskResponse'
          description: Task created.
          headers:
            X-Request-Id:
              description: ID of this request; include it when reporting issues.
              schema:
                type: string
        '400':
          content:
            application/json:
              examples:
                example:
                  value:
                    error:
                      code: invalid_request
                      http_status: 400
                      message: Invalid request.
                      request_id: req_6a9a539502118ba1c33f1bfc
                      type: invalid_request_error
              schema:
                $ref: '#/components/schemas/VideoAPIErrorResponse'
          description: >-
            Invalid request: a required parameter is missing or a value is not
            allowed. A number or item count out of range is reported with the
            field and its allowed range; other cases return a generic message.
            No task is created and nothing is charged.
        '401':
          content:
            application/json:
              examples:
                example:
                  value:
                    error:
                      code: unauthorized
                      http_status: 401
                      message: Invalid API key.
                      request_id: req_6a9a539502118ba1c33f1bfc
                      type: authentication_error
              schema:
                $ref: '#/components/schemas/VideoAPIErrorResponse'
          description: Missing or invalid API Key.
        '402':
          content:
            application/json:
              examples:
                example:
                  value:
                    error:
                      code: insufficient_balance
                      http_status: 402
                      message: Insufficient balance.
                      request_id: req_6a9a539502118ba1c33f1bfc
                      type: insufficient_balance_error
              schema:
                $ref: '#/components/schemas/VideoAPIErrorResponse'
          description: >-
            Insufficient balance: the balance is below the estimated price of
            the request. No task is created.
        '429':
          content:
            application/json:
              examples:
                example:
                  value:
                    error:
                      code: rate_limit_exceeded
                      http_status: 429
                      message: Rate limit exceeded. Please try again later.
                      request_id: req_6a9a539502118ba1c33f1bfc
                      type: rate_limit_error
              schema:
                $ref: '#/components/schemas/VideoAPIErrorResponse'
          description: Too many requests; retry later.
        '502':
          content:
            application/json:
              examples:
                example:
                  value:
                    error:
                      code: service_unavailable
                      http_status: 502
                      message: Service temporarily unavailable. Please try again later.
                      request_id: req_6a9a539502118ba1c33f1bfc
                      type: api_error
              schema:
                $ref: '#/components/schemas/VideoAPIErrorResponse'
          description: >-
            The model service is temporarily unavailable. No task is created and
            nothing is charged; retry later.
components:
  schemas:
    Kling40VideoRequest:
      additionalProperties: false
      description: Body of a Kling 4.0 video generation request.
      properties:
        model:
          description: |-
            Model name. Must be `kling-4.0`.

            **Allowed values:**
            - `kling-4.0`: Kling 4.0.
          enum:
            - kling-4.0
          type: string
        input:
          $ref: '#/components/schemas/Kling40VideoInput'
          description: >-
            Generation parameters. `prompt` alone is text-to-video; `image_url`
            makes it image-to-video; `image_url` together with `last_frame_url`
            is first-and-last-frame generation.
      required:
        - model
        - input
      type: object
    VideoCreateTaskResponse:
      additionalProperties: false
      description: Response of a create request.
      properties:
        task_id:
          description: Task ID, used to query the task.
          type: string
        status:
          description: |-
            Task status; `queued` or `in_progress` right after creation.

            **Allowed values:**
            - `queued`: Waiting in the queue.
            - `in_progress`: Being generated.
            - `completed`: Finished; download the video from `video_url`.
            - `failed`: Failed; see `error` for the reason. Not charged.
          enum:
            - queued
            - in_progress
            - completed
            - failed
          type: string
        model:
          description: Model name.
          type: string
        created_at:
          description: Task creation time, Unix timestamp in seconds.
          format: int64
          type: integer
        request_id:
          description: ID of this request; include it when reporting issues.
          type: string
      required:
        - task_id
        - status
        - model
        - created_at
        - request_id
      type: object
    VideoAPIErrorResponse:
      additionalProperties: false
      description: Error response.
      properties:
        error:
          $ref: '#/components/schemas/VideoAPIError'
          description: Error details.
      required:
        - error
      type: object
    Kling40VideoInput:
      additionalProperties: false
      description: Generation parameters of Kling 4.0.
      properties:
        prompt:
          description: >-
            The prompt: describes the content, motion and camera work of the
            video. Required for text-to-video.
          type: string
        image_url:
          description: >-
            Public URL of the first-frame image; turns the request into
            image-to-video. jpeg / jpg / png, up to 10MB.
          type: string
        last_frame_url:
          description: >-
            Public URL of the last-frame image. Must be used together with
            `image_url`; the video transitions from the first frame to the last
            frame. jpeg / jpg / png, up to 10MB.
          type: string
        resolution:
          default: 720P
          description: |-
            Output resolution. Defaults to `720P`.

            **Allowed values:**
            - `720P`: 720P, native output.
            - `1080P`: 1080P, native output.
            - `2K`: 2K, upscaled output.
            - `4K`: 4K, upscaled output.
          enum:
            - 720P
            - 1080P
            - 2K
            - 4K
          type: string
        duration:
          default: 5
          description: >-
            Output duration in seconds, an integer from `3` to `30`. Defaults to
            `5`.
          format: int64
          maximum: 30
          minimum: 3
          type: integer
        aspect_ratio:
          description: >-
            Output aspect ratio, for text-to-video. With a first-frame image the
            output follows the image.


            **Allowed values:**

            - `16:9`: Landscape.

            - `9:16`: Portrait.

            - `1:1`: Square.

            - `21:9`: Ultra-wide.
          enum:
            - '16:9'
            - '9:16'
            - '1:1'
            - '21:9'
          type: string
      type: object
    VideoAPIError:
      additionalProperties: false
      description: Error details.
      properties:
        code:
          description: Error code.
          type: string
        http_status:
          description: HTTP status code.
          format: int64
          type: integer
        message:
          description: Human-readable error message.
          type: string
        request_id:
          description: Request ID; include it when reporting issues.
          type: string
        type:
          description: |-
            Error type.

            **Allowed values:**
            - `invalid_request_error`: Invalid request.
            - `authentication_error`: Authentication failed.
            - `insufficient_balance_error`: Insufficient balance.
            - `permission_error`: Permission denied.
            - `rate_limit_error`: Rate limited.
            - `api_error`: Server error.
          enum:
            - invalid_request_error
            - authentication_error
            - insufficient_balance_error
            - permission_error
            - rate_limit_error
            - api_error
          type: string
      required:
        - code
        - http_status
        - message
        - request_id
        - type
      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.