OFERTA POR TIEMPO LIMITADO | ¡20% DE DESCUENTO en Seedance 2.0 & 2.0 Mini!

Cómo utilizar la API de Gemini Omni Flash para la generación de video (2026)

Cómo empezar con la API de Gemini Omni Flash en 15 minutos. Incluye código completo en Python y Node.js para generación de vídeo a través de Atlas Cloud (texto a vídeo e imagen a vídeo). Precios: desde USD1.00/clip.

TL;DR: 本教程将向你展示如何使用 Gemini Omni Flash API 通过文本提示词和参考图像生成视频。利用 Atlas Cloud 的统一 API,你可以在大约 15 分钟内完成视频生成脚本的开发。无需 Google 账户审批,仅需一个 Atlas Cloud API Key 即可。

Google 官方的 Gemini API 入门文档并未专门针对 Gemini Omni Flash 进行介绍。本教程使用 Atlas Cloud 的统一 API 端点,无需通过 Google AI Studio 即可直接调用 Gemini Omni Flash。

developer editorial style terminal

六天前,r/GeminiAI 上一篇题为“Gemini Omni Flash API 访问:测试了 5 家提供商,按用例排名”的帖子迅速成为开发者评估方案时的首选参考。热门评论直击要点:Google AI Studio 是上手最快的方式,但会很快触及速率限制。寻求生产级路径的开发者需要一个不同的入口。

Gemini Omni Flash 是 Google 的多模态视频生成模型,支持文本、图像、音频和视频的任意组合作为输入。它能生成长达 10 秒、分辨率从 720p 到 4K 的电影级视频。本教程将展示如何通过 Atlas Cloud 使用 Gemini Omni Flash API,该平台提供统一的 API 端点、按用量付费模式,且没有绑定 Google 账户的速率限制。

本教程涵盖了 Gemini Omni API 的两种生成模式:文生视频 (Text-to-Video) 和图生视频 (Image-to-Video)。所有代码示例均已在 Atlas Cloud 生产环境 API 上测试通过。

Gemini Omni Flash API 前置条件

你需要准备:

  • Python 3.9+ 或 Node.js 18+
  • 一个 Atlas Cloud 账户及 API Key(注册免费)
  • Python 的 requests 库或 Node.js 的 axios 库
  • 对 REST API 有基础了解
  • 大约 15 分钟的预留时间

测试环境: macOS 14, Ubuntu 22.04, Windows 11 (WSL2)

价格参考(来源:Atlas Cloud 定价页面,2026-06-02):

  • 720p / 1080p:基础费 USD0.20 + 每秒 USD0.10。一段 8 秒的 720p 视频成本为 USD1.00
  • 4K:基础费 USD1.00 + 每秒 USD0.10。一段 8 秒的 4K 视频成本为 USD1.80

我们将使用 Gemini Omni API 构建什么

在本教程结束时,你将获得两个可用的脚本:一个用于通过文本提示词生成视频,另一个用于将参考图像转换为视频。两个脚本共享相同的认证和轮询逻辑。其架构非常直观:

plaintext
1你的脚本 → Atlas Cloud API → Gemini Omni Flash → 视频 URL
2               (认证 + 队列)     (生成)      (输出)

脚本功能说明:

  • 提交生成请求并获取 prediction_id
  • 每 3 秒轮询一次状态端点,直到视频准备就绪
  • 生成完成后打印输出视频的 URL

第 1 步:获取 Gemini Omni Flash API Key

在此步骤中,你将注册 Atlas Cloud 账户并生成 API Key,以便脚本能够通过 Gemini Omni Flash API 进行认证。

  1. 前往 atlascloud.ai 注册免费账户。
  2. 在控制面板中,导航至 API Keys
  3. 点击 Create new key,复制密钥并妥善保存。

将密钥设置为环境变量,以避免在脚本中硬编码:

plaintext
1# macOS / Linux
2export ATLASCLOUD_API_KEY="your_api_key_here"
3
4# Windows (PowerShell)
5$env:ATLASCLOUD_API_KEY="your_api_key_here"

验证设置是否正确:

plaintext
1echo $ATLASCLOUD_API_KEY

预期输出:

plaintext
1your_api_key_here

注意: 切勿将 API Key 提交到版本控制系统中。如果使用 python-dotenv 或 Node.js 的 dotenv,请将 ATLASCLOUD_API_KEY 添加到 .gitignore 的 .env 文件中。

第 2 步:发送第一个 Gemini Omni Flash API 请求

