> ## Documentation Index
> Fetch the complete documentation index at: https://apidoc.cometapi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Tạo video Veo 3

> Tạo video Veo 3.1 bất đồng bộ thông qua CometAPI với POST /v1/videos, sau đó thăm dò tác vụ và tải xuống tệp MP4 đã hoàn tất.

Sử dụng endpoint này để bắt đầu một tác vụ video Veo 3.1. API trả về task ID ngay lập tức, vì vậy hãy lưu `id` được trả về và thăm dò tác vụ cho đến khi nó đạt trạng thái kết thúc.

`POST /v1/videos` sử dụng `multipart/form-data`; truyền các điều khiển vô hướng dưới dạng form field và đầu vào media dưới dạng file field `input_reference`.

## Chọn một model

| Model ID      | Khi nào nên dùng                                  | Ghi chú                   |
| ------------- | ------------------------------------------------- | ------------------------- |
| `veo3.1-fast` | Lựa chọn mặc định cho hầu hết các clip ngắn       | Tuyến Veo 3.1 nhanh hơn.  |
| `veo3.1`      | Dùng khi bạn muốn cụ thể model Veo 3.1 tiêu chuẩn | Tuyến Veo 3.1 tiêu chuẩn. |

## Chọn chế độ đầu vào

| Mục tiêu       | Trường bắt buộc                      | Trường tùy chọn   |
| -------------- | ------------------------------------ | ----------------- |
| Text-to-video  | `model`, `prompt`                    | `seconds`, `size` |
| Image-to-video | `model`, `prompt`, `input_reference` | `seconds`, `size` |

## Đặt thời lượng và kích thước

Đối với tuyến tương thích OpenAI, dùng `seconds` cho thời lượng và `size` cho kích thước đầu ra. Gửi các giá trị dưới dạng form field.

| Model ID      | `seconds`     | Mặc định             |
| ------------- | ------------- | -------------------- |
| `veo3.1-fast` | `4`, `6`, `8` | `4` giây, `1280x720` |
| `veo3.1`      | `4`, `6`, `8` | `4` giây, `1280x720` |

Đặt `size` thành một trong các giá trị WxH bên dưới.

| Tầng độ phân giải | Tỷ lệ khung hình | `size` (`WxH`) |
| ----------------- | ---------------- | -------------- |
| `720p`            | `16:9`           | `1280x720`     |
|                   | `9:16`           | `720x1280`     |
| `1080p`           | `16:9`           | `1920x1080`    |
| `4K`              | `16:9`           | `3840x2160`    |

## Luồng tác vụ

<Steps>
  <Step title="Tạo tác vụ">
    Gửi yêu cầu biểu mẫu multipart và lưu `id` được trả về.
  </Step>

  <Step title="Thăm dò tác vụ">
    Sử dụng [Veo3 Retrieve](./retrieve) cho đến khi `status` là `completed`, `failed`, hoặc `error`.
  </Step>

  <Step title="Tải xuống kết quả">
    Khi tác vụ ở trạng thái `completed`, hãy tải tệp MP4 xuống từ phản hồi tác vụ đã hoàn tất.
  </Step>
</Steps>


## OpenAPI

````yaml api/openapi/video/veo3/post-create.openapi.json POST /v1/videos
openapi: 3.1.0
info:
  title: Veo 3.1 Async Generation API
  version: 1.0.0
  description: >-
    Create an asynchronous Veo 3.1 video task through CometAPI. Save the
    returned id, poll GET /v1/videos/{task_id}, and download the completed MP4
    file.
servers:
  - url: https://api.cometapi.com
security:
  - bearerAuth: []
