根據圖片生成影片

您可以在 Gemini Enterprise Agent Platform 使用 Gemini Omni 或 Veo,以現有圖片做為第一個影格,生成新影片。如要將圖片的第一個影格轉換為影片,請使用 Gemini Enterprise Agent Platform Media Studio,或使用 Gemini Enterprise Agent Platform 影片生成 API。

下列模型支援根據圖片生成影片:

Gemini Omni

按一下即可展開支援的模型

Veo

按一下即可展開支援的模型

如要進一步瞭解如何撰寫有效的文字提示詞來生成影片,請參閱影片生成提示詞指南。

在 Colab 試用 Gemini Omni Flash

事前準備

  1. In the Cloud de Confiance console, on the project selector page, select or create a Cloud de Confiance project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  2. Enable the Agent Platform API, if it is not already enabled.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the API

  3. 為環境設定驗證機制。

    請根據您打算如何使用本頁範例,選取對應的分頁標籤:

    控制台

    使用 Cloud de Confiance 控制台存取 Cloud de Confiance by S3NS 服務和 API 時,不需要設定驗證。

    REST

    如要在本機開發環境中使用本頁的 REST API 範例,請使用您提供給 gcloud CLI 的憑證。

      安裝 Google Cloud CLI,然後 使用聯合身分登入 gcloud CLI。

    詳情請參閱 Cloud de Confiance 驗證說明文件中的「使用 REST 進行驗證」一節。

使用 Gemini Omni 根據圖片生成影片

REST

影片生成作業可能需要超過一分鐘才能完成。您可以根據工作流程,選擇多種互動模式:

  • 同步:無狀態:在單一要求中生成影片,不必在伺服器上保留互動狀態。
  • 同步:有狀態:將 store 設為 true,即可保留互動狀態,方便您日後擷取結果,或參考互動 ID 進行多輪影片編輯。
  • 同步:有狀態的串流:將 store 和 stream 都設為 true,即可在模型生成想法時逐步接收,然後接收輸出影片。
  • 非同步:將 background 設為 true,即可在背景執行影片生成作業,稍後再使用互動 ID 擷取結果。

儲存和非同步互動資料最多會保留 14 天。

如要進一步瞭解如何使用 Gemini Omni Flash API,請參閱「Interactions API」。

同步:無狀態

使用任何要求資料之前,請先修改下列項目的值:

  • PROJECT_ID:代表 Cloud de Confiance by S3NS 專案 ID 的字串。
  • MODEL_ID:代表要使用的模型 ID 的字串。可接受的值如下:
    • "gemini-omni-1.1-flash-preview"
  • TEXT_PROMPT:用來引導影片生成的文字提示詞。
  • CLOUD_STORAGE_INPUT_URI:代表 Cloud Storage bucket 的字串,其中包含輸入媒體。例如:"gs://video-bucket/input/"。
  • CLOUD_STORAGE_OUTPUT_URI: 選用:代表 Cloud Storage bucket 的字串,用於儲存輸出影片。如未提供,系統會在回應中傳回影片位元組。 例如:"gs://video-bucket/output/"。
  • ASPECT_RATIO: 選用:代表輸出影片預期顯示比例的字串。如未提供,系統會根據提示推論顯示比例。 可接受的值如下:
    • "16:9"
    • "9:16"
  • OUTPUT_RESOLUTION:

    選用:代表影片輸出解析度的字串。如未提供,輸出內容預設為 720p。

    gemini-omni-1.1-flash-preview 支援下列值:

    • "360p"
    • "720p"
    • "1080p"
    • "4k"

    gemini-omni-flash-preview 僅支援 "720p"。

  • DURATION:代表生成影片檔案長度的字串。允許的字串為 3 至 10 之間的整數,後接「s」代表秒。例如 "10s"。

HTTP 方法和網址:

POST https://aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/global/interactions

JSON 要求內文:

{
  "model": "MODEL_ID",
  "input": [
    {
      "type": "text",
      "text": "TEXT_PROMPT"
    },
    {
      "type": "image",
      "uri": "CLOUD_STORAGE_INPUT_URI",
      "mime_type": "image/png"
    }
  ],
  "response_format": [
    {
      "type": "video",
      "delivery": "uri",
      "gcs_uri": "CLOUD_STORAGE_OUTPUT_URI",
      "aspect_ratio": "ASPECT_RATIO",
      "resolution": "OUTPUT_RESOLUTION",
      "duration": "DURATION"
    }
  ],
  "generation_config": {
    "video_config": {
      "task": "image_to_video"
    }
  }
}

如要傳送要求,請選擇以下其中一個選項:

curl

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

curl -X POST \
-H "Authorization: Bearer TOKEN" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/global/interactions"

PowerShell

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

