如何使用 Gemini Omni API:逐步指南 (2026)

如何在 15 分鐘內使用 Gemini Omni Flash API。透過 Atlas Cloud 進行文字轉影片及圖片轉影片的完整 Python 與 Node.js 程式碼。定價:每段影片 USD1.00 起。

TL;DR: 本教學將說明如何使用 Gemini Omni Flash API,透過文字提示詞(text prompts)與參考圖片來生成影片。利用 Atlas Cloud 的統一 API,您大約只需 15 分鐘即可完成影片生成腳本。無需經過 Google 帳號審核,僅需一組 Atlas Cloud API 金鑰即可。

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 是上手最快的方式,但很容易觸及速率限制(rate limits)。對於尋求生產環境路徑的開發者而言,需要一個不同的入口。

Gemini Omni Flash 是 Google 的多模態影片生成模型,可接收文字、圖片、音訊和影片的任意組合作為輸入。它能生成長達 10 秒、解析度從 720p 到 4K 的電影級影片。本教學將示範如何透過 Atlas Cloud 使用 Gemini Omni Flash API,該平台提供統一的 API 端點、隨用隨付(pay-as-you-go)計費模式,且沒有與 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 金鑰(註冊免費)
  • 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 → 影片網址
2               (驗證 + 佇列)     (生成)          (輸出)

完成後的腳本功能:

  • 提交生成請求並取得
    text
    1prediction_id
  • 每 3 秒輪詢一次狀態端點,直到影片準備就緒
  • 生成完成後列印出輸出影片的網址

第 1 步:取得 Gemini Omni Flash API 金鑰

在此步驟中,您將註冊 Atlas Cloud 帳號並產生 API 金鑰,以便讓您的腳本能夠通過 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 金鑰提交到版本控制系統。如果您使用 python-dotenv 或 Node.js 的 dotenv,請透過

text
1.env
檔案將
text
1ATLASCLOUD_API_KEY
加入
text
1.gitignore

第 2 步:發送您的第一個 Gemini Omni Flash API 請求

在此步驟中,您將向 Gemini Omni Flash API 提交文字轉影片的請求,並取得一個

text
1prediction_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

plaintext
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

plaintext
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 會立即傳回

text
1prediction_id
,但此時影片尚未製作完成。您必須在第 3 步輪詢狀態端點以擷取輸出網址。

第 3 步:輪詢 Gemini Omni Flash 影片結果

在此步驟中,您將重複查詢狀態端點,直到影片生成完成且輸出網址可用為止。

使用 Gemini Omni Flash 進行影片生成屬於非同步作業。完成時間通常在 30 秒到 3 分鐘之間,具體取決於解析度和伺服器負載。狀態端點為:

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

可能的狀態值:

text
1processing
(處理中),
text
1completed
(已完成),
text
1succeeded
(成功),
text
1failed
(失敗)。

Python

plaintext
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    """持續輪詢直到影片準備就緒,然後回傳輸出網址。"""
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

plaintext
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 秒。每秒輪詢會增加不必要的 API 呼叫,且並不會有效縮短等待時間,因為 Gemini Omni Flash 作業在 1080p 解析度下極少能在 30 秒內完成。

注意: 輸出影片會在 Atlas Cloud 伺服器上保存 48 小時。若您需要保留影片,請務必在生成後立即下載至您自己的儲存空間。

第 4 步:使用 Gemini Omni Flash API 進行圖片轉影片

在此步驟中,您將上傳一張本地圖片至 Atlas Cloud,並將其用作 Gemini Omni Flash API 進行圖片轉影片(Image-to-Video)生成的參考。

圖片轉影片生成使用相同的端點,但需要不同的模型 ID 以及一個

text
1images
陣列。模型識別碼為:

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 步:上傳您的圖片

plaintext
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 步:提交圖片轉影片請求

plaintext
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() 函式進行輪詢

若要從 Gemini Omni Flash 圖片轉影片獲得最佳效果,請使用乾淨、採光良好且背景簡約的參考圖片。當主體與背景界線清晰時,模型對面部和服裝細節的保持會更加一致。包含複雜圖案或經過重度後製的圖片,往往容易導致幀與幀之間的輸出不連貫。

注意: 僅接受 PNG, JPEG, JPG 和 WebP 格式的圖片。超過 20 MB 的檔案會被系統拒絕並回傳 400 錯誤。

第 5 步:透過單一參數切換模型

透過 Atlas Cloud 存取 Gemini Omni API 的實務優勢之一,在於平台上每個影片生成模型都共享相同的端點與輪詢邏輯。從 Gemini Omni Flash 切換到另一個模型,僅需更改模型參數即可。

plaintext
1# 切換至 Seedance 2.0 文字轉影片 (Atlas Cloud 定價為 USD0.096/秒)
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"}提示詞可能違反內容政策;請改寫或移除受限內容
任務卡在
text
1processing
6 分鐘後仍無完成狀態重試請求;這種情況較罕見,但在負載高峰期可能會發生
影片網址回傳 404網址無法再存取輸出檔案在 48 小時後會過期;請在生成後立即下載
429 Too Many Requests超過速率限制在請求之間增加延遲;重試時使用指數退避(exponential backoff)

仍有困難? 請造訪 Atlas Cloud 文件或透過平台的支援頻道與我們聯繫。

後續步驟

現在您已經擁有可運行的文字轉影片與圖片轉影片腳本,以下是如何擴展它們的方法。

延伸此專案:

  • 結合 Seedance 2.0 使用包含音訊輸入的參考影片轉影片(Reference-to-Video)功能,該模型支援多達 7 張參考圖片與一條音軌
  • 建構一個批次生成管線,同步提交多個提示詞並以非同步方式收集結果
  • 在您的腳本中加入成本估算器:720p/1080p 的成本 = 0.20 + (duration * 0.10)

相關資源:

常見問題集

什麼是 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。所有計費皆為隨用隨付,沒有最低消費限制(Atlas Cloud 定價,2026-06-02)。

Google AI Studio 與 Atlas Cloud 在存取 Gemini Omni Flash API 時有什麼區別?

Google AI Studio 提供對 Gemini 模型的直接存取,但需要 Google 帳號,並受限於個人的使用配額,很容易就會耗盡。Atlas Cloud 則透過統一的 API 端點提供相同的 Gemini Omni Flash 模型,具有透明的按秒計費、無需排隊等待核准,且能透過同一組 API 金鑰存取其他 300 多個影片與圖片模型。對於生產環境使用,Atlas Cloud 的統一 API 省去了管理不同模型供應商分開憑證的麻煩。

Gemini Omni Flash 生成一段影片需要多久?

一段 8 秒 1080p 影片的典型生成時間為 30 秒至 3 分鐘,具體取決於伺服器負載。API 是非同步的:您的腳本會提交工作並立即收到

text
1prediction_id
,隨後輪詢狀態端點直到影片準備就緒。請將您的逾時處理時間上限設定為 6 分鐘,以因應高負載期間的延遲。

我可以免費使用 Gemini Omni Flash API 嗎?

Atlas Cloud 為新帳號提供免費額度,您可以將其用於 Gemini Omni Flash 的生成。在免費額度用盡後,即採用隨用隨付制,無需訂閱。立即前往 atlascloud.ai 註冊即可開始。

最新模型

一個 API,暢享全模態 AI。

探索全部模型

Join our Discord community

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