Yum News Yum News

Technology  ·  Artificial Intelligence  ·  Developer Insights

Breaking
Gemini Task Automation Guide: India UK Japan Apps ✦   How to Set Up ChatGPT Wallet for Agent Purchases ✦   How to Set Up and Use Gemini Live on Apple CarPlay ✦   How to Set Up Gemini Live on Apple CarPlay ✦   How to Use the Gemini Decisions API for Fast Choices ✦   How to Use Gemini Task Automation on Pixel Phones   ✦   Gemini 3.8 Live launches with native audio dialogue  ✦  Android September Drop adds Find Hub memory  ✦  ML Kit now supports Gemini Nano on-device inference
Use Server Prompt Templates with Firebase AI Logic on Android
firebaseandroidtutorialshow-togemini

Use Server Prompt Templates with Firebase AI Logic on Android

Step-by-step guide to creating and calling server prompt templates in Firebase AI Logic for Android apps to update prompts without new releases.

Android developers using Firebase AI Logic can store prompts, model settings, and schemas on the server instead of hard-coding them in the app. Server prompt templates let you change wording, switch models, or adjust parameters from the Firebase console without shipping a new APK.

This protects sensitive prompt text from reverse engineering and speeds up iteration. The client sends only a template ID plus any input variables. The server fills in the rest and returns the response.

Firebase requires App Check enforcement for AI Logic starting 2 November 2026. Complete that setup before you rely on templates in production.

Why Use Server Prompt Templates

Client-side prompts expose your instructions if someone decompiles the APK. Templates keep that logic on Google’s servers. You update the template in the console and the change reaches users on the next request.

Templates also centralize configuration. Change the model from gemini-3.8-flash to gemini-4-argon, raise max output tokens, or add a system instruction without touching app code. Supported models include all Gemini models available through Firebase AI Logic except Live API models.

Android phone and laptop on a desk during development

Prerequisites

Finish the standard Firebase AI Logic getting-started steps for Android. Your project must have AI Logic enabled and your app registered. Add the Firebase AI Logic SDK.

You need the Owner role or the specific IAM permissions for promptTemplates.create, get, update, delete, list, and updateLock. Start with a test project so you can experiment freely.

Create a Template in the Console

Open the Firebase console and go to AI Services > AI Logic > Prompt templates. Click Create new template and choose a starter such as Input + System Instructions.

Set a display name and a unique Template ID. Use a versioned ID like invoice-generator-v1-0-0 so you can introduce breaking changes later without affecting existing clients. Template IDs allow lowercase letters, numbers, and hyphens, up to 63 characters. The ID cannot be changed after creation.

In the Configuration (frontmatter) section enter at least the model:

---
model: 'gemini-3.8-flash'
---

You can add generation config, safety settings, or input/output schemas here. In the Prompt section write the instructions. Use Handlebars syntax for variables:

{{role "system"}}
All output must be a clearly structured invoice document.
Use a tabular or clearly delineated list format for line items.

{{role "user"}}
Create an example customer invoice for a customer named {{customerName}}.

Save the template. The console offers a test panel. Supply sample input JSON such as {“customerName”: “Jane”} and run a real request to verify the output before you call it from code.

Call the Template from Android

Initialize Firebase as usual and obtain a TemplateGenerativeModel. The call looks similar to a normal generateContent request except you pass the template ID and a map of inputs.

val model = Firebase.ai(backend = GenerativeBackend.googleAI())
    .templateGenerativeModel()

val response = model.generateContent(
    "invoice-generator-v1-0-0",
    mapOf("customerName" to "Jane")
)

val text = response.text

The SDK injects the variables into the stored template and returns the model response. After you create or edit a template, wait a couple of minutes for the change to propagate before testing from the device.

Close-up of code on a laptop screen

Tips for Production

  • Version your Template IDs. When you need a breaking change, publish a new ID and update the client only when ready.
  • Keep templates focused. Complex control flow (loops, conditionals) is supported, but start simple so debugging stays easy.
  • Combine with App Check and spend caps. Templates do not replace security controls.
  • Test both the Gemini Developer API and Agent Platform Gemini API backends if your project enables both. The console test panel lets you choose.
  • Monitor token usage in the Firebase console. Templates can increase or decrease cost depending on how you write the prompt.

For hybrid on-device and cloud routing, see the existing guide on hybrid Firebase AI Logic inference.

Conclusion

Server prompt templates move prompt management out of the APK and into the Firebase console. You protect your instructions, iterate faster, and keep model configuration under central control. Create the template, test it in the console, then call templateGenerativeModel.generateContent with the template ID and input map.

Start with one narrow feature such as invoice generation or product description rewriting. Once the flow is stable, expand the set of templates your app uses.

Sources

Share this story