The
[Build mode in Google AI Studio](https://aistudio.google.com/apps)
can automatically set up and integrate Firebase services into your web and
Android apps:

- **Cloud Firestore** and **Firebase Authentication** (for web and Android apps) to build apps with persistent data storage and secure login flows.
- **Firebase AI Logic** and **Firebase App Check** (for Android apps) to securely call Gemini models directly from your mobile app without exposing API keys.

With just a single prompt and a few clicks, you empower the
Google AI Studio agent to set up a Firebase project, connect your app to that
project, and generate the necessary Firebase code and configuration files
directly in your app.

Learn more about building
[full-stack web apps](https://ai.google.dev/gemini-api/docs/aistudio-fullstack)
and
[Android apps](https://ai.google.dev/gemini-api/docs/aistudio-android)
in the Google AI Studio documentation.

## Overview: Add a backend to your Google AI Studio app

1. **Describe your idea** : Create a new app in Google AI Studio and describe
   a feature that requires a database, authentication, or generative AI (for
   Android apps). For example, you could enter a prompt like:

   - `Build a shared to-do list app using Firebase as a backend.`
   - `Build an Android recipe app that uses Firebase AI Logic to suggest meals from ingredients.`

   > [!TIP]
   > **Tip:** For best results, explicitly ask the agent to use Firebase (or Firebase AI Logic) for your app.

2. **Enable the Firebase integration**: In the card that appears, configure
   your setup:

   1. **Customize project or location** *(optional)* : Click the **Settings**
      icon , then select a
      location or the Google Cloud project you want to use.

   2. **Confirm your selection** : To proceed, click the **Enable Firebase**
      button.

   The agent then automatically sets up the applicable Firebase services in
   your Firebase project, connects your app to your Firebase project, and
   generates the applicable Firebase code and configuration files:
   - **Web apps**:

     - Possible services: Cloud Firestore, Authentication, and Firebase Security Rules
     - Files include `/src/lib/firebase.ts` and `firestore.rules`
   - **Android apps**:

     - Possible services: Cloud Firestore, Authentication, and Firebase Security Rules; if your app uses AI features: Firebase AI Logic and Firebase App Check
     - Files include `google-services.json`, `firestore.rules`, and `firebase_applet_config.xml`

   > [!IMPORTANT]
   > **Important:** The project and location you select for your first integrated feature (such as Cloud Firestore and Authentication) will automatically apply to all other Firebase and Google Cloud services (such as Cloud Run) that you later add to your app. Once set, you can't change the location for these resources set up using Google AI Studio.

3. **Deploy or publish**: Once ready, you can deploy or publish your app:

   - **Web apps** : Use the **Share** \> **Publish** option to deploy your web app to Cloud Run. Your app will automatically deploy to the same project you selected during setup.
   - **Android apps** : Install the app on a physical device via USB for local testing or publish to specific testers in Google Play for internal testing.

   Before sharing, deploying, or publishing your app, also make sure to
   [review the AI-generated Firebase Security Rules](https://firebase.google.com/docs/ai-assistance/ai-studio-integration.md.txt#security-rules).

### Add Firebase to an app during development

If you want to add the Firebase integration to an app that you're
working on in Google AI Studio, you can do so at any time during the
iteration phase using either of the following options:

- **Talk to the agent** : Instruct the agent to add a feature that requires a database, authentication, or generative AI for Android (for example, `Add a Firestore database to this app` or `Add Firebase AI Logic
  to summarize notes`).
- **Use the settings menu** : Go to **Settings** \> **Integrations** and click the **Firebase Firestore \& Auth** tile.

Both options will launch the Firebase integration setup flow, allowing you to
select a project, configure your backend location, and enable the integration
for your app as described in the [overview](https://firebase.google.com/docs/ai-assistance/ai-studio-integration.md.txt#add-backend).

Once the integration is enabled, you can review its configuration--including the
project, location, app support email, and database ID---at any time by going to
**Settings** \> **Integrations** and clicking the **Firebase Firestore \& Auth**
tile.

## Understand the shared quota for Cloud Firestore

Depending on when you created your app, your account eligibility, and your
platform (Starter Tier is not available for Android apps), your
databases may be hosted in a
[Starter Tier](https://docs.cloud.google.com/docs/starter-tier)
project or a standard project. However, in both cases, all the Cloud Firestore
databases provisioned by the Google AI Studio agent are placed in the same
"AI shared quota" group of databases in your project. They all share these
characteristics:

- **Shared quota** : All databases in the group share a usage quota ([see details below](https://firebase.google.com/docs/ai-assistance/ai-studio-integration.md.txt#shared-quota)).
- **No Cloud Billing account required** : You can build and test your app without adding billing. See details [below](https://firebase.google.com/docs/ai-assistance/ai-studio-integration.md.txt#add-billing) about optionally adding billing.
- **Daily resets**: If you hit a daily quota limit (for example, 50k reads/day), the service will pause for all databases within the group and resume the following day at around midnight Pacific Time.

> [!NOTE]
> **Note:** [Projects migrated from Firebase Studio](https://firebase.google.com/docs/studio/migrating-project.md.txt) that have existing Cloud Firestore databases are **not** subject to this shared quota group.

Cloud Firestore databases in the shared quota group share the following
limits:

| Metric | Quota |
|---|---|
| Stored data | 1 GiB total |
| Network egress | 10 GiB per month |
| Write units | 40,000 writes per day |
| Read units | 50,000 reads per day |
| Real-time update units | 50,000 updates per day |

> [!NOTE]
> **Note:** While your app's database usage is subject to the Cloud Firestore shared quota, your Authentication usage is handled separately. The specific daily limits for reads, writes, and storage listed in the table apply only to Cloud Firestore resources.

### *(Optional)* Add billing to get more Cloud Firestore quota

If your app gains traction and you need to move beyond the no-cost limits for
Cloud Firestore, you can add billing which upgrades your Firebase project to
the **pay-as-you-go Blaze pricing plan**.

You might have already added billing for your project for different
reasons, like to use Nano Banana. If this is the case, then your project is
already on the Blaze pricing plan, and you can skip straight to the
[Upgrade the database step](https://firebase.google.com/docs/ai-assistance/ai-studio-integration.md.txt#upgrade-database).

#### Step 1. Add billing (if you haven't already done so)

You can set up billing directly within Google AI Studio.

1. In Google AI Studio, go to the [**Projects** page](https://aistudio.google.com/projects).
2. Click **Set up billing** next to the project you want to upgrade.
3. Follow the on-screen prompts to select your country, agree to terms, and add a payment method or select an existing billing account. You may also be asked for a prepayment (which does *not* apply towards usage of Firebase and Google Cloud services).

**Important** : **Setting up billing in
Google AI Studio automatically creates or upgrades the linked billing
account to a
[Paid billing account](https://cloud.google.com/free/docs/free-cloud-features#how-to-upgrade).** This means ***all*** service usage is subject to standard pay-as-you-go pricing, including any usage of Firebase and other Google Cloud services (with the exception of any Cloud Firestore instances still in the shared quota group).

- If you create a *new* billing account, you may still be eligible to claim [Free Trial Welcome credits](https://cloud.google.com/free/docs/free-cloud-features#free-trial) to use for Firebase and other Google Cloud services.
- If you link an *existing* billing account, you can use any remaining [Free Trial Welcome credits](https://cloud.google.com/free/docs/free-cloud-features#free-trial) for usage of Firebase and other Google Cloud services. Be aware that if you have other projects linked to this billing account, any usage in those projects is also now subject to pay-as-you-go pricing.


Note that setting up billing directly within Google AI Studio is in
**Public Preview**.

#### Step 2: Upgrade the database

Even after adding billing, Cloud Firestore databases created by the
Google AI Studio agent remain in the shared quota group. To enable full paid
scaling for a specific database, you must manually upgrade it.

1. Navigate to the [Firebase console](https://console.firebase.google.com/) and select the project containing the database you want to upgrade.
2. From the left navigation pane, go to **Databases \& Storage** \> **Firestore**.
3. If your project contains multiple Cloud Firestore database instances, select the one you want to upgrade.
4. Look for a banner near the top of the page indicating the database is subject to AI shared quota limits. To upgrade it, click **Upgrade database** \> **Upgrade to pay-as-you-go.** If you don't see this banner, the database either wasn't created by the Google AI Studio agent and isn't part of the shared quota group, or has already been upgraded.

The change to disable the shared quota and enable pay-as-you-go billing for your
database should take effect within a few minutes.
**Important:** Linking a Cloud Billing account doesn't automatically remove the shared quota caps. You must click the **Upgrade database** button in the Firebase console to move it out of the AI shared quota limit.

- **Shared failure** : If the shared quota is exhausted, **all** databases in the group will return errors. They don't have access to the linked billing account.
- **Additional usage** : To enable additional usage for a specific database, you must move that database out of the shared quota group using the **Upgrade database** button. This converts that instance to a regular paid database where ***all*** usage is charged at [Cloud Firestore rates](https://cloud.google.com/firestore/enterprise/pricing#pricing-by-location).

## Security Rules generation

The Google AI Studio agent automatically generates Firebase Security Rules based on your
app's logic. These Security Rules are designed to be "default deny," meaning
end-users of your app can only access the data they own.
**Important:** Keep the following in mind when using generative AI with your app:

- Generative AI can make mistakes. Always check its changes or output before deploying to production.
- Frequently commit snapshots of your code, especially before making major changes to your app.
- Use this AI-assisted approach at your own risk. Google and Firebase are not liable for any security vulnerabilities in AI-generated Security Rules. It's your responsibility to review and test the generated Security Rules before deploying them to production.

Note that if you manually adjust your Security Rules directly in the
Firebase console, the Google AI Studio agent won't know about the changes,
and they will be overwritten during subsequent app iterations. We recommend
using the Google AI Studio agent to adjust your Firebase Security Rules to ensure your
changes are preserved and aligned with your app's logic.

## Firebase AI Logic and App Check for Android apps

When you build an **Android app** that includes generative AI features in
Google AI Studio, the agent automatically integrates
[**Firebase AI Logic**](https://firebase.google.com/docs/ai-logic.md.txt) and enforces
[**Firebase App Check**](https://firebase.google.com/docs/ai-logic/app-check.md.txt).

Unlike web apps in Google AI Studio---which execute Gemini API calls from a
server-side runtime on Cloud Run---Android apps are distributed as
client-side binaries (APKs). Embedding a raw Gemini API key directly into an APK
exposes the key to extraction and potential billing abuse. Using
Firebase AI Logic with App Check protects your project by verifying that
requests to the Gemini API originate from an authentic instance of your app.

### How App Check works across testing and production

Google AI Studio configures App Check so that your app works securely
without manual setup,
whether you're testing a prototype or publishing to Google Play.

- **Testing and sharing (debug builds)** : When you preview your app in the Google AI Studio emulator, install it on your phone via USB, or share it with trusted testers in Google AI Studio, the app uses an **App Check debug token** that Google AI Studio manages automatically behind the scenes. Collaborators can test AI features right away without seeing your API keys or secrets.
- **Publishing to Google Play (release builds)** : When you build a release version for Google Play, your app automatically switches to **reCAPTCHA Enterprise** for production attestation using a pre-configured site key. You don't need to manually link Google Play or configure App Check providers before publishing.

## Use an existing project

When you first enable the Firebase integration, you can optionally select an
existing Google Cloud project that you own:

1. In the card that pops up, click the **Settings** icon .
2. Select your project, and then click **Enable Firebase**.

As you iterate on your app, you can also instruct the agent to use a different
project with a prompt such as:

    Add Firestore to this app using project PROJECT_ID.

When you choose a project, the following actions occur:

- **A new Cloud Firestore database will be provisioned into that project** using the shared quota.
- **Firebase Authentication with Google Sign-In will be configured.**
- **For Android apps using generative AI, Firebase AI Logic,
  Firebase App Check, and reCAPTCHA Enterprise will be
  set up.** App Check is automatically enforced for Firebase AI Logic to protect your API quota.
- **A service account will be granted access to your Cloud Firestore database.** To allow administrator access from Google AI Studio, a new service account named `ais-sandbox@PROJECT_ID.iam.gservice.com` will be granted permission to access your Cloud Firestore database. This account is associated only with your Google AI Studio apps.
- **Limitations** : If the Firebase project already has a Cloud Firestore database, the agent won't be able to add an additional one. You'll need to select a different project or create a new, empty project to use.

## Use the Firebase console

You can view your app's data and settings in the Firebase console. Here's how
to access the Firebase project associated with Google AI Studio:

1. Navigate to the
   [Firebase console](https://console.firebase.google.com/) and
   select the project with a label of `AI Studio`.

2. From the left navigation pane, explore the enabled services in your project:

   - To view and edit your stored Cloud Firestore data, go to **Databases \& Storage** \> **Firestore**.
   - To view or configure Authentication settings and data, go to **Security** \> **Authentication**.
   - To monitor usage, view quotas, or configure settings for Firebase AI Logic, go to **AI** \> **AI Logic**.
   - To manage App Check enforcement, monitor attestation requests, or revoke debug tokens, go to **Security** \> **App Check**.

## Troubleshooting and FAQ

Find answers to common questions and learn how to resolve issues when
integrating Firebase with your Google AI Studio app.

### How is my Google Cloud / Firebase project and location selected?

When you request a Firebase backend for an app, you can optionally select a
location and project in the card that appears:

- **Customize project or location** *(optional)* : Click the **Settings** icon , select a location or the Google Cloud project you want to use, and then click **Enable Firebase**.

Keep the following in mind:

- **Database location is permanent**: Once you select a location for your database, you can't change it for that project. This choice will be used as the default for other backend services.
- **Project consistency** : To ensure a seamless integration, Google AI Studio automatically uses the same project for both your backend and your deployment. You can't use different projects for different services within the same app.

### What authentication methods are supported?

The Google AI Studio agent sets up Google Sign-In when you ask to set up
Authentication or a sign-in screen. Here's how to add additional sign-in methods to
your app:

1. In the Firebase console, go to the **Security** \> **Authentication** \>
   [**Sign-in method** page](https://console.firebase.google.com/project/_/authentication/providers),
   and configure any desired sign-in methods.

2. Back in Google AI Studio, ask the Google AI Studio agent for
   assistance updating your codebase with the new sign-in method.

### Can I create a mobile app (like Android or iOS) with Google AI Studio?

The Google AI Studio agent supports creating both **web apps** and
**Android apps** . The Firebase integration supports adding **Cloud Firestore** and
**Authentication** to both web and Android apps, and additionally supports
**Firebase AI Logic** and **Firebase App Check** for **Android apps**.

Creating iOS apps isn't supported in Google AI Studio. However, just like
all web apps, the web apps that Google AI Studio creates can be accessed
as *mobile web apps* from browsers that are installed on mobile devices
(including iOS).

Learn more about building Android apps in the
[Google AI Studio documentation](https://ai.google.dev/gemini-api/docs/aistudio-android).

### Why is Firebase AI Logic and App Check integration only used for Android apps and not web apps?

Android apps are distributed as client-side binaries (APKs). If an Android app
called the Gemini API directly using a standard API key, anyone could decompile
the APK, extract the key, and make unauthorized requests. To prevent this,
Android apps built in Google AI Studio use Firebase AI Logic together
with Firebase App Check to verify that requests come from an authentic
instance of your app.

Web apps built in Google AI Studio, on the other hand, execute Gemini API
requests from a secure server-side runtime (hosted on Cloud Run when
deployed) using the Google Gen AI SDK. Because the API key remains on the server
and is never exposed to the client browser, client-side Firebase AI Logic
and App Check aren't required for web apps structured like this.

### What is the `firebase-blueprint.json` file?

This is an intermediate file used by the Google AI Studio agent to understand
your app's codebase. Don't modify this file manually, as it may cause the agent
to generate incorrect code or insecure Security Rules.

### What should I do if I get a "Quota exceeded" error?

Hitting a Cloud Firestore quota limit means your app has reached its daily
usage cap for your Cloud Firestore database shared quota group. There are two
ways to resolve this:

- **Option 1: Wait**: Quotas reset daily around midnight Pacific Time.
- **Option 2: Upgrade** : Upgrade to the pay-as-you-go Blaze pricing plan.
  - If the Google AI Studio agent set up Cloud Firestore for you, you must then use the **Upgrade database** button described in [Add billing to get more Cloud Firestore quota](https://firebase.google.com/docs/ai-assistance/ai-studio-integration.md.txt#add-billing) to move your database into a regular paid state. If you set up Cloud Firestore manually, then using the **Upgrade database** button isn't necessary.

### What should I do if I get a "Missing or insufficient permissions" error?

This error occurs when your app attempts to read or write data to your
Cloud Firestore database, but the request is rejected by your
Security Rules. It indicates that the Security Rules are not allowing the
attempted operation based on the current authentication state or data path.
Click the **Fix error** button to prompt the Google AI Studio agent to
attempt to correct the Security Rules.

### What happens to my Firebase backend when I delete my Google AI Studio app?

Deleting your application in Google AI Studio doesn't automatically delete
the connected Firebase project, Cloud Firestore database, or Firebase Authentication
configurations.

If you added a Firebase backend, you must manually go to the
[Firebase console](https://console.firebase.google.com/)
and delete the project or clean up individual resources (such as the
Cloud Firestore database instance and Authentication providers) to ensure all data and
configurations are removed.

### Can the Google AI Studio agent delete or edit data in my Cloud Firestore database?

The Google AI Studio agent is designed to help provision the necessary
backend resources and generate code and Security Rules. While the agent itself
can't directly delete, edit, or manipulate data entries within your
Cloud Firestore database, it can write code into your app that is designed to
perform these actions. To perform data management tasks, such as deleting
entries, go to the **Databases \& Storage** \>
[**Firestore** page](https://console.firebase.google.com/project/_/firestore)
in the Firebase console.

### I belong to an organization that uses Google Cloud; can I connect my Google AI Studio app to an existing project within my organization's Google Cloud environment?

Yes. Ensure your Firebase project is placed within your Google Cloud
organization folder, and then connect your project using one of the following
methods:

- **During enablement** : When you first enable the Firebase integration in Google AI Studio, select your existing project in the card that appears. Click the **Settings** icon and select your project.
- **During iteration**: If you've already enabled Firebase or want to
  switch projects later, you can instruct the agent to use your existing
  project with a prompt such as:

        Add Firestore to this app using project PROJECT_ID.

### Why can't I find certain documents in the Firebase console?

When the AI Studio agent saves data to a nested path
(like `/users/user1/messages/msg1`) without first creating the parent document
(`user1`), it creates what is known as a *non-existent parent document* . These
documents aren't displayed in the Firebase console, which can make them
difficult to find when browsing your Cloud Firestore database. While this doesn't
affect how your app runs, you can often describe the issue to the AI Studio
agent to prompt it to create the missing parent documents.

For more details, see
[Non-existent parent documents](https://firebase.google.com/docs/firestore/using-console.md.txt#non-existent-parent-documents).

### Can I choose the location for my Cloud Firestore database?

Yes. When you first enable the Firebase integration in Google AI Studio, you
can [select the location for your Cloud Firestore database](https://firebase.google.com/docs/ai-assistance/ai-studio-integration.md.txt#add-backend).

Keep in mind that the location you select applies to **all** Cloud Firestore
databases that the Google AI Studio agent creates in that Firebase project.
Once set, this location cannot be changed for those databases.

### After upgrading a Cloud Firestore database, can I return it to the shared quota group?

Once a database has been moved out of the shared quota group and converted to a
regular paid instance, you can use a `curl` command to return
it to the shared quota group. Note that all databases within the shared quota
group must be the same edition and be located in the same region.

- <var translate="no">PROJECT_ID</var> : Firebase project ID.
  Find this ID in the
  **Settings** \>
  [**General** page](https://console.firebase.google.com/project/_/settings/general/)
  of the Firebase console.

- <var translate="no">DATABASE_ID</var> : Cloud Firestore database ID, which will
  match your applet ID.
  Find this database ID in Google AI Studio by going to **Settings** \>
  **Integrations** and clicking the **Firebase Firestore \& Auth** tile.

```bash
curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://firestore.googleapis.com/v1/projects/PROJECT_ID/databases/DATABASE_ID?updateMask=free_tier_limited" \
-d '{"free_tier_limited": true}'
```

### How does Google use my data (for example, code and prompts) in Google AI Studio?

Refer to the
[Gemini API Additional Terms of Service](https://ai.google.dev/gemini-api/terms)
for details on how your data is used.

### I received an email from Google Cloud about a "publicly accessible Google API key for your Google Cloud project". What do I need to do?


If you've received an email from Google Cloud about a "publicly accessible
Google API key for your Google Cloud project" *and the API key listed in
the email is your Firebase API key* , then make sure that the API key meets
the following requirements to be safe to include in your code or configuration
files. You can verify the following in the **APIs \& Services** \>
[**Credentials** page](https://console.cloud.google.com/apis/credentials)
of the Google Cloud console.

- It's the API key that you use for your Firebase app and *only* for Firebase services. These keys are usually called `Browser key (auto created by Firebase)` or `Android key (auto created by Firebase)` or `iOS key (auto created by Firebase)`.
- It has all the [required
  Firebase-related APIs included in the key's "API restrictions"
  allowlist](https://firebase.google.com/docs/projects/api-keys#faq-required-apis-for-restricted-firebase-api-key).
- It does *not* have any other APIs in its "API restrictions" allowlist. In particular, the list should ***not*** have `Generative Language API`.


Also, make sure that you're using Firebase Security Rules and App Check as recommended
for the Firebase products that you use.

You can learn details about API keys for Firebase and find a list of FAQs in
[Learn about using and managing API keys for
Firebase](https://firebase.google.com/docs/projects/api-keys)
**Important** : The API key that you use for calls to the Gemini Developer API in your app should *never* be included in your code or configuration files. It must be protected from public exposure. In the Google Cloud console, it will be called `Gemini API Key` or `Gemini Developer API key (auto created by Firebase)`, and it will be restricted to the `Generative Language API`.