Starting November 2, 2026, Firebase App Check enforcement will be required to use Firebase AI Logic. Learn more.
Model updates:
The latest Gemini models, like Gemini 3.8 Flash, are available to use with
Firebase AI Logic! Learn more.
Gemini 2.5 models are limited to projects that actively used them in the past. For the
Agent Platform Gemini API, these models will shut down for all projects in
October 2026. To avoid service disruptions, update to a newer model (like
gemini-3.8-flash or
gemini-3.1-flash-image).
Any stable Gemini Live API 2.5 models are not impacted.
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 控制台的「API 和服務」>「憑證」面板中,查看所有 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.
如果專案啟用 Agent Platform API 時,未正確自動佈建必要的服務代理,就會發生這個錯誤。這是部分專案的已知問題,我們正在設法全面修正。
以下是解決專案問題的替代方案,可正確佈建這些服務代理程式,讓您開始在多模態要求中加入 Cloud Storage for Firebase 網址。您必須是專案的「擁有者」,且專案只需要完成一次這組工作。
403 錯誤:PERMISSION_DENIED: Firebase AI Logic has been deactivated in this project. To resume using Firebase AI Logic, you must enforce Firebase App Check. Learn more: https://firebase.google.com/docs/ai-logic/app-check
如果收到 403 - PERMISSION_DENIED 錯誤,且錯誤訊息為 Firebase AI Logic has been deactivated in this project. To resume using
Firebase AI Logic, you must enforce Firebase App Check. Learn more:
https://firebase.google.com/docs/ai-logic/app-check,表示系統判定您的 Firebase 專案處於閒置狀態,且您未對 Firebase AI Logic 強制執行 App Check。
「閒置專案」是指已啟用 Firebase AI Logic,但近期沒有任何 Firebase AI Logic 用量的專案。
由於您未對 Firebase AI Logic 強制執行 App Check,您的專案容易遭到 Gemini API 濫用。為保護專案,Firebase 已停用 Firebase AI Logic 的使用權,直到您對 Firebase AI Logic 強制執行 App Check 為止。
如果已強制執行 App Check,但仍收到這項錯誤訊息,請檢查
Firebase AI Logic 是否已
開啟重播保護機制 (包括「僅監控」模式)。
開啟重放攻擊防護機制後,只有限次使用權杖會計為 Firebase AI Logic 的已驗證權杖;一般工作階段權杖不會清除這項錯誤。請在應用程式中啟用限用權杖,或關閉 Firebase AI Logic 的重播保護機制,重新傳送要求,並等待約一天後再重新啟用重播保護機制 (系統每天會重新評估專案活動)。
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 控制台的「API 和服務」>「憑證」面板中,查看所有 API 金鑰。
如果發現不相符,請取得新的 Firebase 設定檔/物件,然後取代應用程式中的設定檔/物件。新的設定檔/物件應包含應用程式和 Firebase 專案的有效 API 金鑰。
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 清單。
在「選取的 API」下拉式選單中,搜尋並選取要新增的 Firebase AI Logic API,將其加入可使用 API 金鑰呼叫的 API 清單。
按一下 [儲存]。
變更最多可能需要五分鐘才會生效。
404 錯誤:Firebase AI Logic genai config not found
如果收到「404」錯誤,通常表示 Firebase AI Logic 的設定有誤或遺漏。Firebase AI Logic genai config not found
造成這項錯誤最可能的原因如下:
您尚未為 Gemini API 供應商設定 Firebase 專案。
解決方法:
在 Firebase 控制台中,依序前往「AI Services」(AI 服務) >「AI Logic」(AI 邏輯)。按一下「開始使用」,然後選取您選擇的 Gemini API 供應商。啟用 API 後,Firebase 會為該供應商設定專案。完成工作流程後,請再次嘗試提出要求。
如果您最近才在 Firebase 控制台中完成 Firebase AI Logic 設定工作流程,則 Firebase AI Logic 設定可能尚未在所有適用區域的所有必要後端服務中生效。
解決方法:
稍候幾分鐘,然後再試一次。
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.1-pro-preview was not found or your project does not have access to it. Please ensure you are using a valid model version.」