限時優惠 | Seedance 2.0 & 2.0 Mini 立減20%!

如何使用 Gemini Omni Flash API 進行影片生成 (2026)

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

簡介: 本教學將說明如何使用 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 端點、隨用隨付定價,且不受 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             (驗證 + 佇列)     (生成)          (輸出)

完成後的腳本功能:

  • 提交生成請求並取得 prediction_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,請透過 .env 檔案將 ATLASCLOUD_API_KEY 加入 .gitignore

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

在此步驟中,您將發送一個文字轉影片(Text-to-Video)請求到 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

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

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    """輪詢直到影片準備好,並傳回輸出 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

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 與一個 images 陣列。模型識別碼為:

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

Gemini Omni Flash 圖片轉影片可接收 1 至 7 張參考圖片(PNG, JPEG, JPG, 或 WebP;每張最大 20 MB,最小 128×128 px)。它能維持影片生成過程中的視覺識別度,讓人物與物件保持一致。

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

若要獲得最佳效果,請使用一張清晰、光線充足且背景簡單的參考圖片。當主體與背景分離明顯時,模型在保持臉部與服裝細節一致性上表現更佳。具有複雜圖案或經過重度後製的圖片,往往會在影格間產生不一致的輸出。

注意: 僅接受 PNG、JPEG、JPG 與 WebP 格式的圖片。超過 20 MB 的檔案將會回傳 400 錯誤。

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

透過 Atlas Cloud 存取 Gemini Omni API 的一大優勢是,平台上每個影片生成模型都共用相同的端點與輪詢邏輯。從 Gemini Omni Flash 切換到其他模型只需更改模型參數。

plaintext
1# 切換至 Seedance 2.0 文字轉影片(在 Atlas Cloud 上費用為 $0.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"}提示詞可能違反內容政策;請改寫或移除受限制的內容
任務卡在 processing6 分鐘後仍未完成重新提交請求;此情況罕見,但在負載高峰時可能發生
影片 URL 回傳 404URL 無法存取輸出檔案於 48 小時後失效;請在生成後立即下載
429 Too Many Requests超過頻率限制增加請求間的延遲;重試時請使用指數退避(exponential backoff)

仍有疑問? 請前往 Atlas Cloud 文件 或透過平台的支援管道聯繫。

後續步驟

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

擴充此專案:

  • 使用 Seedance 2.0 加入支援音訊輸入的 Reference-to-Video,它支援最多 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。所有定價皆為隨用隨付,無最低消費(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 是非同步的:您的腳本提交任務後會立即收到 prediction_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.

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