延長影片

您可以在 Gemini Enterprise Agent Platform 使用 Gemini Omni 或 Veo 延伸影片。使用 Gemini Omni 時,您可以提供任何長度的輸入影片,模型最多會使用最後 10 秒的內容,生成 3 到 10 秒的延伸內容,並串連至輸入影片最後 30 秒的內容 (總輸出長度最多 40 秒)。使用 Veo 時,輸入影片長度必須介於 1 到 30 秒之間,且最多可延長 7 秒 (總長度最多 37 秒)。您可以使用 Cloud de Confiance 控制台或 Agent Platform API 延長影片。

下列模型支援延長影片:

Gemini Omni

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

Veo

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

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

在 Colab 試用 Gemini Omni

事前準備

  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 進行驗證」一節。

Veo 限制

使用 Veo 延長影片時,輸入影片須符合下列限制:

  • 輸入檔案必須是 MP4。
  • 長度必須介於 1 到 30 秒。
  • 影格速率必須為每秒 24 個影格。
  • 解析度必須為 720p、1080p 或 4k。
  • 輸入影片的顯示比例可為 9:16 或 16:9。

使用 Veo 延長影片時,輸出影片會受到下列限制:

  • 輸出檔案為 MP4。
  • 延長時間長度為 7 秒。
  • 影格率為每秒 24 個影格。
  • 解析度可以是 720p、1080p 或 4k。
  • 輸出影片的顯示比例可為 9:16 或 16:9。

使用 Gemini Omni 延長影片

如要使用 Gemini Omni 延長影片,請提供任意長度的輸入影片,並輸入文字提示詞,描述要接續的內容 (3 到 10 秒)。模型最多會使用輸入影片的最後 10 秒生成延伸內容,並將生成的影片串連至輸入影片的最後 30 秒 (例如,將 60 秒的輸入影片延長 10 秒,會產生 40 秒的輸出影片)。使用 gemini-omni-1.2-flash 時,您也可以在 input 陣列中加入最多兩張選用的參考圖像 ("type": "image"),引導擴充片段、指定 generation_config.seed 以取得可重現的結果,以及附加自訂中繼資料標籤 (labels),以便整理要求及追蹤已計費用。

REST

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

  • 同步:無狀態:將 store 設為 false,即可在單一要求中生成影片,而不會在伺服器上保留互動狀態。
  • 同步:有狀態:將 store 設為 true,即可保留互動狀態,以便日後擷取結果,或參照互動 ID 進行多輪影片編輯。
  • 同步:有狀態串流:將 store 和 stream 設為 true,即可在模型生成思考過程時逐步接收,並在單一 step.delta 事件 ("type": "video") 中接收輸出影片。
  • 非同步:將 background 設為 true,在背景執行影片生成作業,並在稍後使用互動 ID 擷取結果。

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

在 response_format 中設定 "delivery": "uri" 時,也必須指定 gcs_uri。如果 "delivery" 為 "uri",省略 gcs_uri 會傳回 400 INVALID_ARGUMENT 錯誤。

一元回應會在 steps[].content[].uri 中傳回 Cloud Storage URI,串流回應則會在 delta.uri 中傳回。如要改為在回應中內嵌傳回影片位元組,請設定 "delivery": "inline" 並省略 gcs_uri ("delivery" 為 "inline" 時不支援 gcs_uri)。使用內嵌傳送時,影片輸出會以 base64 編碼位元組字串的形式傳回,並與 steps[].content[].data (一元 POST 和 GET) 或 delta.data (SSE step.delta) 中的 "mime_type": "video/mp4" 一起傳回。與文字或音訊差異不同,內嵌影片不會在多個 step.delta 事件中分塊,每個生成的影片都會在一個 step.delta 事件中以單一完整的 base64 酬載傳送。

如果是大型或高解析度影片,請搭配使用 "delivery": "uri" 和 gcs_uri,避免大型 HTTP 或單一事件 SSE 回應酬載。

如要進一步瞭解如何搭配使用 Gemini Omni 模型和 Interactions API,請參閱「Interactions API」。