在此步骤中,你将向 Gemini Omni Flash API 提交文生视频请求,并获取 prediction_id 以跟踪任务。

Atlas Cloud 上所有视频生成的端点为:

plaintext
1POST https://api.atlascloud.ai/api/v1/model/generateVideo

Gemini Omni Flash 文生视频的模型标识符为:

plaintext
1google/gemini-omni-flash/text-to-video-developer

Python

python
1# gemini_omni_t2v.py
2import requests
3import os
4
5API_KEY = os.environ["ATLASCLOUD_API_KEY"]
6BASE_URL = "https://api.atlascloud.ai/api/v1/model"
7
8headers = {
9    "Content-Type": "application/json",
10    "Authorization": f"Bearer {API_KEY}"
11}
12
13payload = {
14    "model": "google/gemini-omni-flash/text-to-video-developer",
15    "prompt": "A young woman walks slowly through a rainy Tokyo street at night, neon reflections on wet pavement, cinematic slow motion, realistic lighting, 4K, film grain",
16    "duration": 8,          # 秒数: 4, 6, 8, 或 10
17    "aspect_ratio": "16:9", # "16:9" 或 "9:16"
18    "resolution": "1080p",  # "720p", "1080p", 或 "4k"
19    "seed": -1              # -1 表示随机;设置整数可获得可重复的输出
20}
21
22response = requests.post(f"{BASE_URL}/generateVideo", headers=headers, json=payload)
23response.raise_for_status()
24
25prediction_id = response.json()["data"]["id"]
26print(f"Job submitted. Prediction ID: {prediction_id}")

Node.js

javascript
1// geminiOmniT2V.js
2const axios = require("axios");
3
4const API_KEY = process.env.ATLASCLOUD_API_KEY;
5const BASE_URL = "https://api.atlascloud.ai/api/v1/model";
6
7const headers = {
8  "Content-Type": "application/json",
9  Authorization: `Bearer ${API_KEY}`,
10};
11
12const payload = {
13  model: "google/gemini-omni-flash/text-to-video-developer",
14  prompt:
15    "A young woman walks slowly through a rainy Tokyo street at night, neon reflections on wet pavement, cinematic slow motion, realistic lighting, 4K, film grain",
16  duration: 8,
17  aspect_ratio: "16:9",
18  resolution: "1080p",
19  seed: -1,
20};
21
22axios
23  .post(`${BASE_URL}/generateVideo`, payload, { headers })
24  .then((res) => {
25    const predictionId = res.data.data.id;
26    console.log(`Job submitted. Prediction ID: ${predictionId}`);
27  })
28  .catch((err) => console.error(err.response?.data || err.message));

预期输出:

plaintext
1Job submitted. Prediction ID: pred_abc123xyz

注意: API 会立即返回 prediction_id,但这并不代表视频已完成。你必须在第 3 步中轮询状态端点以获取输出 URL。

第 3 步:轮询 Gemini Omni Flash 视频结果

在此步骤中,你将重复查询状态端点,直到视频生成完成并获取输出 URL。

Gemini Omni Flash 的视频生成是异步的。根据分辨率和服务器负载,完成时间通常为 30 秒到 3 分钟。状态端点为:

plaintext
1GET https://api.atlascloud.ai/api/v1/model/prediction/{prediction_id}

可能的状态值:processing(处理中)、completed(已完成)、succeeded(成功)、failed(失败)。

Python

python
1# poll_result.py
2import requests
3import time
4import os
5
6API_KEY = os.environ["ATLASCLOUD_API_KEY"]
7BASE_URL = "https://api.atlascloud.ai/api/v1/model"
8
9headers = {
10    "Authorization": f"Bearer {API_KEY}"
11}
12
13def poll_video(prediction_id: str, timeout: int = 360) -> str:
14    """轮询直到视频准备好,然后返回输出 URL。"""
15    elapsed = 0
16    while elapsed < timeout:
17        response = requests.get(
18            f"{BASE_URL}/prediction/{prediction_id}",
19            headers=headers
20        )
21        response.raise_for_status()
22        data = response.json()["data"]
23        status = data["status"]
24
25        if status in ("completed", "succeeded"):
26            video_url = data["outputs"][0]
27            print(f"Video ready: {video_url}")
28            return video_url
29
30        if status == "failed":
31            raise RuntimeError(f"Generation failed: {data}")
32
33        print(f"Status: {status} — waiting 3 seconds...")
34        time.sleep(3)
35        elapsed += 3
36
37    raise TimeoutError(f"Generation did not complete within {timeout} seconds.")
38
39# 替换为你第 2 步中实际的 prediction_id
40video_url = poll_video("pred_abc123xyz")

