> ## 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 một tác vụ image-to-video của Runway

> Sử dụng CometAPI để gọi Runway image_to_video và chuyển đổi URL hình ảnh tĩnh thành đầu ra video thô, với hỗ trợ X-Runway-Version để tương thích.

Sử dụng endpoint này để tạo chuyển động cho một ảnh nguồn thành video Runway.

## Trước khi gọi

* Gửi header `X-Runway-Version` bắt buộc, ví dụ `2024-11-06`
* Sử dụng `model: gen3a_turbo`
* Cung cấp `promptImage` HTTPS ổn định
* Bắt đầu với `duration: 5` và một giá trị ratio được hỗ trợ cho model/phiên bản Runway đã chọn

## Duration và ratio

| Thiết lập                                    | Giá trị được hỗ trợ                                                                                                        | Điểm khởi đầu mặc định | Hành vi ở giới hạn                                                                                                                     |
| -------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- | ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
| `duration`                                   | Phụ thuộc vào model/phiên bản Runway; dùng `5` hoặc `10` để có khả năng tương thích rộng nhất                              | `5`                    | CometAPI chuyển tiếp giá trị này đến Runway. Nếu model/phiên bản đã chọn từ chối nó, hãy thử lại với `5`.                              |
| `ratio` với `X-Runway-Version: 2024-11-06`   | Các giá trị kiểu độ phân giải phụ thuộc vào model/phiên bản Runway như `1280:768`, `768:1280`, `1280:720`, hoặc `720:1280` | `1280:768`             | Các giá trị yêu cầu có thể được chuẩn hóa trong media đã hoàn tất; hãy kiểm tra video hoàn chỉnh trước khi dựa vào số pixel chính xác. |
| `ratio` với các phiên bản tương thích cũ hơn | `16:9`, `9:16`, hoặc các giá trị kiểu độ phân giải được model/phiên bản đã chọn chấp nhận                                  | `16:9` hoặc `1280:768` | Ưu tiên các giá trị kiểu độ phân giải Runway hiện tại cho các tích hợp production.                                                     |

Các request theo định dạng chính thức của Runway sử dụng `ratio`, không phải `size`. Hãy hiểu các giá trị ratio kiểu độ phân giải theo dạng tương đương `WxH` của chúng: `1280:720` nhắm tới `1280x720`, `720:1280` nhắm tới `720x1280`, và `1280:768` vẫn có thể render thành `1280x720` tùy thuộc vào model/phiên bản đã chọn.

## Luồng tác vụ

<Steps>
  <Step title="Gửi request image-to-video">
    Tạo tác vụ với một ảnh nguồn và một motion prompt ngắn tùy chọn.
  </Step>

  <Step title="Lưu id được trả về">
    Lưu `id` của tác vụ để polling sau.
  </Step>

  <Step title="Poll trạng thái tác vụ">
    Sử dụng [Lấy một tác vụ Runway](./runway-to-get-task-details). Nếu lần poll đầu tiên trả về `task_not_exist`, hãy đợi vài giây rồi thử lại.
  </Step>
</Steps>


## OpenAPI

````yaml api/openapi/video/runway/official-format/post-runway-images-raw-video.openapi.json POST /runwayml/v1/image_to_video
openapi: 3.1.0
info:
  title: Image to Video API
  version: 1.0.0
  description: >-
    Create a Runway image-to-video task through the official-format CometAPI
    route.
servers:
  - url: https://api.cometapi.com
security:
  - bearerAuth: []