同步:無狀態

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

  • PROJECT_ID:代表 Cloud de Confiance by S3NS 專案 ID 的字串。
  • MODEL_ID:代表要使用的模型 ID 的字串。可接受的值如下:
    • "gemini-omni-1.2-flash"
    • "gemini-omni-1.1-flash-preview"
  • TEXT_PROMPT:用於引導影片生成的文字提示詞。
  • CLOUD_STORAGE_VIDEO_URI:代表 Cloud Storage bucket 的字串,其中包含輸入影片。例如:"gs://video-bucket/input/"。
  • VIDEO_MIME:代表影片 MIME 類型的字串。可接受的值如下:
    • video/3gpp
    • video/mp4
    • video/mpeg
    • video/quicktime
    • video/webm
    • video/x-flv
    • video/x-ms-wmv
  • CLOUD_STORAGE_OUTPUT_URI:代表 Cloud Storage bucket 的字串,用於儲存輸出影片 (例如 "gs://video-bucket/output/")。如果 delivery 設為 "uri",則必須提供這個參數。如要改為在回覆中傳回影片位元組,請設定 "delivery": "inline",並從 response_format 省略 gcs_uri。
  • ASPECT_RATIO:選用。代表輸出影片預期顯示比例的字串。如未提供,系統會根據提示推論顯示比例。 可接受的值如下:
    • "16:9"
    • "9:16"
  • DURATION:代表生成影片檔案長度的字串。允許的字串為 3 至 10 之間的整數,後接「s」代表秒。例如 "10s"。

HTTP 方法和網址:

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

JSON 要求內文:

{
  "model": "MODEL_ID",
  "store": false,
  "input": [
    {
      "type": "text",
      "text": "TEXT_PROMPT"
    },
    {
      "type": "video",
      "uri": "CLOUD_STORAGE_VIDEO_URI",
      "mime_type": "VIDEO_MIME"
    }
  ],
  "response_format": [
    {
      "type": "video",
      "delivery": "uri",
      "gcs_uri": "CLOUD_STORAGE_OUTPUT_URI",
      "aspect_ratio": "ASPECT_RATIO",
      "duration": "DURATION"
    }
  ],
  "generation_config": {
    "video_config": {
      "task": "extend"
    }
  }
}

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

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-1.2-flash",
  "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.2-flash"
    • "gemini-omni-1.1-flash-preview"
  • TEXT_PROMPT:用於引導影片生成的文字提示詞。
  • CLOUD_STORAGE_VIDEO_URI:代表 Cloud Storage bucket 的字串,其中包含輸入影片。例如:"gs://video-bucket/input/"。
  • VIDEO_MIME:代表影片 MIME 類型的字串。可接受的值如下:
    • video/3gpp
    • video/mp4
    • video/mpeg
    • video/quicktime
    • video/webm
    • video/x-flv
    • video/x-ms-wmv
  • CLOUD_STORAGE_OUTPUT_URI:代表 Cloud Storage bucket 的字串,用於儲存輸出影片 (例如 "gs://video-bucket/output/")。如果 delivery 設為 "uri",則必須提供這個參數。如要改為在回覆中傳回影片位元組,請設定 "delivery": "inline",並從 response_format 省略 gcs_uri。
  • ASPECT_RATIO:選用。代表輸出影片預期顯示比例的字串。如未提供,系統會根據提示推論顯示比例。 可接受的值如下:
    • "16:9"
    • "9:16"
  • 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": "video",
          "uri": "CLOUD_STORAGE_VIDEO_URI",
          "mime_type": "VIDEO_MIME"
        }
      ]
    }
  ],
  "response_format": [
    {
      "type": "video",
      "delivery": "uri",
      "gcs_uri": "CLOUD_STORAGE_OUTPUT_URI",
      "aspect_ratio": "ASPECT_RATIO",
      "duration": "DURATION"
    }
  ],
  "generation_config": {
    "video_config": {
      "task": "extend"
    }
  }
}

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

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-1.2-flash",
  "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-1.2-flash",
  "status":"completed",
  "usage":{
    "total_tokens":29435,
    "total_input_tokens":150,
    "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",
          "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"
}

使用內嵌傳送時 ("delivery": "inline",省略 gcs_uri),model_output 步驟會傳回完整影片,做為 steps[].content[].data 中 "mime_type": "video/mp4" 旁的 Base64 編碼位元組字串,而非 uri:

{
  "type": "model_output",
  "content": [
    {
      "type": "video",
      "data": "BASE64_ENCODED_VIDEO",
      "mime_type": "video/mp4"
    }
  ]
}

