Skip to content

Gemini Omni Flash 视频 API ​

Gemini Omni Flash 是高性能多模态模型,适合快速视频生成、视频编辑和电影化控制。它可以同时理解文本、图片、音频和视频,通过 Interactions API 支持对话式编辑,并结合 Gemini 的世界知识处理物理场景和叙事细节。

调用方式 ​

接口与鉴权 ​

使用以下 Interactions 接口创建请求或查询结果:

text
POST https://api.exchangetoken.ai/v1beta/interactions
GET  https://api.exchangetoken.ai/v1beta/interactions/{id}

使用 Exchange Token API Key,支持以下任一鉴权 Header:

http
x-goog-api-key: YOUR_API_KEY
http
Authorization: Bearer YOUR_API_KEY

Content-Type Header:

http
Content-Type: application/json

Request Body ​

请求体遵循 Vertex AI Interactions API 的 create schema。下方示例主要使用这些字段:

字段类型必填说明
modelstring是模型名称。文本和视频编辑示例使用 gemini-omni-flash-preview;图片示例中的 $MODEL 填写实际调用的模型名称。
previous_interaction_idstring否上一轮 interaction 的 id,用于在已生成的视频上继续编辑。
inputstring、content object 或 content array是interaction 的主输入内容。文生视频可直接传字符串;图生视频或视频编辑传多模态数组。
input[].typestring条件必填内容项类型,例如 text、image、video、user_input。
input[].textstring条件必填当 type 为 text 时传入文本提示词。
input[].datastring条件必填图片输入的 Base64 内容;视频使用 uri,不接受 Base64 data。
input[].uristring条件必填媒体文件地址。
input[].mime_typestring条件必填媒体输入的 MIME 类型,例如 image/jpeg、image/png、video/mp4。
input[].contentarray条件必填使用 user_input 包装时传入的嵌套内容数组。
backgroundboolean否是否后台执行,默认 false。
storeboolean否默认 true。
streamboolean否是否以 SSE 流式返回,默认 false。
response_formatobject 或 array否输出格式配置。下方使用对象形式;数组形式按每个输出项填写。
response_format.typestring否输出类型。视频输出使用 video。
response_format.deliverystring否交付方式。下方使用 uri,通过链接获取视频。
response_format.aspect_ratiostring否视频画面比例:16:9 或 9:16。
response_format.resolutionstring否输出分辨率,例如 720p。
response_format.durationstring否视频时长,例如 5s,数值和单位放在同一字符串中。
response_format.gcs_uristring不传视频 URI 输出的存储地址由平台自动填写。
generation_configobject否生成配置。
generation_config.video_config.taskstring否可选的视频任务提示。参数值包括 text_to_video、image_to_video、reference_to_video、edit、extend,按所用模型的参数约束填写。

TIP

获取视频链接时,同时设置 response_format.type: video 和 response_format.delivery: uri,并省略 gcs_uri。平台会分配输出存储地址,并将模型输出中的存储 URI 转为签名下载链接。

Response Body ​

常见字段:

字段类型说明
idstringinteraction 的唯一标识
objectstring资源类型标识,通常为 interaction
statusstring当前 interaction 状态,例如 in_progress、completed、failed
rolestring响应载荷对应的角色,通常为 model
createdstringinteraction 的 ISO 8601 创建时间
updatedstringinteraction 的 ISO 8601 更新时间
modelstring本次 interaction 使用的模型名称
stepsarrayinteraction 返回的有序步骤对象
usageobject上游返回时附带的 token usage 汇总信息

常见的 steps 字段:

字段类型说明
typestring步骤类型,例如 model_output
contentarray该步骤携带的内容项
content[].uristring视频输出的下载地址,从 type: model_output 的步骤中读取

示例:

json
{
  "id": "v1_...",
  "status": "completed",
  "role": "model",
  "created": "2026-05-27T06:15:03Z",
  "updated": "2026-05-27T06:15:03Z",
  "steps": [
    {
      "content": [
        {
          "text": "",
          "type": "text"
        }
      ],
      "type": "model_output"
    },
    {
      "content": [
        {
          "mime_type": "video/mp4",
          "uri": "https://storage.googleapis.com/example-bucket/output.mp4?X-Goog-Signature=EXAMPLE",
          "type": "video"
        }
      ],
      "type": "model_output"
    }
  ],
  "object": "interaction",
  "model": "gemini-omni-flash-preview"
}

