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

# 创建视频生成任务

> 提交一个异步视频生成任务并立即返回 `task_id`，视频在后台生成。请求体为 `{"model": "...", "input": {...}}`，所有生成参数都放在 `input` 中。拿到 `task_id` 后用 `GET /v1/videos/{task_id}` 轮询，直到 `status` 为 `completed` 或 `failed`。



## OpenAPI

````yaml /openapi/zh/kling-4-0.json post /v1/videos
openapi: 3.1.0
info:
  description: 可灵 Kling 4.0：一次生成 3 ~ 30 秒、音画同出的视频，支持文生视频、图生视频和首尾帧，最高 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: 创建视频生成任务
      description: >-
        提交一个异步视频生成任务并立即返回 `task_id`，视频在后台生成。请求体为 `{"model": "...", "input":
        {...}}`，所有生成参数都放在 `input` 中。拿到 `task_id` 后用 `GET /v1/videos/{task_id}`
        轮询，直到 `status` 为 `completed` 或 `failed`。
      operationId: videoCreateTask
      requestBody:
        content:
          application/json:
            examples:
              文生视频:
                description: 只传提示词，用 `aspect_ratio` 指定宽高比。
                summary: 文生视频
                value:
                  model: kling-4.0
                  input:
                    prompt: 一只小熊猫在雪地里慢慢行走，回头看向镜头，电影感，浅景深
                    resolution: 1080P
                    duration: 5
                    aspect_ratio: '16:9'
              图生视频（首帧）:
                description: '`image_url` 作为视频的第一帧，输出比例跟随图片。'
                summary: 图生视频（首帧）
                value:
                  model: kling-4.0
                  input:
                    prompt: 女孩转过头，对着狐狸微笑，微风吹动头发
                    image_url: https://your-cdn.example.com/first-frame.png
                    resolution: 720P
                    duration: 5
              首尾帧生视频:
                description: 同时传 `image_url` 和 `last_frame_url`，生成从首帧过渡到尾帧的视频。
                summary: 首尾帧生视频
                value:
                  model: kling-4.0
                  input:
                    prompt: 镜头缓慢推进，白天逐渐变为夜晚，城市灯光亮起
                    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 竖屏长视频:
                description: 一次生成 15 秒的 9:16 竖屏视频，4K 超分输出。
                summary: 4K 竖屏长视频
                value:
                  model: kling-4.0
                  input:
                    prompt: 雨后的霓虹街头，一位撑伞的行人从远处走来，镜头跟随，地面倒映灯光
                    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: 任务已创建。
          headers:
            X-Request-Id:
              description: 本次请求的 ID，排查问题时请提供。
              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: 参数错误：缺少必填参数或取值不合法。数值或数量超出范围时错误信息会指出字段和允许范围；其他情况为通用提示。不创建任务、不扣费。
        '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: 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: 余额不足：账户余额低于本次请求的预估价格，不创建任务。
        '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: 请求过于频繁，请稍后重试。
        '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: 模型服务暂时不可用，未创建任务、不扣费，可稍后重试。
components:
  schemas:
    Kling40VideoRequest:
      additionalProperties: false
      description: 创建 Kling 4.0 视频生成任务的请求体。
      properties:
        model:
          description: |-
            模型名称，固定为 `kling-4.0`。

            **可选值：**
            - `kling-4.0`：Kling 4.0。
          enum:
            - kling-4.0
          type: string
        input:
          $ref: '#/components/schemas/Kling40VideoInput'
          description: >-
            生成参数。只传 `prompt` 为文生视频；传 `image_url` 为图生视频；同时传 `image_url` 和
            `last_frame_url` 为首尾帧生视频。
      required:
        - model
        - input
      type: object
    VideoCreateTaskResponse:
      additionalProperties: false
      description: 创建任务的响应。
      properties:
        task_id:
          description: 任务 Id，用于查询任务。
          type: string
        status:
          description: |-
            任务状态，创建后为 `queued` 或 `in_progress`。

            **可选值：**
            - `queued`：排队中。
            - `in_progress`：生成中。
            - `completed`：生成成功，从 `video_url` 下载视频。
            - `failed`：生成失败，原因见 `error`，不扣费。
          enum:
            - queued
            - in_progress
            - completed
            - failed
          type: string
        model:
          description: 模型名称。
          type: string
        created_at:
          description: 任务创建时间，Unix 秒级时间戳。
          format: int64
          type: integer
        request_id:
          description: 本次请求的 ID，排查问题时请提供。
          type: string
      required:
        - task_id
        - status
        - model
        - created_at
        - request_id
      type: object
    VideoAPIErrorResponse:
      additionalProperties: false
      description: 错误响应。
      properties:
        error:
          $ref: '#/components/schemas/VideoAPIError'
          description: 错误信息。
      required:
        - error
      type: object
    Kling40VideoInput:
      additionalProperties: false
      description: Kling 4.0 的生成参数。
      properties:
        prompt:
          description: 提示词，描述视频的内容、动作和镜头。文生视频时必填。
          type: string
        image_url:
          description: 首帧图片的公网 URL，传入后为图生视频。支持 jpeg / jpg / png，不超过 10MB。
          type: string
        last_frame_url:
          description: >-
            尾帧图片的公网 URL，必须与 `image_url` 一起使用，生成从首帧过渡到尾帧的视频。支持 jpeg / jpg /
            png，不超过 10MB。
          type: string
        resolution:
          default: 720P
          description: |-
            输出分辨率，默认 `720P`。

            **可选值：**
            - `720P`：720P，原生输出。
            - `1080P`：1080P，原生输出。
            - `2K`：2K，超分输出。
            - `4K`：4K，超分输出。
          enum:
            - 720P
            - 1080P
            - 2K
            - 4K
          type: string
        duration:
          default: 5
          description: 输出视频时长，单位秒，`3` ~ `30` 的整数，默认 `5`。
          format: int64
          maximum: 30
          minimum: 3
          type: integer
        aspect_ratio:
          description: |-
            输出宽高比，用于文生视频。传入首帧图片时输出比例跟随图片。

            **可选值：**
            - `16:9`：横屏。
            - `9:16`：竖屏。
            - `1:1`：方形。
            - `21:9`：超宽屏。
          enum:
            - '16:9'
            - '9:16'
            - '1:1'
            - '21:9'
          type: string
      type: object
    VideoAPIError:
      additionalProperties: false
      description: 错误信息。
      properties:
        code:
          description: 错误码。
          type: string
        http_status:
          description: HTTP 状态码。
          format: int64
          type: integer
        message:
          description: 可读的错误说明。
          type: string
        request_id:
          description: 请求 ID，排查问题时请提供。
          type: string
        type:
          description: |-
            错误类型。

            **可选值：**
            - `invalid_request_error`：请求参数错误。
            - `authentication_error`：认证失败。
            - `insufficient_balance_error`：余额不足。
            - `permission_error`：无权限。
            - `rate_limit_error`：请求过于频繁。
            - `api_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: '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.