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

# 创建一个 Runway 图生视频任务

> 使用 CometAPI 调用 Runway image_to_video，将静态图片 URL 转换为原始视频输出，并通过 X-Runway-Version 支持兼容性。

使用此端点可将一张源图片制作成带动画效果的 Runway 视频。

## 调用前准备

* 发送必需的 `X-Runway-Version` 请求头，例如 `2024-11-06`
* 使用 `model: gen3a_turbo`
* 提供稳定可访问的 HTTPS `promptImage`
* 以 `duration: 5` 和所选 Runway model/version 支持的 ratio 值开始

## Duration 和 ratio

| 设置                                          | 支持的值                                                                              | 默认起始值               | 边界行为                                                        |
| ------------------------------------------- | --------------------------------------------------------------------------------- | ------------------- | ----------------------------------------------------------- |
| `duration`                                  | 取决于 Runway model/version；为获得最广泛兼容性，请使用 `5` 或 `10`                                 | `5`                 | CometAPI 会将该值转发给 Runway。如果所选 model/version 拒绝该值，请重试并使用 `5`。 |
| 带有 `X-Runway-Version: 2024-11-06` 的 `ratio` | 取决于 Runway model/version 的分辨率样式值，例如 `1280:768`、`768:1280`、`1280:720` 或 `720:1280` | `1280:768`          | 请求值在最终媒体中可能会发生归一化；在依赖精确像素前，请先检查生成完成的视频。                     |
| 使用较旧兼容版本时的 `ratio`                          | `16:9`、`9:16`，或所选 model/version 接受的分辨率样式值                                         | `16:9` 或 `1280:768` | 在生产集成中，优先使用当前 Runway 的分辨率样式值。                               |

Runway 官方格式请求使用 `ratio`，而不是 `size`。请将分辨率样式的 ratio 值理解为其对应的 `WxH`：`1280:720` 表示目标为 `1280x720`，`720:1280` 表示目标为 `720x1280`，而 `1280:768` 仍可能根据所选 model/version 渲染为 `1280x720`。

## 任务流程

<Steps>
  <Step title="提交图生视频请求">
    使用源图片和可选的简短运动 Prompt 创建任务。
  </Step>

  <Step title="保存返回的 id">
    保存任务 `id` 以便后续轮询。
  </Step>

  <Step title="轮询任务状态">
    使用 [获取一个 Runway 任务](./runway-to-get-task-details)。如果第一次轮询返回 `task_not_exist`，请等待几秒后重试。
  </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.

````