The latest Gemini models, like Gemini 3.1 Flash Image (Nano Banana 2), are available to use with Firebase AI Logic! Learn more.
Gemini 2.0 Flash and Flash-Lite models will shut down on June 1, 2026. To avoid service disruption, update to a newer model like gemini-2.5-flash-lite. Learn more.
本頁說明如何排解 Gemini API 和 Firebase AI Logic SDK 的常見錯誤代碼。
400 錯誤:API key not valid. Please pass a valid API key.
如果收到 400 錯誤,顯示「API key not valid. Please pass a valid API key.」,通常表示 Firebase 設定檔/物件中的 API 金鑰不存在,或未設定為與應用程式和/或 Firebase 專案搭配使用。
檢查 Firebase 設定檔/物件中列出的 API 金鑰,是否與應用程式的 API 金鑰相符。您可以在 Google Cloud 控制台的「APIs & Services」(API 和服務) >「Credentials」(憑證) 面板中,查看所有 API 金鑰。
如果發現不相符,請取得新的 Firebase 設定檔/物件,然後取代應用程式中的設定檔/物件。新的設定檔/物件應包含應用程式和 Firebase 專案的有效 API 金鑰。
400 錯誤:Service agents are being provisioned ... Service agents are needed to read the Cloud Storage file provided.
如果嘗試使用 Cloud Storage for Firebase 網址傳送多模態要求,可能會遇到下列 400 錯誤: Service agents are being provisioned ... Service agents are needed to read the Cloud Storage file provided.
如果專案啟用 Vertex AI API 時,沒有正確自動佈建必要的服務代理,就會發生這個錯誤。這是部分專案的已知問題,我們正在設法全面修正。
以下是解決專案問題的替代方案,可正確佈建這些服務代理程式,讓您開始在多模態要求中加入 Cloud Storage for Firebase 網址。您必須是專案的擁有者,且專案只需要完成一次這組工作。
403 錯誤:Requests to this API firebasevertexai.googleapis.com ... are blocked.
如果收到 403 錯誤,且錯誤訊息為「Requests to this API firebasevertexai.googleapis.com ... are blocked.」,通常表示應用程式 Firebase 設定中的 API 金鑰設有限制,導致無法呼叫必要 API。
如要修正這個問題,請在 Google Cloud 控制台中更新 API 金鑰的限制,加入必要的 API。如要使用 Firebase AI Logic,請務必確認 Firebase AI Logic API (firebasevertexai.googleapis.com) 已列入可透過 API 金鑰呼叫的所選 API 清單。
404 錯誤:模型「was not found or your project does not have access to it」?
例如:「Publisher Model projects/PROJECT-ID/locations/us-central1/publishers/google/models/gemini-3-pro-image-preview was not found or your project does not have access to it. Please ensure you are using a valid model version.」
如果您使用 Vertex AI Gemini API,所有預先發布和實驗Gemini模型 (Gemini Live 模型除外) 僅適用於 global 地區。不過,由於 Firebase AI Logic 預設為 us-central1 位置,因此使用這些預覽版和實驗版Gemini 模型時,您需要在程式碼中初始化 Vertex AI Gemini API 後端服務時,明確指定 global 位置。
修正:初始化 Vertex AI Gemini API 服務時,請指定位置 global。進一步瞭解如何指定存取模型的位置 (包括程式碼片段)。
位置無效(僅適用於使用 Vertex AI Gemini API 供應商的情況)
原因:您使用的模型在您嘗試存取的位置不支援。
如果使用 Vertex AI Gemini API,部分機型僅適用於特定地區。例如 (僅列舉部分內容):
Imagen 模型不支援 global 位置。
Gemini Live API 模型 (例如 gemini-2.0-flash-live-preview-04-09) 僅支援 us-central1 位置。