同步:有狀態串流

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

  • PROJECT_ID:代表 Cloud de Confiance by S3NS 專案 ID 的字串。
  • MODEL_ID:代表要使用的模型 ID 的字串。可接受的值如下:
    • "gemini-omni-1.2-flash"
    • "gemini-omni-1.1-flash-preview"
  • TEXT_PROMPT:用於引導影片生成的文字提示詞。
  • CLOUD_STORAGE_VIDEO_URI:代表 Cloud Storage bucket 的字串,其中包含輸入影片。例如:"gs://video-bucket/input/"。
  • VIDEO_MIME:代表影片 MIME 類型的字串。可接受的值如下:
    • video/3gpp
    • video/mp4
    • video/mpeg
    • video/quicktime
    • video/webm
    • video/x-flv
    • video/x-ms-wmv
  • CLOUD_STORAGE_OUTPUT_URI:代表 Cloud Storage bucket 的字串,用於儲存輸出影片 (例如 "gs://video-bucket/output/")。如果 delivery 設為 "uri",則必須提供這個參數。如要改為在回覆中傳回影片位元組,請設定 "delivery": "inline",並從 response_format 省略 gcs_uri。
  • ASPECT_RATIO:選用。代表輸出影片預期顯示比例的字串。如未提供,系統會根據提示推論顯示比例。 可接受的值如下:
    • "16:9"
    • "9:16"
  • 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": "video",
          "uri": "CLOUD_STORAGE_VIDEO_URI",
          "mime_type": "VIDEO_MIME"
        }
      ]
    }
  ],
  "response_format": [
    {
      "type": "video",
      "delivery": "uri",
      "gcs_uri": "CLOUD_STORAGE_OUTPUT_URI",
      "aspect_ratio": "ASPECT_RATIO",
      "duration": "DURATION"
    }
  ],
  "generation_config": {
    "video_config": {
      "task": "extend"
    }
  }
}

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

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-1.2-flash"},"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-1.2-flash"},"event_id":"EVENT_ID","event_type":"interaction.completed"}

event: done
data: [DONE]

使用內嵌傳送時 ("delivery": "inline",省略 gcs_uri),影片 step.delta 事件會傳回 delta.data 中的影片位元組,做為 base64 編碼字串,並與 "mime_type": "video/mp4" 一起傳回,而不是 delta.uri:

event: step.delta
data: {"index":1,"delta":{"mime_type":"video/mp4","data":"BASE64_ENCODED_VIDEO","type":"video"},"event_id":"EVENT_ID","event_type":"step.delta"}

與文字 ("type": "text") 或音訊 ("type": "audio") 差異不同,內嵌影片不會在多個 step.delta 事件中分塊。每個生成的影片都會在一個 step.delta 事件 ("type": "video") 中,以單一完整的 Base64 編碼酬載形式傳送。請勿跨多個影片 step.delta 事件串連 delta.data。如果是大型或高解析度影片,請搭配使用 "delivery": "uri" 和 Cloud Storage bucket (gcs_uri),避免單一事件 SSE 酬載過大。

使用 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-1.2-flash"},"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-1.2-flash"},"event_id":"EVENT_ID","event_type":"interaction.completed"}

event: done
data: [DONE]

使用內嵌傳送時 ("delivery": "inline",省略 gcs_uri),影片 step.delta 事件會傳回 delta.data 中的影片位元組,做為 base64 編碼字串,並與 "mime_type": "video/mp4" 一起傳回,而不是 delta.uri:

event: step.delta
data: {"index":1,"delta":{"mime_type":"video/mp4","data":"BASE64_ENCODED_VIDEO","type":"video"},"event_id":"EVENT_ID","event_type":"step.delta"}

與文字 ("type": "text") 或音訊 ("type": "audio") 差異不同,內嵌影片不會在多個 step.delta 事件中分塊。每個生成的影片都會在一個 step.delta 事件 ("type": "video") 中,以單一完整的 Base64 編碼酬載形式傳送。請勿跨多個影片 step.delta 事件串連 delta.data。如果是大型或高解析度影片,請搭配使用 "delivery": "uri" 和 Cloud Storage bucket (gcs_uri),避免單一事件 SSE 酬載過大。