Node.js

javascript
1// pollResult.js
2const axios = require("axios");
3
4const API_KEY = process.env.ATLASCLOUD_API_KEY;
5const BASE_URL = "https://api.atlascloud.ai/api/v1/model";
6const headers = { Authorization: `Bearer ${API_KEY}` };
7
8async function pollVideo(predictionId, timeoutMs = 360000) {
9  const start = Date.now();
10  while (Date.now() - start < timeoutMs) {
11    const res = await axios.get(`${BASE_URL}/prediction/${predictionId}`, { headers });
12    const data = res.data.data;
13
14    if (data.status === "completed" || data.status === "succeeded") {
15      console.log("Video ready:", data.outputs[0]);
16      return data.outputs[0];
17    }
18    if (data.status === "failed") throw new Error(`Generation failed: ${JSON.stringify(data)}`);
19
20    console.log(`Status: ${data.status} — waiting 3 seconds...`);
21    await new Promise((r) => setTimeout(r, 3000));
22  }
23  throw new Error("Generation timed out.");
24}
25
26pollVideo("pred_abc123xyz");

预期输出:

plaintext
1Status: processing — waiting 3 seconds...
2Status: processing — waiting 3 seconds...
3Video ready: https://storage.atlascloud.ai/outputs/result.mp4

请将轮询间隔设置为 3 秒而不是 1 秒。因为 Gemini Omni Flash 在 1080p 下很少能在 30 秒内完成,每秒轮询只会增加无意义的 API 调用。

注意: 输出视频在 Atlas Cloud 服务器上仅保存 48 小时。如果需要长期保存,请在生成后立即下载。

第 4 步:使用 Gemini Omni Flash API 进行图生视频

在此步骤中,你将上传一张本地图片到 Atlas Cloud,并将其作为 Gemini Omni Flash 图生视频的参考。

图生视频模式使用相同的端点,但需要不同的模型 ID 和一个 images 数组。模型标识符为:

plaintext
1google/gemini-omni-flash/image-to-video-developer

Gemini Omni Flash 图生视频接受 1 到 7 张参考图片(PNG、JPEG、JPG 或 WebP 格式;单张最大 20 MB,最小 128×128 像素)。它能保持视频中视觉的一致性,确保角色和物体在整个过程中保持稳定。

the video of showing a person is moving

第 4a 步:上传图片

python
1# upload_image.py
2import requests
3import os
4
5API_KEY = os.environ["ATLASCLOUD_API_KEY"]
6UPLOAD_URL = "https://api.atlascloud.ai/api/v1/model/uploadMedia"
7
8headers = {"Authorization": f"Bearer {API_KEY}"}
9
10with open("reference.jpg", "rb") as f:
11    response = requests.post(UPLOAD_URL, headers=headers, files={"file": f})
12
13response.raise_for_status()
14image_url = response.json()["data"]["url"]
15print(f"Uploaded image URL: {image_url}")

第 4b 步:提交图生视频请求

python
1# gemini_omni_i2v.py
2import requests
3import os
4
5API_KEY = os.environ["ATLASCLOUD_API_KEY"]
6BASE_URL = "https://api.atlascloud.ai/api/v1/model"
7
8headers = {
9    "Content-Type": "application/json",
10    "Authorization": f"Bearer {API_KEY}"
11}
12
13payload = {
14    "model": "google/gemini-omni-flash/image-to-video-developer",
15    "prompt": "The character walks forward slowly, natural lighting, cinematic depth of field",
16    "images": [image_url],  # 使用第 4a 步返回的 URL
17    "duration": 8,
18    "aspect_ratio": "16:9",
19    "resolution": "1080p",
20    "seed": -1
21}
22
23response = requests.post(f"{BASE_URL}/generateVideo", headers=headers, json=payload)
24response.raise_for_status()
25
26prediction_id = response.json()["data"]["id"]
27print(f"Job submitted. Prediction ID: {prediction_id}")
28# 然后使用第 3 步中的 poll_video() 函数进行轮询

为了获得最佳效果,建议使用背景简洁、光线充足的参考图像。当主体与背景清晰分离时,模型能更一致地保留面部和衣物细节。包含复杂图案或过度后期处理的图片往往会导致跨帧生成的一致性下降。

