> [!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 />

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:

- [Set a specific location for a template](https://firebase.google.com/docs/ai-logic/server-prompt-templates/advanced-workflows.md.txt#specify-location-for-template)

- [Provide the template as a file](https://firebase.google.com/docs/ai-logic/server-prompt-templates/advanced-workflows.md.txt#provide-template-as-file)

The advanced workflows described in this page use the
[Firebase AI Logic REST API](https://firebase.google.com/docs/reference/ai-logic/rest.md.txt).

## 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](https://firebase.google.com/docs/reference/ai-logic/rest/v1beta/projects.locations.templates/create.md.txt)
  ***and*** you set its location to `global`, then the server prompt template is
  automatically provisioned in *all* locations (including `global`), 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 Agent Platform Gemini API (formerly Vertex AI). Learn more about
  [setting a specific location for a template](https://firebase.google.com/docs/ai-logic/server-prompt-templates/advanced-workflows.md.txt#specify-location-for-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 `templateGenerateContent` or
  `templateStreamGenerateContent` request via REST API, you must use the
  endpoint specific to your Gemini API provider
  ([Gemini Developer API](https://firebase.google.com/docs/reference/ai-logic/rest/v1beta/projects.templates.md.txt) \|
  [Agent Platform Gemini API (formerly Vertex AI)](https://firebase.google.com/docs/reference/ai-logic/rest/v1beta/projects.locations.templates.md.txt)).

## *(Agent Platform Gemini API (formerly Vertex AI) 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 Agent Platform Gemini API (formerly Vertex AI) and you specify a
  [location for accessing a model](https://firebase.google.com/docs/ai-logic/locations.md.txt?api=vertex).

As described earlier on this page, a server prompt template is automatically
provisioned to *all*
[supported regions for Firebase AI Logic](https://firebase.google.com/docs/ai-logic/locations.md.txt?api=vertex#available-locations)
(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`.

1. Create the template by calling the
   [`projects.locations.templates.create` endpoint](https://firebase.google.com/docs/reference/ai-logic/rest/v1beta/projects.locations.templates/create.md.txt).
   Specify the `location` of the template (for example, `europe-west4`)
   as part of creating a
   [`PromptTemplate`](https://firebase.google.com/docs/reference/ai-logic/rest/v1beta/projects.locations.templates.md.txt).

2. In your app's request, make sure the
   [location where you access the model](https://firebase.google.com/docs/ai-logic/locations.md.txt?api=vertex)
   matches the location of the template (`eu`).

Be aware of the following:

- The list of templates in the Firebase console only shows templates that are
  (at minimum) provisioned in the `global` location.

- 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](https://firebase.google.com/docs/reference/ai-logic/rest/v1beta/projects.locations.templates/create.md.txt).