$headers = @{ "Authorization" = "Bearer TOKEN" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/global/interactions" | Select-Object -Expand Content
回覆包含互動,其中有模型想法和輸出影片。
{
  "id":"INTERACTION_ID",
  "model":"gemini-omni-flash-preview",
  "status":"completed",
  "usage":{
    "total_tokens":479,
    "total_input_tokens":26,
    "input_tokens_by_modality":[
      {
        "modality":"text",
        "tokens":26
      },
      {
        "modality":"image",
        "tokens":124
      }
    ],
    "output_tokens_by_modality": [
      {
        "modality": "video",
        "tokens": 28832
      }
    ],
    "total_output_tokens":28832,
    "total_thought_tokens":453
  },
  "steps":[
    {
      "type":"thought",
      "summary":[
        {
          "type":"text",
          "text":"MODEL THOUGHTS"
        }
      ],
    },
    { 
      "type":"model_output",
      "content":[
        {
          "type":"video",
          "uri":"gs://some/output_path/123.mp4",
          "mime_type":"video/mp4" 
        }
      ]
    }
  ],
  "object":"interaction"
  "role":"model",
  "created":"2026-05-29T02:17:56Z",
  "updated":"2026-05-29T02:17:56Z",
}

同步:有狀態

使用任何要求資料之前,請先修改下列項目的值:

  • PROJECT_ID:代表 Cloud de Confiance by S3NS 專案 ID 的字串。
  • MODEL_ID:代表要使用的模型 ID 的字串。可接受的值如下:
    • "gemini-omni-1.1-flash-preview"
  • TEXT_PROMPT:用來引導影片生成的文字提示詞。
  • CLOUD_STORAGE_INPUT_URI:代表 Cloud Storage bucket 的字串,其中包含輸入媒體。例如:"gs://video-bucket/input/"。
  • CLOUD_STORAGE_OUTPUT_URI: 選用:代表 Cloud Storage bucket 的字串,用於儲存輸出影片。如未提供,系統會在回應中傳回影片位元組。 例如:"gs://video-bucket/output/"。
  • ASPECT_RATIO: 選用:代表輸出影片預期顯示比例的字串。如未提供,系統會根據提示推論顯示比例。 可接受的值如下:
    • "16:9"
    • "9:16"
  • OUTPUT_RESOLUTION:

    選用:代表影片輸出解析度的字串。如未提供,輸出內容預設為 720p。

    gemini-omni-1.1-flash-preview 支援下列值:

    • "360p"
    • "720p"
    • "1080p"
    • "4k"

    gemini-omni-flash-preview 僅支援 "720p"。

  • DURATION:代表生成影片檔案長度的字串。允許的字串為 3 至 10 之間的整數,後接「s」代表秒。例如 "10s"。

HTTP 方法和網址:

POST https://aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/global/interactions

JSON 要求內文:

{
  "model": "MODEL_ID",
  "background": false,
  "store": true,
  "stream": false,
  "input": [
    {
      "type": "user_input",
      "content": [
        {
          "type": "text",
          "text": "TEXT_PROMPT"
        },
        {
          "type": "image",
          "uri": "CLOUD_STORAGE_INPUT_URI",
          "mime_type": "image/png"
        }
      ]
    }
  ],
  "response_format": [
    {
      "type": "video",
      "delivery": "uri",
      "gcs_uri": "CLOUD_STORAGE_OUTPUT_URI",
      "aspect_ratio": "ASPECT_RATIO",
      "resolution": "OUTPUT_RESOLUTION",
      "duration": "DURATION"
    }
  ]
}

如要傳送要求,請選擇以下其中一個選項:

curl

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

curl -X POST \
-H "Authorization: Bearer TOKEN" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/global/interactions"

PowerShell

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

$headers = @{ "Authorization" = "Bearer TOKEN" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/global/interactions" | Select-Object -Expand Content
回覆包含互動,其中包含模型想法和輸出影片。
{
  "id":"INTERACTION_ID",
  "model":"gemini-omni-flash-preview",
  "status":"completed",
  "usage":{
    "total_tokens":479,
    "total_input_tokens":26,
    "input_tokens_by_modality":[
      {
        "modality":"text",
        "tokens":26
      },
      {
        "modality":"image",
        "tokens":124
      }
    ],
    "output_tokens_by_modality": [
      {
        "modality": "video",
        "tokens": 28832
      }
    ],
    "total_output_tokens":28832,
    "total_thought_tokens":453
  },
  "steps":[
    {
      "type":"thought",
      "summary":[
        {
          "type":"text",
          "text":"MODEL THOUGHTS"
        }
      ],
    },
    { 
      "type":"model_output",
      "content":[
        {
          "type":"video",
          "uri":"gs://some/output_path/123.mp4",
          "mime_type":"video/mp4" 
        }
      ]
    }
  ],
  "object":"interaction",
  "role":"model",
  "created":"2026-05-29T02:17:56Z",
  "updated":"2026-05-29T02:17:56Z",
}
使用 INTERACTION_ID 取得生成的影片:

使用任何要求資料之前,請先修改下列項目的值:

  • PROJECT_ID:代表 Cloud de Confiance by S3NS 專案 ID 的字串。
  • INTERACTION_ID:非同步要求的互動 ID。

HTTP 方法和網址:

GET https://aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/global/interactions/INTERACTION_ID

如要傳送要求,請選擇以下其中一個選項:

curl

執行下列指令:

curl -X GET \
-H "Authorization: Bearer TOKEN" \
"https://aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/global/interactions/INTERACTION_ID"

PowerShell

執行下列指令:

$headers = @{ "Authorization" = "Bearer TOKEN" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/global/interactions/INTERACTION_ID" | Select-Object -Expand Content
回應格式大致如下:
{
  "id":"INTERACTION_ID",
  "model":"gemini-omni-flash-preview",
  "status":"completed",
  "usage":{
    "total_tokens":479,
    "total_input_tokens":26,
    "input_tokens_by_modality":[
      {
        "modality":"text",
        "tokens":26
      },
      {
        "modality":"image",
        "tokens":124
      }
    ],
    "output_tokens_by_modality": [
      {
        "modality": "video",
        "tokens": 28832
      }
    ],
    "total_output_tokens":28832,
    "total_thought_tokens":453
  },
  "steps":[
    {
      "type": "user_input",
      "content": [
        {
          "type": "text",
          "text": "5 second, 9:16 video. Use the image as the first frame."
        },
        {
          "type": "image",
          "uri": "gs://some/path",
          "mime_type": "image/png"
        }
      ]
    },
    {
      "type":"thought"
      "summary":[
        {
          "type":"text",
          "text":"MODEL THOUGHTS"
        }
      ],
    },
    { 
      "type":"model_output",
      "content":[
        {
          "type":"video",
          "data":"VIDEO DATA",
          "mime_type":"video/mp4" 
        }
      ]
    }
  ],
  "object":"interaction"
  "role":"model",
  "created":"2026-05-29T02:17:56Z",
  "updated":"2026-05-29T02:17:56Z",
}

同步:有狀態的串流

使用任何要求資料之前,請先修改下列項目的值:

  • PROJECT_ID:代表 Cloud de Confiance by S3NS 專案 ID 的字串。
  • MODEL_ID:代表要使用的模型 ID 的字串。可接受的值如下:
    • "gemini-omni-1.1-flash-preview"
  • TEXT_PROMPT:用來引導影片生成的文字提示詞。
  • CLOUD_STORAGE_INPUT_URI:代表 Cloud Storage bucket 的字串,其中包含輸入媒體。例如:"gs://video-bucket/input/"。
  • CLOUD_STORAGE_OUTPUT_URI: 選用:代表 Cloud Storage bucket 的字串,用於儲存輸出影片。如未提供,系統會在回應中傳回影片位元組。 例如:"gs://video-bucket/output/"。
  • ASPECT_RATIO: 選用:代表輸出影片預期顯示比例的字串。如未提供,系統會根據提示推論顯示比例。 可接受的值如下:
    • "16:9"
    • "9:16"
  • OUTPUT_RESOLUTION:

    選用:代表影片輸出解析度的字串。如未提供,輸出內容預設為 720p。

    gemini-omni-1.1-flash-preview 支援下列值:

    • "360p"
    • "720p"
    • "1080p"
    • "4k"

    gemini-omni-flash-preview 僅支援 "720p"。

  • DURATION:代表生成影片檔案長度的字串。允許的字串為 3 至 10 之間的整數,後接「s」代表秒。例如 "10s"。

HTTP 方法和網址:

POST https://aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/global/interactions

JSON 要求內文:

{
  "model": "MODEL_ID",
  "background": false,
  "store": true,
  "stream": true,
  "input": [
    {
      "type": "user_input",
      "content": [
        {
          "type": "text",
          "text": "TEXT_PROMPT"
        },
        {
          "type": "image",
          "uri": "CLOUD_STORAGE_INPUT_URI",
          "mime_type": "image/png"
        }
      ]
    }
  ],
  "response_format": [
    {
      "type": "video",
      "delivery": "uri",
      "gcs_uri": "CLOUD_STORAGE_OUTPUT_URI",
      "aspect_ratio": "ASPECT_RATIO",
      "resolution": "OUTPUT_RESOLUTION",
      "duration": "DURATION"
    }
  ]
}

如要傳送要求,請選擇以下其中一個選項:

curl

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

curl -X POST \
-H "Authorization: Bearer TOKEN" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/global/interactions"

PowerShell

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

$headers = @{ "Authorization" = "Bearer TOKEN" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/global/interactions" | Select-Object -Expand Content
回覆包含互動,其中包含模型想法和輸出影片。
event: interaction.created
data: {"interaction":{"id":"INTERACTION_ID","status":"in_progress","object":"interaction","model":"gemini-omni-flash-preview"},"event_type":"interaction.created"}

event: interaction.status_update
data: {"interaction_id":"INTERACTION_ID","status":"in_progress","event_type":"interaction.status_update"}

event: step.start
data: {"index":0,"step":{"type":"thought"},"event_type":"step.start"}

event: step.delta
data: {"index":0,"delta":{"content":{"text":"MODEL THOUGHTS","type":"text"},"type":"thought_summary"},"event_id":"EVENT_ID","event_type":"step.delta"}

event: step.delta
data: {"index":0,"delta":{"content":{"text":"MODEL THOUGHTS","type":"text"},"type":"thought_summary"},"event_id":"EVENT_ID","event_type":"step.delta"}

event: step.delta
data: {"index":0,"delta":{"signature":"...","type":"thought_signature"},"event_type":"step.delta"}

event: step.stop
data: {"index":0,"event_type":"step.stop"}

event: step.start
data: {"index":1,"step":{"type":"model_output"},"event_type":"step.start"}

event: step.delta
data: {"index":1,"delta":{"mime_type":"video/mp4","uri":"gs://some/output_path/123.mp4","type":"video"},"event_id":"EVENT_ID","event_type":"step.delta"}

event: step.stop
data: {"index":1,"event_type":"step.stop"}

event: interaction.completed
data: {"interaction":{"id":"INTERACTION_ID","status":"completed","usage":{"total_tokens":17812,"total_input_tokens":21,"input_tokens_by_modality":[{"modality":"text","tokens":21}],"total_output_tokens":17376,"output_tokens_by_modality":[{"modality":"video","tokens":17376}],"total_thought_tokens":415},"created":"2026-08-12T21:26:20Z","updated":"2026-08-12T21:26:20Z","event_id":"EVENT_ID","object":"interaction","model":"gemini-omni-flash-preview"},"event_id":"EVENT_ID","event_type":"interaction.completed"}

event: done
data: [DONE]
使用 INTERACTION_ID 和 `?stream=true` 串流儲存的互動和生成的影片:

使用任何要求資料之前,請先修改下列項目的值:

  • PROJECT_ID:代表 Cloud de Confiance by S3NS 專案 ID 的字串。
  • INTERACTION_ID:要求中的互動 ID。

HTTP 方法和網址:

GET https://aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/global/interactions/INTERACTION_ID?stream=true

如要傳送要求,請選擇以下其中一個選項:

curl

執行下列指令:

curl -X GET \
-H "Authorization: Bearer TOKEN" \
"https://aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/global/interactions/INTERACTION_ID?stream=true"

PowerShell

執行下列指令:

$headers = @{ "Authorization" = "Bearer TOKEN" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/global/interactions/INTERACTION_ID?stream=true" | Select-Object -Expand Content
回應是伺服器傳送事件 (SSE) 串流,格式類似於以下內容:
event: interaction.created
data: {"interaction":{"id":"INTERACTION_ID","status":"in_progress","object":"interaction","model":"gemini-omni-flash-preview"},"event_type":"interaction.created"}

event: interaction.status_update
data: {"interaction_id":"INTERACTION_ID","status":"in_progress","event_type":"interaction.status_update"}

event: step.start
data: {"index":0,"step":{"type":"thought"},"event_type":"step.start"}

event: step.delta
data: {"index":0,"delta":{"content":{"text":"MODEL THOUGHTS","type":"text"},"type":"thought_summary"},"event_id":"EVENT_ID","event_type":"step.delta"}

event: step.delta
data: {"index":0,"delta":{"content":{"text":"MODEL THOUGHTS","type":"text"},"type":"thought_summary"},"event_id":"EVENT_ID","event_type":"step.delta"}

event: step.delta
data: {"index":0,"delta":{"signature":"...","type":"thought_signature"},"event_type":"step.delta"}

event: step.stop
data: {"index":0,"event_type":"step.stop"}

event: step.start
data: {"index":1,"step":{"type":"model_output"},"event_type":"step.start"}

event: step.delta
data: {"index":1,"delta":{"mime_type":"video/mp4","uri":"gs://some/output_path/123.mp4","type":"video"},"event_id":"EVENT_ID","event_type":"step.delta"}

event: step.stop
data: {"index":1,"event_type":"step.stop"}

event: interaction.completed
data: {"interaction":{"id":"INTERACTION_ID","status":"completed","usage":{"total_tokens":17664,"total_input_tokens":21,"input_tokens_by_modality":[{"modality":"text","tokens":21}],"total_output_tokens":17376,"output_tokens_by_modality":[{"modality":"video","tokens":17376}],"total_thought_tokens":267},"created":"2026-08-12T21:33:08Z","updated":"2026-08-12T21:33:08Z","event_id":"EVENT_ID","object":"interaction","model":"gemini-omni-flash-preview"},"event_id":"EVENT_ID","event_type":"interaction.completed"}

event: done
data: [DONE]

非同步

使用任何要求資料之前,請先修改下列項目的值:

  • PROJECT_ID:代表 Cloud de Confiance by S3NS 專案 ID 的字串。
  • MODEL_ID:代表要使用的模型 ID 的字串。可接受的值如下:
    • "gemini-omni-1.1-flash-preview"
  • TEXT_PROMPT:用來引導影片生成的文字提示詞。
  • CLOUD_STORAGE_INPUT_URI:代表 Cloud Storage bucket 的字串,其中包含輸入媒體。例如:"gs://video-bucket/input/"。
  • CLOUD_STORAGE_OUTPUT_URI: 選用:代表 Cloud Storage bucket 的字串,用於儲存輸出影片。如未提供,系統會在回應中傳回影片位元組。 例如:"gs://video-bucket/output/"。
  • ASPECT_RATIO: 選用:代表輸出影片預期顯示比例的字串。如未提供,系統會根據提示推論顯示比例。 可接受的值如下:
    • "16:9"
    • "9:16"
  • OUTPUT_RESOLUTION:

    選用:代表影片輸出解析度的字串。如未提供,輸出內容預設為 720p。

    gemini-omni-1.1-flash-preview 支援下列值:

    • "360p"
    • "720p"
    • "1080p"
    • "4k"

    gemini-omni-flash-preview 僅支援 "720p"。

  • DURATION:代表生成影片檔案長度的字串。允許的字串為 3 至 10 之間的整數,後接「s」代表秒。例如 "10s"。

HTTP 方法和網址:

POST https://aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/global/interactions

JSON 要求內文:

{
  "model": "MODEL_ID",
  "input": [
    {
      "background": true,
      "type": "text",
      "text": "TEXT_PROMPT"
    },
    {
      "type": "image",
      "uri": "CLOUD_STORAGE_INPUT_URI",
      "mime_type": "image/png"
    }
  ],
  "response_format": [
    {
      "type": "video",
      "delivery": "uri",
      "gcs_uri": "CLOUD_STORAGE_OUTPUT_URI",
      "aspect_ratio": "ASPECT_RATIO",
      "resolution": "OUTPUT_RESOLUTION",
      "duration": "DURATION"
    }
  ],
  "generation_config": {
    "video_config": {
      "task": "image_to_video"
    }
  }
}

如要傳送要求,請選擇以下其中一個選項:

curl

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

curl -X POST \
-H "Authorization: Bearer TOKEN" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/global/interactions"

PowerShell

將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

$headers = @{ "Authorization" = "Bearer TOKEN" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/global/interactions" | Select-Object -Expand Content
回應中包含互動 ID,可用於取得生成的影片。
{
  "id":"INTERACTION_ID",
  "status":"in_progress",
  "object":"interaction"
}
之後,使用 INTERACTION_ID 取得生成的影片:

使用任何要求資料之前,請先修改下列項目的值:

  • PROJECT_ID:代表 Cloud de Confiance by S3NS 專案 ID 的字串。
  • INTERACTION_ID:非同步要求的互動 ID。

HTTP 方法和網址:

GET https://aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/global/interactions/INTERACTION_ID

如要傳送要求,請選擇以下其中一個選項:

curl

執行下列指令:

curl -X GET \
-H "Authorization: Bearer TOKEN" \
"https://aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/global/interactions/INTERACTION_ID"

PowerShell

執行下列指令:

$headers = @{ "Authorization" = "Bearer TOKEN" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/global/interactions/INTERACTION_ID" | Select-Object -Expand Content
回應格式大致如下:
{
  "id":"INTERACTION_ID",
  "model":"gemini-omni-flash-preview",
  "status":"completed",
  "usage":{
    "total_tokens":479,
    "total_input_tokens":26,
    "input_tokens_by_modality":[
      {
        "modality":"text",
        "tokens":26
      },
      {
        "modality":"image",
        "tokens":124
      }
    ],
    "output_tokens_by_modality": [
      {
        "modality": "video",
        "tokens": 28832
      }
    ],
    "total_output_tokens":28832,
    "total_thought_tokens":453
  },
  "steps":[
    {
      "type": "user_input",
      "content": [
        {
          "type": "text",
          "text": "5 second, 9:16 video. Use the image as the first frame."
        },
        {
          "type": "image",
          "uri": "gs://some/path",
          "mime_type": "image/png"
        }
      ]
    },
    {
      "type":"thought"
      "summary":[
        {
          "type":"text",
          "text":"MODEL THOUGHTS"
        }
      ],
    },
    { 
      "type":"model_output",
      "content":[
        {
          "type":"video",
          "data":"VIDEO DATA",
          "mime_type":"video/mp4" 
        }
      ]
    }
  ],
  "object":"interaction"
  "role":"model",
  "created":"2026-05-29T02:17:56Z",
  "updated":"2026-05-29T02:17:56Z",
}

使用 Veo 根據圖片生成影片

輸入內容範例 輸出內容範例
  1. 輸入圖片1
    輸入圖片:鉤針編織大象的 PNG 檔案
  2. 文字提示詞:大象自然地四處走動

輸出影片:鉤織大象

1 根據提示生成的圖像:一隻編織大象,身上有複雜的花紋,在熱帶草原上行走

只要輸入圖片,或圖片和描述性文字,就能生成新影片。下列範例提供基本操作說明,說明如何根據圖片和文字生成影片。

控制台

  1. 在 Cloud de Confiance 控制台中,依序前往 「Agent Platform」 > 「Media Studio」頁面。

    Media Studio

  2. 按一下「影片」。

  3. 在「Task」選單中,選取「Image-to-video」。

  4. 從「Model」(模型) 選單中,選取顯示的任一選項。

  5. 在「Prompt」(提示) 方塊中,輸入文字提示詞,描述要生成的影片。

  6. 在「輸入圖片」部分中,按一下「開始」,上傳第一格的圖片。

  7. 選用:按一下「結束」,上傳最後一格的圖片。

  8. 選用:調整下列參數:

    • 顯示比例:選擇 16:9 或 9:16。

    • 結果數量:調整滑桿或輸入介於 1 至 4 的值。

    • 影片長度:從選單中選取影片長度。

    • 輸出目錄:按一下「瀏覽」,建立或選取Cloud Storage bucket,用來儲存產生的檔案。

  9. 按一下「執行」。

Python

安裝

pip install --upgrade google-genai

詳情請參閱 SDK 參考文件。

設定環境變數,以便透過 Vertex AI 使用 Google Gen AI SDK:

# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values
# with appropriate values for your project.
export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT
export GOOGLE_CLOUD_LOCATION=global
export GOOGLE_GENAI_USE_ENTERPRISE=True

import time
from google import genai
from google.genai.types import GenerateVideosConfig, Image

client = genai.Client()

# TODO(developer): Update and un-comment below line
# output_gcs_uri = "gs://your-bucket/your-prefix"

operation = client.models.generate_videos(
    model="veo-3.1-generate-001",
    prompt="Extreme close-up of a cluster of vibrant wildflowers swaying gently in a sun-drenched meadow.",
    image=Image(
        gcs_uri="gs://cloud-samples-data/generative-ai/image/flowers.png",
        mime_type="image/png",
    ),
    config=GenerateVideosConfig(
        aspect_ratio="16:9",
        output_gcs_uri=output_gcs_uri,
    ),
)

while not operation.done:
    time.sleep(15)
    operation = client.operations.get(operation)
    print(operation)

if operation.response:
    print(operation.result.generated_videos[0].video.uri)

# Example response:
# gs://your-bucket/your-prefix

Go

瞭解如何安裝或更新 Go。

詳情請參閱 SDK 參考文件。

設定環境變數,以便透過 Vertex AI 使用 Google Gen AI SDK:

# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values
# with appropriate values for your project.
export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT
export GOOGLE_CLOUD_LOCATION=global
export GOOGLE_GENAI_USE_ENTERPRISE=True

import (
	"context"
	"fmt"
	"io"
	"time"

	"google.golang.org/genai"
)

// generateVideoFromImage shows how to gen video from img.
func generateVideoFromImage(w io.Writer, outputGCSURI string) error {
	//outputGCSURI = "gs://your-bucket/your-prefix"
	ctx := context.Background()

	client, err := genai.NewClient(ctx, &genai.ClientConfig{
		HTTPOptions: genai.HTTPOptions{APIVersion: "v1"},
	})
	if err != nil {
		return fmt.Errorf("failed to create genai client: %w", err)
	}

	image := &genai.Image{
		GCSURI:   "gs://cloud-samples-data/generative-ai/image/flowers.png",
		MIMEType: "image/png",
	}

	config := &genai.GenerateVideosConfig{
		AspectRatio:  "16:9",
		OutputGCSURI: outputGCSURI,
	}

	modelName := "veo-3.0-generate-preview"
	prompt := "Extreme close-up of a cluster of vibrant wildflowers swaying gently in a sun-drenched meadow."
	operation, err := client.Models.GenerateVideos(ctx, modelName, prompt, image, config)
	if err != nil {
		return fmt.Errorf("failed to start video generation: %w", err)
	}

	// Polling until the operation is done
	for !operation.Done {
		time.Sleep(15 * time.Second)
		operation, err = client.Operations.GetVideosOperation(ctx, operation, nil)
		if err != nil {
			return fmt.Errorf("failed to get operation status: %w", err)
		}
	}

	if operation.Response != nil && len(operation.Response.GeneratedVideos) > 0 {
		videoURI := operation.Response.GeneratedVideos[0].Video.URI
		fmt.Fprintln(w, videoURI)
		return nil
	}

	// Example response:
	// gs://your-bucket/your-prefix/videoURI

	return fmt.Errorf("video generation failed or returned no results")
}

Node.js

安裝

npm install @google/genai

詳情請參閱 SDK 參考文件。

設定環境變數,以便透過 Vertex AI 使用 Google Gen AI SDK:

# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values
# with appropriate values for your project.
export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT
export GOOGLE_CLOUD_LOCATION=global
export GOOGLE_GENAI_USE_ENTERPRISE=True

const {GoogleGenAI} = require('@google/genai');

const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT;
const GOOGLE_CLOUD_LOCATION = process.env.GOOGLE_CLOUD_LOCATION || 'global';

async function generateVideo(
  outputGcsUri,
  projectId = GOOGLE_CLOUD_PROJECT,
  location = GOOGLE_CLOUD_LOCATION
) {
  const client = new GoogleGenAI({
    vertexai: true,
    project: projectId,
    location: location,
  });

  let operation = await client.models.generateVideos({
    model: 'veo-3.1-fast-generate-001',
    prompt:
      'Extreme close-up of a cluster of vibrant wildflowers swaying gently in a sun-drenched meadow',
    image: {
      gcsUri: 'gs://cloud-samples-data/generative-ai/image/flowers.png',
      mimeType: 'image/png',
    },
    config: {
      aspectRatio: '16:9',
      outputGcsUri: outputGcsUri,
    },
  });

  while (!operation.done) {
    await new Promise(resolve => setTimeout(resolve, 15000));
    operation = await client.operations.get({operation: operation});
    console.log(operation);
  }

  if (operation.response) {
    console.log(operation.response.generatedVideos[0].video.uri);
  }
  return operation;
}

Java

瞭解如何安裝或更新 Java。

詳情請參閱 SDK 參考文件。

設定環境變數,以便透過 Vertex AI 使用 Google Gen AI SDK:

# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values
# with appropriate values for your project.
export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT
export GOOGLE_CLOUD_LOCATION=global
export GOOGLE_GENAI_USE_ENTERPRISE=True


import com.google.genai.Client;
import com.google.genai.types.GenerateVideosConfig;
import com.google.genai.types.GenerateVideosOperation;
import com.google.genai.types.GenerateVideosResponse;
import com.google.genai.types.GeneratedVideo;
import com.google.genai.types.GetOperationConfig;
import com.google.genai.types.Image;
import com.google.genai.types.Video;
import java.util.concurrent.TimeUnit;

public class VideoGenWithImg {

  public static void main(String[] args) throws InterruptedException {
    // TODO(developer): Replace these variables before running the sample.
    String modelId = "veo-3.1-generate-001";
    String outputGcsUri = "gs://your-bucket/your-prefix";
    generateContent(modelId, outputGcsUri);
  }

  // Generates a video with an image and a text prompt.
  public static String generateContent(String modelId, String outputGcsUri)
      throws InterruptedException {
    // Client Initialization. Once created, it can be reused for multiple requests.
    try (Client client = Client.builder().location("global").vertexAI(true).build()) {

      GenerateVideosOperation operation =
          client.models.generateVideos(
              modelId,
              "Extreme close-up of a cluster of vibrant wildflowers"
                  + " swaying gently in a sun-drenched meadow.",
              Image.builder()
                  .gcsUri("gs://cloud-samples-data/generative-ai/image/flowers.png")
                  .mimeType("image/png")
                  .build(),
              GenerateVideosConfig.builder()
                  .aspectRatio("16:9")
                  .outputGcsUri(outputGcsUri)
                  .build());

      while (!operation.done().orElse(false)) {
        TimeUnit.SECONDS.sleep(15);
        operation =
            client.operations.getVideosOperation(operation, GetOperationConfig.builder().build());
      }

      String generatedVideoUri =
          operation
              .response()
              .flatMap(GenerateVideosResponse::generatedVideos)
              .flatMap(videos -> videos.stream().findFirst())
              .flatMap(GeneratedVideo::video)
              .flatMap(Video::uri)
              .orElseThrow(
                  () ->
                      new IllegalStateException(
                          "Could not get the URI from the generated video"));

      System.out.println("Generated video URI: " + generatedVideoUri);
      // Example response:
      // Generated video URI: gs://your-bucket/your-prefix/generated-video-123.mp4
      return generatedVideoUri;
    }
  }
}

REST

如要進一步瞭解 Veo API,請參閱下列資源:

  1. 使用下列指令傳送影片生成要求。這項要求會啟動長時間執行的作業,並將輸出內容儲存至您指定的 Cloud Storage bucket。

    使用任何要求資料之前,請先修改下列項目的值:

    • PROJECT_ID:代表 Cloud de Confiance by S3NS 專案 ID 的字串。
    • MODEL_ID:代表要使用的模型 ID 的字串。可接受的值如下:
      • Veo 2:veo-2.0-generate-001
      • Veo 3:veo-3.0-generate-001
      • Veo 3.1:veo-3.1-generate-001
      • Veo 3.1:veo-3.1-fast-generate-001
    • TEXT_PROMPT:用於引導影片生成的文字提示詞。
    • INPUT_IMAGE:代表輸入圖片的 Base64 編碼字串。為獲得最佳品質,建議輸入圖片的解析度為 720p (1280 x 720 像素) 以上,且長寬比為 16:9 或 9:16。如果上傳的圖片採用其他顯示比例或大小,系統可能會調整圖片大小或從中央裁剪。
    • MIME_TYPE:代表輸入圖片 MIME 類型的字串。僅支援下列 MIME 類型的圖片:
      • "image/jpeg"
      • "image/png"
    • OUTPUT_STORAGE_URI:選用:代表 Cloud Storage bucket 的字串,用於儲存輸出影片。如未提供,回應中會傳回影片位元組。例如:"gs://video-bucket/output/"。
    • RESIZE_MODE:代表要使用的大小調整模式的字串。可接受的值如下:
      • "crop":裁剪影片,配合新尺寸。
      • "pad":在影片中加入邊框,以符合新尺寸。
    • RESPONSE_COUNT: 要生成的影片檔案數量。可接受的值範圍為 1-4。
    • DURATION:代表生成影片檔案長度的整數。以下是各模型可接受的值:
      • Veo 2 模型:5-8。預設值為 8。
      • Veo 3 模型:4、6 或 8。預設值為 8。
    • 其他選用參數

      視用途而定,使用下列選用變數。在 "parameters": {} 物件中新增下列部分或所有參數。

      "parameters": {
        "aspectRatio": "ASPECT_RATIO",
        "negativePrompt": "NEGATIVE_PROMPT",
        "personGeneration": "PERSON_SAFETY_SETTING",
        // "resolution": RESOLUTION, // Veo 3 models only
        "sampleCount": RESPONSE_COUNT,
        "seed": SEED_NUMBER
      }
      • ASPECT_RATIO: 選用:描述生成影片顯示比例的字串值。您可以使用下列值:
        • "16:9" 橫向
        • "9:16" 個直向媒體

        預設值為 "16:9"

      • NEGATIVE_PROMPT:選用:字串值,說明您要禁止模型生成哪些內容。
      • PERSON_SAFETY_SETTING: 選用:字串值,可控制生成人物或臉部的安全設定。您可以使用下列值:
        • "allow_adult":只允許生成成人人物和臉孔。
        • "disallow":不會生成人物或臉孔。

        預設值為 "allow_adult"。

      • RESOLUTION:選用。控制生成影片解析度的字串值。僅支援 Veo 3 模型。您可以使用下列值:
        • "720p"
        • "1080p"
        • "4k" (僅限 Veo 3.1 預先發布版模型)

        預設值為 "720p"。

      • RESPONSE_COUNT: 選用。描述要生成影片數量的整數值。 可接受的值範圍為 1 到 4。
      • SEED_NUMBER: 選用。模型會使用 uint32 值生成確定性影片。在要求中指定種子編號,但不變更其他參數,模型就會生成相同的影片。可接受的值範圍為 0 到 4294967295。

    HTTP 方法和網址:

    POST https://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/publishers/google/models/MODEL_ID:predictLongRunning

    JSON 要求內文:

    {
      "instances": [
        {
          "prompt": "TEXT_PROMPT",
          "image": {
            "bytesBase64Encoded": "INPUT_IMAGE",
            "mimeType": "MIME_TYPE"
          }
        }
      ],
      "parameters": {
        "storageUri": "OUTPUT_STORAGE_URI",
        "sampleCount": RESPONSE_COUNT
        "resizeMode": "RESIZE_MODE"
      }
    }
    

    如要傳送要求,請選擇以下其中一個選項:

    curl

    將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

    curl -X POST \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json; charset=utf-8" \
    -d @request.json \
    "https://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/publishers/google/models/MODEL_ID:predictLongRunning"

    PowerShell

    將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

    $cred = gcloud auth print-access-token
    $headers = @{ "Authorization" = "Bearer $cred" }

    Invoke-WebRequest `
    -Method POST `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/publishers/google/models/MODEL_ID:predictLongRunning" | Select-Object -Expand Content
    這項要求會傳回包含專屬作業 ID 的完整作業名稱。使用這個完整作業名稱輪詢影片生成要求的狀態。
    {
      "name": "projects/PROJECT_ID/locations/us-central1/publishers/google/models/MODEL_ID/operations/a1b07c8e-7b5a-4aba-bb34-3e1ccb8afcc8"
    }
    

  2. 選用:檢查影片生成長時間執行作業的狀態。

    使用任何要求資料之前,請先修改下列項目的值:

    • PROJECT_ID:您的 Cloud de Confiance by S3NS 專案 ID。
    • MODEL_ID:要使用的模型 ID。
    • OPERATION_ID:原始生成影片要求中傳回的專屬作業 ID。

    HTTP 方法和網址:

    POST https://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/publishers/google/models/MODEL_ID:fetchPredictOperation

    JSON 要求內文:

    {
      "operationName": "projects/PROJECT_ID/locations/us-central1/publishers/google/models/MODEL_ID/operations/OPERATION_ID"
    }
    

    如要傳送要求,請選擇以下其中一個選項:

    curl

    將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

    curl -X POST \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json; charset=utf-8" \
    -d @request.json \
    "https://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/publishers/google/models/MODEL_ID:fetchPredictOperation"

    PowerShell

    將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:

    $cred = gcloud auth print-access-token
    $headers = @{ "Authorization" = "Bearer $cred" }

    Invoke-WebRequest `
    -Method POST `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/publishers/google/models/MODEL_ID:fetchPredictOperation" | Select-Object -Expand Content
    這項要求會傳回作業相關資訊,包括作業是否仍在執行或已完成。

後續步驟