paths:
  /v1/videos:
    post:
      summary: Create a Veo 3.1 video task
      description: >-
        Create a Veo 3.1 task through the OpenAI-compatible /v1/videos endpoint.
        Send fields as multipart/form-data.
      operationId: veo3_async_generation
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/VeoCreateRequest'
            examples:
              text_to_video:
                summary: Text-to-video
                value:
                  model: veo3.1-fast
                  prompt: A paper kite floats above a field.
                  seconds: '4'
                  size: 1280x720
      responses:
        '200':
          description: >-
            Task created. Store the returned id and poll GET
            /v1/videos/{task_id}.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/VeoVideoTask'
              example:
                id: task_example
                task_id: task_example
                object: video
                model: veo3.1-fast
                status: queued
                progress: 0
                created_at: 1779938152
        '400':
          description: >-
            The request is missing a required field or contains a value that the
            selected model cannot use.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: The API key is missing or invalid.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
      security:
        - bearerAuth: []
      x-codeSamples:
        - lang: Shell
          label: Text-to-video
          source: |-
            curl https://api.cometapi.com/v1/videos \
              -H "Authorization: Bearer $COMETAPI_KEY" \
              -F model=veo3.1-fast \
              -F 'prompt=A paper kite floats above a field.' \
              -F seconds=4 \
              -F size=1280x720
        - lang: Python
          label: Text-to-video
          source: |
            import os
            import requests

            fields = [
                ("model", (None, "veo3.1-fast")),
                ("prompt", (None, "A paper kite floats above a field.")),
                ("seconds", (None, "4")),
                ("size", (None, "1280x720")),
            ]

            response = requests.post(
                "https://api.cometapi.com/v1/videos",
                headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
                files=fields,
                timeout=120,
            )

            response.raise_for_status()
            print(response.json())
        - lang: JavaScript
          label: Text-to-video
          source: |
            const form = new FormData();
            form.append("model", "veo3.1-fast");
            form.append("prompt", "A paper kite floats above a field.");
            form.append("seconds", "4");
            form.append("size", "1280x720");

            const response = await fetch("https://api.cometapi.com/v1/videos", {
              method: "POST",
              headers: { Authorization: `Bearer ${process.env.COMETAPI_KEY}` },
              body: form,
            });

            const result = await response.json();
            console.log(result);
components:
  schemas:
    VeoCreateRequest:
      type: object
      required:
        - model
        - prompt
      properties:
        model:
          type: string
          description: >-
            Veo 3.1 model ID. Use veo3.1-fast for the default route or veo3.1
            when you specifically need the standard model.
          enum:
            - veo3.1-fast
            - veo3.1
          example: veo3.1-fast
        prompt:
          type: string
          description: Text prompt for the video job.
          example: A paper kite floats above a field.
        seconds:
          type: string
          description: >-
            Requested clip duration. Use 4, 6, or 8. Send the value as a form
            field string.
          enum:
            - '4'
            - '6'
            - '8'
          default: '4'
          example: '4'
        size:
          type: string
          description: >-
            Supported WxH size values: 1280x720, 720x1280, 1920x1080, 3840x2160.
            Default is 1280x720.
          example: 1280x720
        input_reference:
          type: string
          format: binary
          description: Optional first-frame image file for image-to-video.
      additionalProperties: true
    VeoVideoTask:
      type: object
      required:
        - id
        - object
        - model
        - status
        - progress
        - created_at
      properties:
        id:
          type: string
          description: Task ID. Use this value with retrieve and content endpoints.
          example: task_example
        task_id:
          type: string
          description: Compatibility alias for id when present.
          example: task_example
        object:
          type: string
          description: Object type. Video tasks return video.
          example: video
        model:
          type: string
          description: Model ID used for the task.
          example: veo3.1-fast
        status:
          type: string
          description: >-
            Task lifecycle status. Poll until the value is completed, failed, or
            error.
          enum:
            - queued
            - in_progress
            - completed
            - failed
            - error
          example: queued
        progress:
          type: integer
          minimum: 0
          maximum: 100
          description: Task progress as a coarse percentage.
          example: 0
        created_at:
          type: integer
          description: Task creation time as a Unix timestamp in seconds.
          example: 1779938152
        completed_at:
          type: integer
          description: >-
            Task completion time as a Unix timestamp in seconds. This field
            appears on completed tasks.
          example: 1779938219
        video_url:
          type: string
          description: Temporary video delivery URL. This field appears on completed tasks.
          example: <temporary-video-url>
        error:
          type: object
          description: Failure details. This field appears when the task fails.
          additionalProperties: true
      additionalProperties: true
    ErrorResponse:
      description: >-
        Error body returned when a request cannot be processed or the task
        fails.
      type: object
      additionalProperties: true
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Bearer authentication. Use your CometAPI API key.

````