When you call the Gemini API directly from your mobile and web apps,
protecting your backend infrastructure, quota, and proprietary prompts requires
a multi-layered defense-in-depth approach. Review this checklist to implement
recommended security best practices for Firebase AI Logic.
[Video](https://www.youtube.com/watch?v=YoZhjftm6v4)

- [**App, device, and user verification**](https://firebase.google.com/docs/ai-logic/security-checklist.md.txt#app-device-user-verification)

  - [Enforce Firebase App Check with limited-use tokens](https://firebase.google.com/docs/ai-logic/security-checklist.md.txt#enforce-app-check)
  - [Set up restrictions for your Firebase API keys](https://firebase.google.com/docs/ai-logic/security-checklist.md.txt#set-up-api-key-restrictions)
  - [Restrict requests to only authenticated users](https://firebase.google.com/docs/ai-logic/security-checklist.md.txt#auth-mode)
- [**Prompt protection and request hardening**](https://firebase.google.com/docs/ai-logic/security-checklist.md.txt#prompt-hardening)

  - [Use server prompt templates](https://firebase.google.com/docs/ai-logic/security-checklist.md.txt#server-prompt-templates)
  - [Enforce template-only mode](https://firebase.google.com/docs/ai-logic/security-checklist.md.txt#template-only-mode)
- [**Monitoring, limits, and billing**](https://firebase.google.com/docs/ai-logic/security-checklist.md.txt#monitoring-limits-billing)

  - [Set up AI monitoring in the Firebase console](https://firebase.google.com/docs/ai-logic/security-checklist.md.txt#ai-monitoring)
  - [Set rate limits and manage quotas](https://firebase.google.com/docs/ai-logic/security-checklist.md.txt#rate-limits-and-quotas)
  - [Avoid surprise bills with alerts and spend caps](https://firebase.google.com/docs/ai-logic/security-checklist.md.txt#avoid-surprise-bills)

> [!IMPORTANT]
> **Key Point:** You can complete many of these checklist items as soon as you start developing your app and well before launching to production.  
> **Most importantly, it's *critical* that you enforce
> [Firebase App Check](https://firebase.google.com/docs/ai-logic/app-check.md.txt)
> for all versions of your app.**

## App, device, and user verification

Verify that incoming requests originate from legitimate, untampered instances of
your app running on authentic devices, as well as from authentic users.

### Yes *Enforce* Firebase App Check

**Enforce [Firebase App Check](https://firebase.google.com/docs/ai-logic/app-check.md.txt)** to help protect
the Gemini API from abuse when it's called directly from your app. When
App Check is enforced, it verifies that incoming requests originate from
your authentic app and/or an untampered device.

App Check supports attestation providers for
Apple platforms (DeviceCheck, App Attest, or reCAPTCHA Enterprise),
Android (Play Integrity or reCAPTCHA Enterprise), and
Web (reCAPTCHA Enterprise). It supports all these providers for Flutter
and Unity apps, too.

Starting in early July 2026, Firebase automatically enforces App Check for
Firebase AI Logic during the guided setup in the Firebase console. If you
set up Firebase AI Logic earlier, make sure to
[enforce App Check explicitly](https://firebase.google.com/docs/ai-logic/app-check.md.txt#enforce-app-check).
For local development, you can set up the
[App Check *debug provider*](https://firebase.google.com/docs/ai-logic/app-check.md.txt#configure-debug-provider),
and then register your app with a production attestation provider before
releasing to end users.

> [!WARNING]
> **Warning:** **Starting November 2, 2026, Firebase App Check
> enforcement will be *required* to use Firebase AI Logic.** [Learn more.](https://firebase.google.com/docs/ai-logic/faq-and-troubleshooting.md.txt#security-app-check)

#### Enable replay protection with limited-use tokens

As part of setting up App Check, consider **enforcing
[*replay protection*](https://firebase.google.com/docs/ai-logic/app-check.md.txt#replay-protection)** so that
App Check tokens are *one-time-use only*. This option offers enhanced
protection beyond the baseline protection and lets you set an appropriate level
of protection for your app and use cases.

### Yes Set up restrictions for your Firebase API keys

Firebase API keys identify your Firebase project and app when making requests.
To prevent unauthorized use of your API keys:

- Set
  ["Application restrictions"](https://cloud.google.com/docs/authentication/api-keys#adding_application_restrictions)
  in the Google Cloud console to limit key usage to only requests from your
  app's specific bundle ID (Apple),
  package name and SHA-1 fingerprint (Android), or HTTP referrer (Web).

- Review each key's
  ["API restrictions"](https://cloud.google.com/docs/authentication/api-keys#adding_api_restrictions)
  allowlist:

  - Ensure that Firebase AI Logic API (`firebasevertexai.googleapis.com`) is in the allowlist.
  - Ensure that the only other APIs on the allowlist are the specific Firebase services required by your app. See the [list of required APIs for restricted Firebase keys](https://firebase.google.com/docs/projects/api-keys.md.txt#faq-required-apis-for-restricted-firebase-api-key).

Note that Firebase-related APIs use API keys only to *identify* the Firebase
project or app, *not for authorization* to call the API.

### Yes Restrict requests to only authenticated users

Consider **enforcing [*authenticated-users mode*](https://firebase.google.com/docs/ai-logic/auth-mode.md.txt)** so
that all requests via Firebase AI Logic must include valid credentials from
[Firebase Authentication](https://firebase.google.com/docs/auth.md.txt). If a request comes from an unauthenticated end
user, the request is rejected with a `401: unauthenticated` error.

> [!IMPORTANT]
> **Important:** Authenticated-users mode is a project-wide setting and requires that all your apps in the project that use Firebase AI Logic also use Firebase Authentication. Before enforcing this mode in production, make sure that all active, distributed versions of your app authenticate users before your app sends requests to Firebase AI Logic.

## Prompt protection and request hardening

Prevent client decompilation from exposing your prompt designs, and lock down
your backend so malicious users cannot execute arbitrary prompts.

### Yes Use server prompt templates

**Use
[server prompt templates](https://firebase.google.com/docs/ai-logic/server-prompt-templates/get-started.md.txt)**
to keep prompts, system instructions, and model configurations securely in the
cloud, rather than hard coding them in client app code where they can be
extracted using binary decompilation.

Your app only references a template ID and passes dynamic input variables.
Server prompt templates also let you update prompts or switch models on demand
without releasing a new version of your app.

#### Validate and sanitize client-provided template variables

Server prompt templates protect your prompt design, but templates that accept
dynamic variables can still be susceptible to prompt injection. Because
templates concatenate user input variables into the final prompt, make sure to
do the following:

- Validate and sanitize all user input on the client before passing variables to a template (such as enforcing character limits and expected formats).
- Include clear system instructions in your templates that define guardrails for how user input is processed.

### Yes Enforce template-only mode

Consider **enforcing
[template-only mode](https://firebase.google.com/docs/ai-logic/server-prompt-templates/template-only-mode.md.txt)**
once all your app features use server prompt templates. When enforced,
Firebase AI Logic blocks all direct, un-templated requests to the
Gemini API (`403: unauthorized`), preventing malicious actors from sending
arbitrary prompts or abusing your quota.

> [!IMPORTANT]
> **Important:** Template-only mode is a project-wide setting. Before enforcing this mode in production, make sure that all active, distributed versions of your app use server prompt templates.

## Monitoring, limits, and billing

Gain visibility into incoming traffic and security anomalies, and protect your
project from unexpected usage spikes or runaway costs.

### Yes Set up AI monitoring in the Firebase console

**Set up
[AI monitoring in the Firebase console](https://firebase.google.com/docs/ai-logic/monitoring.md.txt#ai-monitoring-in-console)**
to gain visibility into key metrics, like request counts, latency, token usage,
and error rates (including `401` auth failures and `403` template-only blocks).
You can also inspect individual traces in the Google Cloud console.

### Yes Set rate limits and manage quotas

Protect your project from unexpected usage spikes and denial-of-wallet attacks:

- [Set rate limits per user](https://firebase.google.com/docs/ai-logic/quotas.md.txt#per-user-rate-limits) (default is 100 RPM) to prevent individual client instances from consuming excessive quota.
- [Review and manage project quotas](https://firebase.google.com/docs/ai-logic/quotas.md.txt#edit-quota-or-request-quota-increase) in the Google Cloud console for each underlying API.

### Yes Avoid surprise bills with alerts and spend caps

If your Firebase project is on the pay-as-you-go Blaze pricing plan:

- [Monitor your usage.](https://firebase.google.com/docs/ai-logic/monitoring.md.txt)

- Set up
  [**budget alerts**](https://firebase.google.com/docs/projects/billing/avoid-surprise-bills.md.txt#set-up-budgets)
  and
  [**spend caps**](https://firebase.google.com/docs/projects/billing/avoid-surprise-bills.md.txt#set-up-spend-cap).

## Next steps

- Review the general [Firebase security checklist](https://firebase.google.com/support/guides/security-checklist.md.txt).
- Review the general [Production checklist for Firebase AI Logic](https://firebase.google.com/docs/ai-logic/production-checklist.md.txt).
- Learn more about [pricing and cost management](https://firebase.google.com/docs/ai-logic/pricing.md.txt) for Firebase AI Logic.