非同步

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

  • PROJECT_ID:代表 Cloud de Confiance by S3NS 專案 ID 的字串。
  • MODEL_ID:代表要使用的模型 ID 的字串。可接受的值如下:
    • "gemini-omni-1.2-flash"
    • "gemini-omni-1.1-flash-preview"
  • TEXT_PROMPT:用於引導影片生成的文字提示詞。
  • CLOUD_STORAGE_VIDEO_URI:代表 Cloud Storage bucket 的字串,其中包含輸入影片。例如:"gs://video-bucket/input/"。
  • VIDEO_MIME:代表影片 MIME 類型的字串。可接受的值如下:
    • video/3gpp
    • video/mp4
    • video/mpeg
    • video/quicktime
    • video/webm
    • video/x-flv
    • video/x-ms-wmv
  • CLOUD_STORAGE_OUTPUT_URI:代表 Cloud Storage bucket 的字串,用於儲存輸出影片 (例如 "gs://video-bucket/output/")。如果 delivery 設為 "uri",則必須提供這個參數。如要改為在回覆中傳回影片位元組,請設定 "delivery": "inline",並從 response_format 省略 gcs_uri。
  • ASPECT_RATIO:選用。代表輸出影片預期顯示比例的字串。如未提供,系統會根據提示推論顯示比例。 可接受的值如下:
    • "16:9"
    • "9:16"
  • DURATION:代表生成影片檔案長度的字串。允許的字串為 3 至 10 之間的整數,後接「s」代表秒。例如 "10s"。

HTTP 方法和網址:

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

JSON 要求內文:

{
  "model": "MODEL_ID",
  "background": true,
  "input": [
    {
      "type": "text",
      "text": "TEXT_PROMPT"
    },
    {
      "type": "video",
      "uri": "CLOUD_STORAGE_VIDEO_URI",
      "mime_type": "VIDEO_MIME"
    }
  ],
  "response_format": [
    {
      "type": "video",
      "delivery": "uri",
      "gcs_uri": "CLOUD_STORAGE_OUTPUT_URI",
      "aspect_ratio": "ASPECT_RATIO",
      "duration": "DURATION"
    }
  ],
  "generation_config": {
    "video_config": {
      "task": "extend"
    }
  }
}

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

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-1.2-flash",
  "status":"completed",
  "usage":{
    "total_tokens":29435,
    "total_input_tokens":150,
    "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",
          "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"
}

使用內嵌傳送時 ("delivery": "inline",省略 gcs_uri),model_output 步驟會傳回完整影片,做為 steps[].content[].data 中 "mime_type": "video/mp4" 旁的 Base64 編碼位元組字串,而非 uri:

{
  "type": "model_output",
  "content": [
    {
      "type": "video",
      "data": "BASE64_ENCODED_VIDEO",
      "mime_type": "video/mp4"
    }
  ]
}

使用 Veo 延長影片

以下範例說明如何擴充 Veo 影片:

控制台

  1. 前往 Cloud de Confiance 控制台,依序點選「Agent Platform」>「Media Studio」 。

    Media Studio

  2. 按一下「影片」。

  3. 在「Task」(工作) 選單中,選取「Video extension」(影片擴充功能)。

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

  5. 在「Input video」(輸入影片) 區段中,按一下「Add」(新增)。

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

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

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

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

  • 「Output directory」(輸出目錄):按一下「Browse」(瀏覽),建立或選取 Cloud Storage bucket,用於儲存產生的檔案。
  1. 按一下「執行」。

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, Video

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-preview",
    prompt="a butterfly flies in and lands on the flower",
    video=Video(
        uri="gs://cloud-samples-data/generative-ai/video/flower.mp4",
        mime_type="video/mp4",
    ),
    config=GenerateVideosConfig(
        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

REST

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

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

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

    • PROJECT_ID:代表 Cloud de Confiance by S3NS 專案 ID 的字串。
    • MODEL_ID:代表要使用的模型 ID 的字串。擴充影片時,請使用下列其中一種方法:
      • Veo 3.1:veo-3.1-generate-001
      • Veo 3.1:veo-3.1-fast-generate-001
    • TEXT_PROMPT:用於引導影片生成的文字提示詞。
    • PATH_TO_VIDEO:代表要擴充的 Veo 影片 Cloud Storage 路徑的字串。例如:"gs://video-bucket/input/veo-video.mp4"。
    • OUTPUT_STORAGE_URI:選用:代表要儲存輸出影片的 Cloud Storage bucket 字串。如未提供,系統會在回覆中傳回影片位元組。例如:"gs://video-bucket/output/"。
    • RESPONSE_COUNT:要生成的影片檔案數量。可接受的值範圍為 1-4。
    • 其他選用參數

      請根據您的用途,使用下列選用變數。在 "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",
           "video": {
             "gcsUri": "PATH_TO_VIDEO",
             "mimeType": "video/mp4"
           }
        }
      ],
      "parameters": {
        "storageUri": "OUTPUT_STORAGE_URI",
        "sampleCount": RESPONSE_COUNT
      }
    }
    

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

    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
    這項要求會傳回作業相關資訊,包括作業是否仍在執行或已完成。

後續步驟