For Firebase AI Logic, the Firebase console provides a guided UI for you to specify the contents of a template. However, there are several use cases where you may need more advanced ways to set up a template, including:
The advanced workflows described in this page use the Firebase AI Logic REST API.
Important information about using the REST API
If a template is unlocked, then you can overwrite the template by using the same template ID in your REST API call. A locked template cannot be overwritten.
When you create a server prompt template via REST API and you set its location to
global, then the server prompt template is automatically provisioned in all locations (includingglobal), and it's available to use with both Gemini API providers. However, if you set any other location when creating the template via REST API, then the template will only be available to the Vertex AI Gemini API. Learn more about setting a specific location for a template later on this page.Note that when you use the guided UI in the Firebase console, the template is also automatically provisioned in all locations (including
global), and it's available to use with both Gemini API providers.To access a server prompt template in a
templateGenerateContentortemplateStreamGenerateContentrequest via REST API, you must use the endpoint specific to your Gemini API provider (Gemini Developer API | Vertex AI Gemini API).
(Vertex AI Gemini API only) Set a specific location for a template
This section is applicable for these situations:
Your app's use case has location-based requirements.
Your app's requests use the Vertex AI Gemini API and you specify a location for accessing a model.
As described earlier on this page, a server prompt template is automatically
provisioned to all
available regions for Firebase AI Logic
(including global) if you do either of the following:
- Create the template using the guided UI in the Firebase console.
- Create the template via REST API and set its location to
global.
This means that you can set the location in your app's request to any of the
available regions for Firebase AI Logic, and the template will be available.
You're not required to set the location in your app's request to global.
However, if you want your template to
only be available in a specific location, then you need to create the
template via REST API and set that specific location explicitly. Do not
set the location as global.
Create the template by calling the
projects.locations.templates.createendpoint. Specify thelocationof the template (for example,europe-west4) as part of creating aPromptTemplate.In your app's request, make sure the location where you access the model matches the location of the template (
europe-west4).
Be aware of the following:
The list of templates in the Firebase console only shows templates that are (at minimum) provisioned in the
globallocation.If you use the REST API to provision a template in a specific location (that's not
global), then the location where you access the model in your app's request must match the location set for the template. If the locations don't match, then the request will fail (due to regional isolation policies).
Provide the template as a file
You can provide the contents of a server prompt template file by calling the
projects.locations.templates.create endpoint.