获取输入视频 URI ​

视频仅支持通过 uri 传入,且仅支持 Google Cloud Storage 地址(gs://...),不支持 Base64。已有公开可访问的 gs:// 地址时,可以直接使用;否则需要使用本平台的 Google Cloud Storage 上传功能,按以下步骤上传视频,并将返回的 gcs_uri 作为输入 URI。

获取上传地址 ​

调用上传地址接口,使用 Exchange Token API Key 鉴权。请求体只接受可选的 filename,用于指定文件名。

bash
curl --fail-with-body -sS -X POST "https://api.exchangetoken.ai/v1/storage/upload-urls" \
  -H "x-goog-api-key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"filename":"source.mp4"}' \
  -o upload.json

返回示例:

json
{
  "upload_url": "https://storage.googleapis.com/BUCKET/uploads/.../source.mp4?X-Goog-...",
  "gcs_uri": "gs://BUCKET/uploads/.../source.mp4",
  "expires_at": "2026-10-14T00:00:00Z",
  "method": "PUT",
  "headers": {}
}

upload_url 用于上传文件,gcs_uri 用于 Interactions API 的视频输入 uri 字段。上传链接有效期为 24 小时,具体过期时间以 expires_at 为准。此时只获取了上传地址,还需要上传视频文件。

上传本地视频 ​

从 upload.json 读取地址,通过 PUT 上传本地文件。下方使用 Bash、curl 和 jq。

bash
VIDEO_FILE="./source.mp4"
UPLOAD_URL=$(jq -er '.upload_url' upload.json)
VIDEO_URI=$(jq -er '.gcs_uri' upload.json)

curl --fail-with-body -sS -X PUT "$UPLOAD_URL" \
  --upload-file "$VIDEO_FILE"

上传完成后,$VIDEO_URI 可用于 Interactions API 请求中视频内容项的 uri 字段。

文生视频 ​

根据文本提示词生成带音频的视频。建议在提示词里写清楚场景、镜头运动、光线、氛围和关键动作。

bash
curl -X POST "https://api.exchangetoken.ai/v1beta/interactions" \
  -H "x-goog-api-key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini-omni-flash-preview",
    "input": "A marble rolling fast on a chain reaction style track, continuous smooth shot.",
    "response_format": { "type": "video", "delivery": "uri" }
  }'

控制画面比例 ​

设置 response_format.aspect_ratio 为 9:16 请求竖屏视频,16:9 请求横屏视频。

bash
curl -X POST "https://api.exchangetoken.ai/v1beta/interactions" \
  -H "x-goog-api-key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini-omni-flash-preview",
    "input": "A futuristic city with neon lights and flying cars, cyberpunk style",
    "response_format": {
      "type": "video",
      "delivery": "uri",
      "aspect_ratio": "9:16"
    }
  }'

图生视频 ​

图片和文本提示词放在同一个 input 数组中。下方 $MODEL 为实际调用的模型名称,$BASE64_IMAGE 为图片的 Base64 内容。

bash
curl -X POST "https://api.exchangetoken.ai/v1beta/interactions" \
  -H "x-goog-api-key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "'"$MODEL"'",
    "input": [
      { "type": "image", "data": "'"$BASE64_IMAGE"'", "mime_type": "image/jpeg" },
      { "type": "text", "text": "turn this into realistic footage, using the drawing only as a guide for movement, do not show the drawing in the final video" }
    ],
    "response_format": { "type": "video", "delivery": "uri" }
  }'

TIP

图片也可以通过 uri 引用已上传的文件。使用 data 时填写纯 Base64 内容,mime_type 应与实际文件一致。

主体参考 ​

多张参考图片依次放入 input 数组,并通过提示词说明每张图片的用途。