paths:
  /runwayml/v1/image_to_video:
    post:
      summary: Create a Runway image-to-video task
      description: >-
        Submit a source image plus optional motion prompt and receive a task id
        for later polling.
      operationId: runway_images_raw_video
      parameters:
        - name: X-Runway-Version
          in: header
          required: true
          description: Runway version header, for example `2024-11-06`.
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - promptImage
                - model
              properties:
                promptImage:
                  type: string
                  description: Source image URL.
                  default: >-
                    https://cdn.britannica.com/70/234870-050-D4D024BB/Orange-colored-cat-yawns-displaying-teeth.jpg
                seed:
                  type: integer
                  description: 'Random seed for reproducible results. Range: 0–999999999.'
                model:
                  type: string
                  description: >-
                    Runway image-to-video model ID. Choose an available model
                    from the [Models page](/overview/models).
                  default: gen3a_turbo
                promptText:
                  type: string
                  description: >-
                    Text prompt describing the desired motion or scene. Maximum
                    512 characters.
                watermark:
                  type: boolean
                  description: Whether to add a watermark to the output video.
                  default: false
                duration:
                  type: integer
                  description: >-
                    Video duration in seconds. Runway support is model/version
                    dependent; use 5 or 10 for the broadest compatibility.
                    CometAPI forwards this value to Runway.
                  default: 5
                ratio:
                  type: string
                  description: >-
                    Requested output ratio. Accepted values are Runway
                    model/version dependent. With X-Runway-Version 2024-11-06,
                    use a resolution-style value accepted by the selected model,
                    such as 1280:768, 768:1280, 1280:720, or 720:1280. Read
                    these as WxH targets, but completed media may normalize, so
                    inspect the returned file before relying on exact pixels.
                  default: '1280:768'
              default:
                promptImage: >-
                  https://cdn.britannica.com/70/234870-050-D4D024BB/Orange-colored-cat-yawns-displaying-teeth.jpg
                seed: 1
                model: gen3a_turbo
                promptText: A calm camera move.
                watermark: false
                duration: 5
                ratio: '1280:768'
            examples:
              Default:
                summary: Default
                value:
                  promptImage: >-
                    https://cdn.britannica.com/70/234870-050-D4D024BB/Orange-colored-cat-yawns-displaying-teeth.jpg
                  seed: 1
                  model: gen3a_turbo
                  promptText: A calm camera move.
                  watermark: false
                  duration: 5
                  ratio: '1280:768'
      responses:
        '200':
          description: Task accepted.
          content:
            application/json:
              schema:
                type: object
                required:
                  - id
                properties:
                  id:
                    type: string
                example:
                  id: d0658ae1-bbdd-4adc-aaba-fd8070e14d79
      x-codeSamples:
        - lang: Shell
          label: Default
          source: |
            curl https://api.cometapi.com/runwayml/v1/image_to_video \
              -H "Authorization: Bearer $COMETAPI_KEY" \
              -H "Content-Type: application/json" \
              -d '{
                  "promptImage": "https://your-image-host/first-frame.png",
                  "promptText": "A calm camera move.",
                  "model": "gen3a_turbo",
                  "ratio": "1280:768",
                  "duration": 5
                }'
        - lang: Python
          label: Default
          source: >
            import os

            import requests


            response = requests.post(
                "https://api.cometapi.com/runwayml/v1/image_to_video",
                headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
                json={
                        "promptImage": "https://your-image-host/first-frame.png",
                        "promptText": "A calm camera move.",
                        "model": "gen3a_turbo",
                        "ratio": "1280:768",
                        "duration": 5
                },
            )


            task = response.json()

            print(task["id"])  # poll GET /runwayml/v1/tasks/{id} until the
            output array appears
        - lang: JavaScript
          label: Default
          source: >
            const response = await
            fetch("https://api.cometapi.com/runwayml/v1/image_to_video", {
                method: "POST",
                headers: {
                    Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
                    "Content-Type": "application/json",
                },
                body: JSON.stringify({
                        "promptImage": "https://your-image-host/first-frame.png",
                        "promptText": "A calm camera move.",
                        "model": "gen3a_turbo",
                        "ratio": "1280:768",
                        "duration": 5
                    }),
            });


            const task = await response.json();

            console.log(task.id); // poll GET /runwayml/v1/tasks/{id} until the
            output array appears
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Bearer token authentication. Use your CometAPI key.

````