This page provides troubleshooting of common error codes for the Gemini API and the Firebase AI Logic SDKs.
If you receive a 400 error that says
API key not valid. Please pass a valid API key., it usually means that the
API key in your Firebase configuration file/object doesn't exist or isn't setup
to be used with your app and/or Firebase project.
Check that the API key listed in your Firebase configuration file/object matches the API key for your app. You can view all your API keys in the APIs & Services > Credentials panel in the Google Cloud console.
If you discover that they don't match, then obtain a fresh Firebase configuration file/object, and then replace the one that's in your app. The fresh config file/object should contain a valid API key for your app and Firebase project.
If you're trying to send a multimodal request with a Cloud Storage for Firebase
URL, you might encounter the following 400 error:
Service agents are being provisioned ... Service agents are needed to read the Cloud Storage file provided.
This error is caused by a project that didn't have the required service agents correctly auto-provisioned when the Vertex AI API was enabled in the project. This is a known issue with some projects, and we're working on a global fix.
Here's the workaround to fix your project and correctly provision these service agents so that you can start including Cloud Storage for Firebase URLs in your multimodal requests. You must be an Owner on the project, and you only need to complete this set of tasks once for your project.
Access and authenticate with the gcloud CLI.
The easiest way to do this is from Cloud Shell. Learn more in the Google Cloud documentation.If prompted, follow the instructions displayed in the terminal to make the gcloud CLI run against your Firebase project.
You'll need your Firebase project ID, which you can find at the top of the Project settings in the Firebase console.
Provision the required service agents in your project by running the following command:
curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" -H "Content-Type: application/json" https://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/endpoints -d ''
Wait a few minutes to ensure that the service agents are provisioned, and then retry sending your multimodal request that includes the Cloud Storage for Firebase URL.
If you're still getting this error after waiting several minutes, reach out to Firebase Support.
If you receive a 403 error that says
Requests to this API firebasevertexai.googleapis.com ... are blocked., it
usually means that the API key in your Firebase configuration in your app has
restrictions that prevent it from calling the required API.
To fix this, you need to update your API key's restrictions in the
Google Cloud console to include the required API. For Firebase AI Logic,
you must ensure the Firebase AI Logic API
(firebasevertexai.googleapis.com) is included in the list of selected
APIs that can be called using the API key.
Follow these steps:
In the Google Cloud console, open the APIs & Services > Credentials panel.
Select the API key that your application is configured to use (for example, the "iOS key" for an iOS app).
On the Edit API key page, find the API restrictions section.
Ensure the Restrict key option is selected. If it isn't, your key is unrestricted, and this is likely not the source of the error.
In the Selected APIs drop-down menu, search for and select the Firebase AI Logic API to add it to the list of selected APIs that can be called using the API key.
Click Save.
It may take up to five minutes for the changes to take effect.
If you receive a 403 error that says
PERMISSION_DENIED: The caller does not have permission., it usually means that
the API key in your Firebase configuration file/object belongs to a different
Firebase project.
Check that the API key listed in your Firebase configuration file/object matches the API key for your app. You can view all your API keys in the APIs & Services > Credentials panel in the Google Cloud console.
If you discover that they don't match, then obtain a fresh Firebase configuration file/object, and then replace the one that's in your app. The fresh config file/object should contain a valid API key for your app and Firebase project.
If you're attempting to use the Gemini Developer API and you receive a
404 error that says Firebase AI Logic genai config not found, it usually means
that your Firebase project doesn't have a valid Gemini API key for use
with the Firebase AI Logic client SDKs.
Here are the most likely causes of this error:
You haven't yet set up your Firebase project for the Gemini Developer API.
What to do:
In the Firebase console, go to the Firebase AI Logic page. Click Get started, and then select the Gemini Developer API. Enable the API, and the console will set up your project for the Gemini Developer API. After completing the workflow, try your request again.If you very recently went through the Firebase AI Logic setup workflow in the Firebase console, then your Gemini API key might not yet be available to all required backend services in all regions.
What to do:
Wait a few minutes, and then try your request again.Your Gemini API key might have been deleted from your Firebase project.
What to do:
Learn how to change the Gemini API key used by Firebase AI Logic.
For example: "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."
There are a couple different reasons why you could get an error like this.
Invalid model name
Cause: The model name you've provided isn't a valid model name.
Fix: Check your model name and model version against the list of all supported and available models. Be sure to check the segments and their order in the model name. For example:
- The Gemini 3.1 Pro preview model name is
gemini-3.1-pro-preview. - The Gemini 3 Flash preview model name is
gemini-3-flash-preview. - The "Nano Banana Pro" preview model name is
gemini-3-pro-image-preview. - The "Nano Banana 2" preview model name is
gemini-3.1-flash-image-preview. - The "Nano Banana" model name is
gemini-2.5-flash-image.
- The Gemini 3.1 Pro preview model name is
Invalid location (only applicable if using the Vertex AI Gemini API provider and a preview or experimental model)
Cause: You're using a preview or experimental version of a model (for example,
gemini-3.1-pro-previewandgemini-3.1-flash-image-preview), and you didn't specify thegloballocation.If you use the Vertex AI Gemini API, all preview and experimental Gemini models (except Gemini Live models) are only available in the
globallocation. However, since Firebase AI Logic defaults to the location, you need to explicitly specify theus-central1globallocation when initializing the Vertex AI Gemini API backend service in your code when using these preview and experimental Gemini models.Fix: When you initialize the Vertex AI Gemini API service, specify the location
global. Learn more about how to specify the location for accessing the model (including code snippets).
Invalid location (only applicable if using the Vertex AI Gemini API provider)
Cause: You're using a model that's not supported in the location where you're trying to access it.
If you use the Vertex AI Gemini API, some models are only available in specific locations. For example (but not exhaustive):
- Imagen models are not supported in the
globallocation. - Gemini Live API models (like
gemini-2.0-flash-live-preview-04-09) are only supported in the location.us-central1 - Gemini 2.5 models (like
gemini-2.5-pro) are only available in thegloballocation, the US locations, and some European locations (and sometimes in other locations if your project has special options).
- Imagen models are not supported in the
Fix: When you initialize the Vertex AI Gemini API service, make sure that you specify a supported location for the model that you're using. Learn more about how to specify the location for accessing the model (including code snippets) and the supported locations for models.
Note that Firebase AI Logic defaults to the
location.us-central1
429 errors indicate that you're either going over your quota or the model you're accessing is overloaded by requests from other people.
The action to take depends on whether you're using the Gemini Developer API or Vertex AI Gemini API. For more information about quotas and how to request additional quota, see Rate limits and quotas.
If you're using the Vertex AI Gemini API, the Google Cloud documentation provides some additional context and guidance for Error code 429.