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 Vertex AI Gemini API.
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.
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:
- This setting does not block inference requests
which use server prompt templates (like using
templateGenerateContentortemplateStreamGenerateContent). - This setting does not block control-plane requests (like those for managing templates and configurations).
- This setting does not block inference requests
which use server prompt templates (like using
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:
- 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.
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:
If you haven't already, review the important considerations for template-only mode earlier in this guide.
In the Firebase console, go to the AI Services > AI Logic > Settings tab.
Under Template mode, slide the toggle for Enforce template-only mode to Enforced.
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:
In the Firebase console, go to the AI Services > AI Logic > Settings tab.
Under Template mode, turn off Enforce template-only mode.
Review the confirmation dialog, and then click Confirm.