注意: 仅接受 PNG、JPEG、JPG 和 WebP 格式。超过 20 MB 的文件将返回 400 错误。

第 5 步:通过更改参数切换模型

通过 Atlas Cloud 访问 Gemini Omni API 的一大优势在于,平台上的所有视频生成模型都共享相同的端点和轮询逻辑。从 Gemini Omni Flash 切换到其他模型只需更改模型参数。

python
1# 切换至 Seedance 2.0 文生视频 (Atlas Cloud 价格为 USD0.096/s)
2payload["model"] = "bytedance/seedance-2-0/text-to-video"
3
4# 切换至 Veo 3.1 Lite
5payload["model"] = "google/veo-3-1/lite-text-to-video"

这使得多模型 A/B 测试变得简单。你可以用同样的提示词在多个模型上运行,并在投入生产前比较输出质量。

Gemini Omni Flash API 故障排除

以下是使用 Gemini Omni Flash API 时最常见的五个问题及解决方法:

问题现象解决方法
401 Unauthorized{"error": "Invalid API key"}检查 ATLASCLOUD_API_KEY 环境变量是否已设置且未过期
400 Bad Request{"error": "Invalid prompt"}提示词可能违反内容政策;重新措辞或移除违规内容
任务卡在 processing6 分钟后仍未完成重试请求;这种情况极少发生,但在高峰负载时可能出现
视频 URL 返回 404URL 无法访问输出文件 48 小时后过期;生成后请立即下载
429 Too Many Requests达到速率限制在请求之间增加延迟;重试时使用指数退避算法

仍有问题? 请访问 Atlas Cloud 文档 或通过平台支持渠道联系我们。

后续步骤

现在你已经拥有了可用的文生视频和图生视频脚本,以下是如何扩展它们的建议:

扩展此项目:

  • 使用支持音频输入的 Seedance 2.0 添加“参考+音频生成视频”功能,它支持组合 7 张参考图及音轨
  • 构建批量生成管道,并行提交多个提示词并异步收集结果
  • 为脚本添加成本估算器:成本 = 0.20 + (时长 * 0.10) (针对 720p/1080p)

相关资源:

常见问题解答

什么是 Gemini Omni Flash API?

Gemini Omni Flash API 是 Google 的多模态视频生成接口,支持文本、图像、音频和视频的任意组合作为输入,并输出电影级视频片段。它支持 4 到 10 秒的长度、720p 到 4K 的分辨率,以及横向和纵向比例。通过 Atlas Cloud 访问,无需单独经过 Google 审批。

Gemini Omni Flash API 的成本是多少?

在 Atlas Cloud 上,Gemini Omni Flash 的定价为基础费 USD0.20 + 每秒 USD0.10(针对 720p 和 1080p 输出)。一段标准的 8 秒 1080p 视频成本为 USD1.00。对于 4K 输出,基础费为 USD1.00 + 每秒 USD0.10,8 秒 4K 视频成本为 USD1.80。所有计费均为按用量付费,无最低消费(基于 2026-06-02 的 Atlas Cloud 定价)。

Google AI Studio 和 Atlas Cloud 在访问 Gemini Omni Flash API 时有什么区别?

Google AI Studio 提供对 Gemini 模型的直接访问,但需要 Google 账户,且受到个人使用额度的限制,可能会很快触及阈值。Atlas Cloud 通过统一的 API 端点提供相同的 Gemini Omni Flash 模型,具有透明的每秒计费、无需审批队列,并且使用同一 API Key 即可访问 300 多种其他视频和图像模型。对于生产环境,Atlas Cloud 的统一 API 避免了为每个模型提供商管理不同凭据的麻烦。

Gemini Omni Flash 生成视频需要多长时间?

生成 8 秒 1080p 视频的典型耗时为 30 秒到 3 分钟,具体取决于服务器负载。该 API 是异步的:脚本提交任务并立即收到 prediction_id,随后轮询状态端点直到视频完成。建议将超时处理上限设为 6 分钟,以应对高峰负载期。

可以免费使用 Gemini Omni Flash API 吗?

Atlas Cloud 为新账户提供免费额度,可用于 Gemini Omni Flash 生成。免费额度用尽后,即转为按用量付费,无需订阅。前往 atlascloud.ai 注册即可开始。

Modelos recientes

Una sola API para toda la IA multimedia.

Explorar Todos los Modelos

Join our Discord community

Join the Discord community for the latest model updates, prompts, and support.