> [!WARNING]
> **Preview**: Using server prompt templates is a feature that's in Preview, which means that it isn't subject to any SLA or deprecation policy and could change in backwards-incompatible ways.

<br />

You can enforce ***template-only mode*** for your Firebase project so that all
Gemini API requests via Firebase AI Logic must use
server prompt templates.

When a request is blocked, the response will be a `403: unauthorized` error.

## Important considerations

Be aware of the following important considerations for template-only mode.

### When template-only mode is enforced

When template-only mode is enforced, be aware of the following:

- This setting is a ***project-wide*** setting for Firebase AI Logic.

  - It applies to all apps registered in the project.
  - It only applies to the project where it's enforced.
- This setting applies to ***all*** requests via Firebase AI Logic to both
  the Gemini Developer API and the Agent Platform Gemini API (formerly Vertex AI).

- This setting ***blocks*** any requests via Firebase AI Logic that do
  *not* use server prompt templates. This includes blocking requests from your
  app that use
  [not-yet-supported capabilities for server prompt templates](https://firebase.google.com/docs/ai-logic/server-prompt-templates/best-practices-and-considerations.md.txt#limitations-ai-logic-capabilities).

- This setting does ***not block*** Gemini API requests in your project
  that are *not* via Firebase AI Logic.

- If you're using the
  [Firebase AI Logic REST API](https://firebase.google.com/docs/reference/ai-logic/rest.md.txt):

  - This setting does ***not block*** *inference* requests which use server prompt templates (like using `templateGenerateContent` or `templateStreamGenerateContent`).
  - This setting does ***not block*** *control-plane* requests (like those for managing templates and configurations).
- This setting does ***not block*** requests to `countTokens` (the
  Count Tokens API).

### Before enforcing template-only mode

Be aware of the following *before* you enforce template-only mode:

- If you have existing versions of your app that do *not* use server
  prompt templates:

  - This setting will ***block*** requests via Firebase AI Logic from those existing app versions.
  - Make sure that all active clients are updated to use server prompt templates *before* enforcing template-only mode.
- If your app uses
  [not-yet-supported capabilities for server prompt templates](https://firebase.google.com/docs/ai-logic/server-prompt-templates/best-practices-and-considerations.md.txt#limitations-ai-logic-capabilities):

  - This setting will ***block*** requests via Firebase AI Logic for these not-yet-supported capabilities because they don't (and can't) use server prompt templates.
  - Make sure that your app (including any past version) doesn't actively use any of those not-yet-supported capabilities *before* enforcing template-only mode.

> [!NOTE]
> **Note:** If you've enabled [AI monitoring](https://firebase.google.com/docs/ai-logic/monitoring.md.txt#ai-monitoring-in-console), then you can see which requests use server prompt templates. You can find this information when you click into the **Details** of a trace in the [**Trace Explorer**](https://console.cloud.google.com/traces/explorer) in the Google Cloud console (and it's coming soon to the Firebase console!).

## Manage the template-only mode setting

You manage the setting for template-only mode in the Firebase console.

### Required IAM permissions and roles

Managing the template-only mode setting requires the
`firebasevertexai.configs.update` permission, which is included by default in
these IAM roles: Owner, Editor, Firebase Admin, and Firebase AI Logic Admin.

### Enforce template-only mode

Here's how to enforce template-only mode for your Firebase project:

1. If you haven't already, review the
   [important considerations](https://firebase.google.com/docs/ai-logic/server-prompt-templates/template-only-mode.md.txt#important-considerations)
   for template-only mode earlier in this guide.

2. In the Firebase console, go to the **AI Services** \> **AI Logic** \>
   [**Settings** tab](https://console.firebase.google.com/project/_/ailogic/templates?useAutoProject=true).

3. Under **Template mode** , slide the toggle for **Enforce template-only mode**
   to **Enforced**.

4. Review the confirmation dialog, and then click **Confirm**.

### Stop enforcement of template-only mode

If you stop enforcement of template-only mode, be aware of the following:

- Requests via Firebase AI Logic that do *not* use server prompt templates will be allowed.
- This is a *project-wide* setting for Firebase AI Logic.

Here's how to stop enforcement of template-only mode for your Firebase project:

1. In the Firebase console, go to the **AI Services** \> **AI Logic** \>
   [**Settings** tab](https://console.firebase.google.com/project/_/ailogic/templates?useAutoProject=true).

2. Under **Template mode** , turn off **Enforce template-only mode**.

3. Review the confirmation dialog, and then click **Confirm**.