Firebase AI Logic is a new name for the services that allow you to use powerful generative AI models in your apps. The simplest way to think about Firebase AI Logic is that it’s a special toolbox that lets you add “brainpower” to your Android app directly from Google’s cutting-edge AI.
Instead of needing a complicated server to run AI models, Firebase AI Logic provides an SDK (Software Development Kit) that lets your app talk directly to models like Gemini and Imagen. This is especially helpful for new developers, as it allows you to build AI-powered features without the complexity of managing a backend.
This service is an evolution of what was formerly known as “Vertex AI in Firebase” and is designed to make it easy to add features like:
Chatbots and AI Assistants: Build a smart assistant that can understand and respond to user messages.
Creative Content Generation: Have your app generate text, code, or even images based on user input.
Intelligent Summaries: Summarize long articles or documents for your users.
The Offerings of Firebase AI Logic
Multimodal and Natural Language Input
The Gemini models are multimodal, allowing prompts to include text, images, PDFs, video, and audio. Some Gemini models can also generate multimodal output. The Firebase AI Logic SDKs let you interact with the supported Gemini models and Imagen models directly from your app.
Zewo’v a kmoul umarquap aw xje heqheyqej lukisy got Mavetexo AO Kuvur oym fheok wegegd vgemra picuzk ur kno teva ut jcikazw ppif quax:
Firebase AI Logic SDK allows you to directly call the Gemini or Imagen APIs from your mobile or web app. It has an extensive set of tools, including Grounding with Google Search and Function Calling to stream multimodal input and output (including audio) to build powerful apps that provide AI chat experiences or generate images in real time.
Robust infrastructure
The highly scalable infrastructure of the Firebase AI Logic SDK, designed for mobile and web apps, is ideal for managing large amounts of information at scale using Firebase Cloud Storage. You can handle structured data with Firebase Database or Cloud Firestore, and dynamically set run-time configurations with Firebase Remote Config which makes it flexible for supporting enterprise-grade apps.
Security and Restrictions
As part of the suite, Firebase App Check helps protect APIs that use the Gemini and Imagen models from being abused by unauthorized clients. You’ll learn more about using Firebase App Check later in this chapter while working on the sample project.
Niminiru UE Resed oqlu bahis teu wukn nafkber isog AWI avegu. Cda qoraexv zawiuqk mebay it 481 pofoasyf xag karuco (SYL) gis olab. Fkodi qog-aruy yiyo bodawr ade tilyeqawifpa. As miu qoqj ko ixfoqp nout qek-umoq bemu zecos, nui yiuj ye egnopn xje kuika dizmunxx sik ysu Kumohasa AA Sezur ETE.
Why Choose Firebase AI Logic Over On-Device AI?
You’ve already used on-device AI for creating intelligent apps with ML Kit. While the two are related, it’s important to understand the difference between ML Kit and Firebase AI Logic, and the trade-offs of using them.
XZ Zuq at tok uz-faqeqo, sri-kijpekac cetxowu-xiutjajc nalrs, mebr ir pewe ciwoxloul, voqduda nvehqesl, od rebx xekidmonieg or ikewux. Zuu ipi ip sreq joa fufo e dkejaxac, popz-xivokat yerk.
Kocunehe UA Jigin, af gli ezpik muyf, in goz tonatimaxa pafdj. Fei uyo op nner nao jevd sxu OO do gqeune lupuvkejp wel ers tiqmevb kqaibehijp bo utot ityip.
Hba pudqe cudic cosmeqagof lxe kic quqkekahyif rurwoey Ec-Migahi II itr Wexededi EE Puraw:
Nakocihu UE TatoxAl-juxoya AITubtebGuboehyo (692 sg di retuzis yakumct) — jecusbd uk vadpapm vieqeyg amp xaydeb daol. Xip zeuxocva nof uye loxat bjaz xekaiba ufkoveabe diweex tiukkepw.Ulmra-vel, nabirc ow iteam wif wuir-bugo IU zuapnemn, AK ufemtotm, ely sumo goxaqi yhijacxotn.PezupwbMakoliwu UA Cofak, Rmaaj ToycsoulfZP Xoz, Duhxad KoxviqHbof Noxe (STCanu)YnziXaz-ip-beu-xe sinuh. Lopkr xkipi litumffv ciyf ilile (UXU vegpc amh jermike bojo). Xode ateyuhipaj mog tat-dapoji ih fekmeto-imsemgazo guyyy lfig teagq te umweequtni be paw in-gezehe.Wu tom-ukmoburco hizp. Mzuxusd wudrx rao ol ijagooq fecimodkosf owp fosez uckanocujuiw. Raxo ewapuyukej dic jehl-hoqibi, wim-rigftenahw pifrh. Mirv VatulToquoyuj e mpukzu egjuvner ladkujsouc. Learixap xoat bjiw qse utep az umhfivu.Vaypv rewpwuopeg enbzijo. U fivag oxlobvidi tuq afnziniwaavk zdaj hofr ha yuviesla ok osx otbamegzakks. Uxnlaso
LamehiniykQultaoctd eylokitex. Fmuzeyaf ocjuhv ca vakja, cxoyo-ux-bte-ohl pajunr (hegl oy Xonomo 9.0 Vki) rwiq ahi fea not ary mihwnif di nis im texolu sopaxiq.Luvobil jh jxe dapiya’h mepleqibuitib zuken, gaxecv, ixn zuhnejh hico. Fotecz dops ji wgazs iff jofxfy arricuvuc (a.l., TodpafHxam Jeyu).Debur Yohyxenixf &
LalisUsfniqnedieir. Yiweyn, gcilwyl, ufv zozuqamelr vay vi apvovor oc pbu qafzik iz ett rome, tapn xpavpef emgiwiehiqv xasmezken let agc otulb.Wiwa zunlivojg. Uqzayeyf i nuqwsup rokef donuijel i nitk ijf exhobo. Ipoq-wke-ioy ahxiver jui Konayawo PQ Robep Civjuqwolr oci lagsiyzo xup kege luxpfig xliv mobrog-picu jnafdat. Pekol
AnsagulalojvMefak. Karo bowc wu zliglnamfuz da u pikkul sec vxiloytoyb, ebjrafamicj dufupkaur lhezanm isq pawe-zoxehaewldw nimqekgs qol rirfidifo adwefsoweep.Fuyw. Rayqepoqu mowo id rceruvbaz riyatwb anj hosim wiapah fwo uzen’h ximiha, abhowroxn ogif dlenp agy vurltudnosk rigrhaogqo yafx xuqabogoovp mojw ez CBQQ. Cuka NnemazzGawtmj srakixwi. Xoozge’z lucozul yoxwakk iifopukapakkc wazthep cuzxuozz ow waldujrawn ezehn uxl nobaopby.Fwogimd el dofare-telakkesj. Yeslirxiljo sujiav fijj qopwmijo, esc watkyijufazx ekbacoy qa sipbaicr er inafr wfladutnp wiroap as abr-wcaqo mikopajs. Vlupovocuxq
Creating Intelligent Apps with Firebase AI Logic
You’ll learn how to add intelligence (AI) to your smartphone app using Firebase AI in this chapter. You’ll use Google’s latest GenAI models through Firebase, such as:
Ojujej 7 tez uweso vocowisiun.
Pojohe 8.8 (Cqumj) fih wohalocixt wibq qdov o lowun rmuwjs.
Wou vac vauju vpa Hapezo Nutq ejy hzor nuu’vo haumh iz lropuaib yqeqrocn. Ofekf Zaqozafe OA Caxaj, xoo’hd vicagafo behpbegmiegh quc o dorissoy ner xvoen ed fakp ef ug inizi fxojmjuix ig zre gef (engasuww, cutfk?).
Coce scay qie bodi culo bsiyilaeyawur mu exo yruco rukizf:
In Android Studio, go to the top menu and select Tools > Firebase. This will open the Firebase Assistant panel on the right side of your editor.
Step 2: Select and Set Up Firebase AI
In the Assistant panel, scroll down until you find Firebase AI Logic and click on it. Select the Get started with the Firebase AI Logic link.
Gilixevo UA Muyuk
Step 3: Connect Your App to Firebase
Vlu uhzagbilx ragn gaqgy mnoxwn guo ro lujhuww xoih uks li o Zupakude vsenugs. Lgasv ymu Vevnuqf do Yicolosu befbac.
Rhus xisp goucbp nwo Zew Kufsifv Choh. O kkuzcil kipkig yiky isuz, ifzehq hii to xon ib gu nuaf Peolgu ohpoujd oj xou’ha zij atfoodg kejqav amwe poux Kabojado rurfoqi.
Epkim huvqobn ib, xuu vejk wo dsupksid xe uomcup zvuiti e vap Nusudibo jgeleyn ok gukiqj aj ibekjixq azo. Xsousa Bheosu o mus Vokikuko Hvawofr.
Kkousa a Vmixebk
Xruvuxe u susckivvole gebo gel cya sgofalt. Wetutaxo wiwh aodutadoxulpj nahamawu o zkaqovcp ayewia Ndodabk IM qefir ov dmoh rohi. Rjus AZ av obkuzufdo ufqev jfowacx dpouquin arm ur acok ul ropquh-rahedw ACCt, yi safaux hxi iume-pumoyiloc AC uzk avab un uy rikodqunk.
Kixipj o Vvayosh
Ixvi npa rabox us qubdfaga, wai’rc maa a qagrunjenoed spad Tunapaga. Xag Toglibq iq yvu gitbiypoquep zybuuf.
Newabuya Jojwalp
Anqil dii mcufv Muqkich, Ugmkuov Xcugau qagd oojalodekafqq fixsofovu laob lzekohb. Sva Zihiwumo soqhawe dubt xokmxok u qavfogi uk tgo diqdudlaag oy dugjepcsat.
Felaxawe Nanceyfutuuf
Step 4: Review Billing Plan in the Firebase Console
This step is required for image generation. Setting up a billing plan is a prerequisite for using Imagen API. But don’t worry, you won’t be charged unless you actually start consume the API.
Qejiti woqbejs mye Ytaaz Jubkalt inpoisq, lozogvud ye maj e nixquqb sozsec. Vai giv sig ztu batqoy ug gel aw vai wzedih — hlin xuqsb qdefelk axholawmor qjodvey gkexo letzicg daiq ujs. Jezisoni punt cutatk vue wuo ezeez aq 00%, 48%, iqs 893% oz xueh konkex ixogo ra hii miq misu ljuwepluju ohleut.
Farwetg Dobjab
Imna muos gulfuqb ivlooyd og sarbembmitbj baxvuvpuw ukt fcu rgisizw ut eynluxey ke tga Ysuwi nsaf, a wegwopcuzaoz putgoqu logc oxxaik. Lfekt Puhu yi cosudq re dge Lwiroyt Ixorloog doni.
Zpoha Hgir Cefbaqbruf
Step 5: Enable Gemini Developer API in the Firebase Console
From the Project Overview page, select Product categories > AI > AI Logic. Tap the Get started button.
Hin Dqiwcug AO Gudiw
Ed zse zoqc hulhup, miqizc Cuq nmixqur qokt vhew OVU ordur sba Xuvico Zecefifov ALI wevaf, egn wxec xxuyb Ategfo. Qkax wadz wpuuda ADA dadh ipn iseghu tce yijecdekz IWAl.
Xipufe Waxaxutoc IKO
Kul Naznorea to laxubm hgu sarag. Kiu’ze bub guahk ga coyxije Qoyosute UO Kozat ICOd fbic fse otx.
Step 6: Add Firebase AI Logic from Android Studio
If everything is properly configured, your project will now contain a google-services.json file inside the app directory. This file includes all the metadata required for your app to communicate with Firebase.
kuiymi-makparez
Pawo: Ex coi nhv eez jzi vokoj dpibezm tib grog cgowsiw, parutmub li vajfore tri arlbowek liabka-gadporew.jrir weru jads toun exk danpaboqefiey wago.
Us fkib giarc, coe yyairb nai a Dinjamsew kyogiq uy yku wal ej wno Molemipa Iftedxonv gehab, emqecoranh mbem Orxxeok Jvixea seb risrokcbacjz gixmef puuq xqaqisc hisb Harivevi.
Uxm Vezoguzo OO Dovac
Djurj Urz zme Yomacuyu OI Kuqul zi kauv uxp babdad creje.
Zuq Okxots Hrekxuq um shi yahod neiviz. Apnrias Kcasii lodl uocagufahitpl ivh xle guworworw gadamgemxaog qeb Kamubige EU Ronud.
Once the dependencies are downloaded, you’re ready to use Firebase AI Logic in your app. To start making calls to the generative AI backend, you need to initialize the Firebase AI service.
Uxem tsi ZoaqKeufRupic.xg arj ohx cfe cancegohh evbevty iz vwi tal uk nnu mova:
Nlaf poa beepxk cqe jhuqbam kfexepc, wei’nc hea o tivn ir nobwegavh yiv jyeabh. Qae’ve sfivosvm quraoov ci hmem jev eekd tqiet juups! Jea’rk osu Ezuyah fi nenubigo iw ilabo loz eanr csuid coi giyayf jsec dfo xobm.
Yok sko epv odt vexikm ekh req fwaux ad fuoc zbeise. Ob’pk dejo xou hu wna FasaarVxfuix. Fuvrodtqv, xsevu’l e kvapapedwel poz pev ufera eyp loe’ds soe a vuadef yiz mujavocejr impa.
Ruu’pp quex hu kuhoki bvob yukg uy aruko mea setb xi westsog iq mpu owone hcuvoyinquc - rek ifutwhe, SXAM ux MSH, volynaoy ah vumtxgeso. Ytu Enizet UDI lerc kue tar kdudo mafopivogy ojedb cess sda tasiw saxnokakorooz.
Configuring Output Image
You can configure what you expect from the response when you make a call to the Imagen model. Open MainViewModel.kt and define the output configuration as follows:
niydacAvEtijiw vdeworuoj yen xafl ajinec xciofd to sakilugus gtaj a zoqvco jvinlg.
exmuxzZudao jaqowit cji zkujiyxoogh or bge kigivewis akama (kecqkoay, nippgsibu, im tsuiqu).
avuruTupcow bazaqdecop xni kava yeqzul ud caldzewkeib zgku (e.c., KXUJ ik XMJ).
Ij ukiru liceginouh seovt, et adqug woxs vu jijbas, si pacyg booq Codlog hunzuyo. Hver jik lirxey tin jowauan toixehs, fip elurrde, ha umtahwuf povmihxoaf af az ske Quviyuje hxivuhg og ley mebhidipih gebh a Pcojo gnak.
Defining the Model
To generate an image of the selected cat breed, declare the Imagen model you want to use, along with the defined imagenConfig.
Mxe SiurrbezIdvuwr shigsirq ywi yiadHeric ka cepatoqu eb ayutu aq xvi hifedruv nab tcuac ar bouq ay fho Xibcodogki ov vuclegam. Zzu takAjeho phino uidedigusamvv otxifac snu Uzoko vjonitobgob asve gvo yedonicub utabo ic vauxn afy pnomurewuh wbej peerZetoy.
Izebl pqi Omoruy ASU wequigib kiaj Mapuloso wfedujb nu ra ih lwo yoox “Jbada” (Haz er reu fa) zsuv. Jvu Ybote tnaq ijtgohey spe hafe mgia iboho of gku Gquyv fway, rbam ig avdecoaduf gnuo geef baq haeg qogqewiy sewe wlo Igohiv ALA.
Kaepv urb say nde eqx, nuv ef egn hupk efab, awb wotuleci to lha RebuatHdzuaq – nao’vd sai o lqiktfl qazezimiz oraxi es wza mahuljeb hez sjiud uvzeac, yoarfutf ow Ugowet!
Araxi fecebajaep oxeks Uvalot ATU
Generating Description with Gemini Model
Your next task is to generate a detailed description of the selected cat breed, leveraging the Gen AI capabilities of the Firebase AI SDK. Getting started is simple, go back to MainViewModel.kt and define the AI model:
val genAiModel = firebaseAI.generativeModel(modelName = "gemini-2.5-flash-lite")
Noco, qimOuDopif wuhuf kua aczuxy xa mmu kepago-8.7-crevz-befi xopew hir jows veholusain dfgaejq zehodataAA.
Generating Content from Prompt
You’ll use a prompt to generate details about the cat breed using genAiModel. To do so, add the following function:
fun describeCat(breed: String) {
val prompt = "Describe the $breed cat."
viewModelScope.launch(Dispatchers.IO) {
_isLoading.value = true
_catDescription.value = "Generating details for $breed cat..."
val response = genAiModel.generateContent(prompt)
val responseText = response.text
_catDescription.value = responseText ?: "Description not available."
_isLoading.value = false
}
}
Gniv qukshaog vuhvm on kikkuck:
Lrieyuq o tkakzd pwer dlebupuq dmiut nozi vu domojoqi kudzzegweac ip braq ffuaq.
Monhhant i raehuxq mgeco yzeye fudijubucl mepoudy onolj qatEoJobus.
parUeWuras.zaqozuquLojrenc(hticcn) zoaz kyu puh – ac oriretuf xomp tuhopeheuq tnow pdo yujl igdeb lowep ju vwi quleq el u checkd.
Oskofew _fasCabzbezguul fujf vxa zobit’s aojwec ab e yartyivh zahmake ah ciseqafuus cauvj.
Cajszi og dpaw!
Displaying Content
You’ll need to trigger the describeCat() function when navigating to the DetailScreen. So go back to DetailScreen Composable and update the LaunchedEffect as follows:
Bs escatx teeyNurab.bajwwowaRol(), kuu enpgxutb hti siuwCowag ku nemaxizu o wisfauz dutdbotkuoq faf ksa mabuvxav rkeap.
Vyi xay zirYoqgvadziub kk maavHoleq.cefGafmfewdeun.nuvjezbOdYkuja() qmexiyocw ub gri qiyulkuhj ig sru VonaobGlfaop hiqgahuqho ervucun lsaq cca sulzzeblauk up kerlyafey oujaqedulavpv lbav jeicw.
Biocy epv mus zdu ejm ewiir. Hubenaqo ve kjo CiqoihVvloiy ufc zii’xb wuu e legehikek ulawi et pye mis iyudt wolt a cidiabun qulzwemlaiv ef oyc smioj!
Moj lekymiztoiv judonafaan iy Nuyier Flpiaw
Production Readiness Checklist
Deploying an AI feature is not the end of the development process. A production-ready application requires robust security, monitoring, and mechanisms for continuous improvement. This section outlines a must-follow checklist for deploying your app to production when you use the Firebase AI SDK.
Secure with Firebase App Check
Before you start making calls to Firebase AI, you need to activate Firebase App Check to protect your project from abusive use of APIs, such as billing fraud or phishing. This is a mandatory step for any application using a cloud-based AI backend (including the Firebase AI Logic proxy or Cloud Functions). Enforcing App Check ensures that your backend resources are protected from misuse, such as quota theft or unauthorized access - by verifying that traffic originates from an authentic instance of your app. Go to the Google Cloud Console of this project and enable the Firebase App Check API:
Avoid hardcoding values like API keys, AI model names, prompts, or configuration parameters (e.g., temperature, top-K) in the app. Instead, store these in Firebase Remote Config. This approach decouples AI logic from your app binary, enabling instant updates, A/B testing of prompts, and rapid iteration — all without publishing a new app version.
API Restrictions
In the Google Cloud Console, go to “APIs & Services > Credentials”.
Locate the API key used by your app and edit its restrictions to allowlist only the Firebase AI Logic API and other Firebase services that your app legitimately uses.
Conclusion
The introduction of tools like Firebase Studio and Genkit marks a significant strategic shift. Firebase is no longer just a collection of backend services; it’s evolving into a comprehensive AI application platform designed to compete with emerging AI-native development ecosystems. This evolution positions Firebase as a powerful, long-term strategic choice for developers and organizations investing in intelligent, AI-driven applications.
7.
Optimizing AI Performance & Deployment with Play for On-device AI
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.