bash
curl -X POST "https://api.exchangetoken.ai/v1beta/interactions" \
  -H "x-goog-api-key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "'"$MODEL"'",
    "input": [
      { "type": "image", "data": "'"$CAT_B64"'", "mime_type": "image/png" },
      { "type": "image", "data": "'"$YARN_B64"'", "mime_type": "image/png" },
      { "type": "text", "text": "A cat playfully batting at a ball of yarn." }
    ],
    "response_format": { "type": "video", "delivery": "uri" }
  }'

task 参数 ​

使用 generation_config.video_config.task 指定任务模式。该字段由网关透传;不传时,模型根据提示词和输入媒体判断。参数语义见 Vertex AI VideoConfig。

参数值(具体使用范围按所用模型填写):

  • text_to_video
  • image_to_video
  • reference_to_video
  • edit
  • extend
bash
curl -X POST "https://api.exchangetoken.ai/v1beta/interactions" \
  -H "x-goog-api-key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "'"$MODEL"'",
    "input": [
      { "type": "image", "data": "'"$BASE64_IMAGE"'", "mime_type": "image/jpeg" },
      { "type": "text", "text": "turn this into realistic footage, using the drawing only as a guide for movement, do not show the drawing in the final video" }
    ],
    "generation_config": {
      "video_config": {
        "task": "image_to_video"
      }
    },
    "response_format": { "type": "video", "delivery": "uri" }
  }'

编辑自己的视频 ​

准备好 $VIDEO_URI 后提交编辑请求,地址获取方式见获取输入视频 URI。

bash
curl -sS -w "\n[HTTP %{http_code}]\n" "https://api.exchangetoken.ai/v1beta/interactions" \
  -H "x-goog-api-key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini-omni-flash-preview",
    "input": [
      {
        "type": "user_input",
        "content": [
          {
            "type": "video",
            "mime_type": "video/mp4",
            "uri": "'"$VIDEO_URI"'"
          },
          {
            "type": "text",
            "text": "When the person touches the mirror, make the mirror ripple beautifully like liquid, and the person arm turns into reflective mirror material"
          }
        ]
      }
    ],
    "generation_config": { "video_config": { "task": "edit" } },
    "response_format": { "type": "video", "delivery": "uri" }
  }'

多轮编辑 ​

上一轮完成后,previous_interaction_id 引用该轮 interaction,input 提供本轮编辑指令。后续请求须使用同一 API Key 和模型。

使用 previous_interaction_id 时,请省略 generation_config.video_config.task,通过 input 描述编辑意图,避免上游返回参数冲突错误。

bash
PREVIOUS_INTERACTION_ID="YOUR_INTERACTION_ID"

curl -X POST "https://api.exchangetoken.ai/v1beta/interactions" \
  -H "x-goog-api-key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini-omni-flash-preview",
    "previous_interaction_id": "'"$PREVIOUS_INTERACTION_ID"'",
    "input": "Keep the subject and camera motion unchanged, and change the background to a snowy mountain.",
    "response_format": { "type": "video", "delivery": "uri" }
  }'

后台生成与查询 ​

background: true 启用后台执行模式。创建与查询请求须使用同一 API Key 鉴权。

bash
curl -X POST "https://api.exchangetoken.ai/v1beta/interactions" \
  -H "x-goog-api-key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini-omni-flash-preview",
    "input": "A paper boat drifts across a quiet pond in soft morning light.",
    "background": true,
    "response_format": { "type": "video", "delivery": "uri" }
  }'

GET /v1beta/interactions/{id} 用于查询任务状态与结果,其中 {id} 为创建请求返回的 interaction 标识。

bash
INTERACTION_ID="YOUR_INTERACTION_ID"

curl --fail-with-body -sS "https://api.exchangetoken.ai/v1beta/interactions/$INTERACTION_ID" \
  -H "x-goog-api-key: $API_KEY" \
  -o result.json

响应中的 status 表示任务状态:

状态说明
in_progress任务执行中,可定期轮询查询。
completed任务已完成,生成结果位于 steps。
failed任务执行失败,错误原因见响应信息。
incomplete任务未完整完成,详情见响应信息。