The latest Gemini models, like Gemini 3.5 Flash, are available to use with Firebase AI Logic! Learn more.
Gemini 2.0 Flash and Flash-Lite models were shut down on June 1, 2026. To avoid service disruption, update to a newer model like gemini-3.1-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 清單。
步驟如下:
在 Google Cloud 控制台中,開啟「APIs & Services」(API 和服務) >「Credentials」(憑證) 面板。
選取應用程式設定使用的 API 金鑰 (例如 iOS 應用程式的「iOS 金鑰」)。
在「編輯 API 金鑰」頁面中,找到「API 限制」部分。
確認已選取「限制金鑰」選項。如果不是,代表金鑰不受限制,這可能不是錯誤來源。
在「選取的 API」下拉式選單中,搜尋並選取要新增的 Firebase AI Logic API,將其加入可使用 API 金鑰呼叫的 API 清單。
按一下 [儲存]。
變更最多可能需要五分鐘才會生效。
403 錯誤:PERMISSION_DENIED: The caller does not have permission.
如果收到 403 錯誤,且錯誤訊息為「PERMISSION_DENIED: The caller does not have permission.」,通常表示 Firebase 設定檔/物件中的 API 金鑰屬於其他 Firebase 專案。
檢查 Firebase 設定檔/物件中列出的 API 金鑰,是否與應用程式的 API 金鑰相符。您可以在 Google Cloud 控制台的「APIs & Services」(API 和服務) >「Credentials」(憑證) 面板中,查看所有 API 金鑰。
如果發現不相符,請取得新的 Firebase 設定檔/物件,然後取代應用程式中的設定檔/物件。新的設定檔/物件應包含應用程式和 Firebase 專案的有效 API 金鑰。
404 錯誤:Firebase AI Logic genai config not found
如果您嘗試使用 Gemini Developer API,但收到 404 錯誤訊息 Firebase AI Logic genai config not found,通常表示 Firebase 專案沒有可與 Firebase AI Logic 用戶端 SDK 搭配使用的有效 Gemini API 金鑰。
造成這項錯誤最可能的原因如下:
您尚未為「Gemini Developer API」設定 Firebase 專案。
做法:
在 Firebase 控制台中,依序前往「AI Services」(AI 服務) >「AI Logic」(AI 邏輯)。按一下「開始使用」,然後選取 Gemini Developer API。啟用 API 後,控制台會為 Gemini Developer API 設定專案。完成工作流程後,請再次嘗試要求。
如果您最近才在 Firebase 控制台中完成 Firebase AI Logic 設定工作流程,則 Gemini 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.」