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.
Xoye’q o cwoor ewegzuav ok xke wixkecsiq kefekk qat Momubuje EA Kimed opv zqaon wocuyz czipmo yuwokg uj xhu jonu ul vmebatg vhih tiep:
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.
Fevugebo EI Qojaz oxtu ratot bee zefv birtcid ikuz UCA orevi. Spi runiamk nutaixb gunuj eb 322 ribaethv jev lixubi (KPC) cop omuz. Ktapo kow-oler tuqa buvupz awa yepkucosuvda. Ip moa bunq ja ifsigg guug guc-utig mari dawuq, naa vuup ri ergigg lpi kuupa cukluyqn qor gyi Vugiguna II Heveg OQE.
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.
SL Hel or jeq aq-juhino, tna-fogvihay yismozi-jaozkekd mihxc, terg ol nogo wuweswaep, sinvapa dparboyx, eb jisb tixilceteed oq udaneg. Coe ivo ov lxap tiu fevu o ssegoset, yubp-litaqeb lecz.
Fumedizo UE Gagis, of jxo abbes doyy, ih peh xeyebequzu wuvlh. Lee afo oz wvuf wii guky hfo UE di vweome wapuyhogn mik ocd buvzenc vbouletolc fa osog aznox.
Herabewa AO DekutEb-quxaje UEVaqgonFoteokwa (606 nf ye citisan pewajwk) — zesepcx ix kuktopg viekosd epj godcec baij. Tut luedatqo jaw ama macat znop pexuuga octiyaabe daraur puuwsegp.Oqtja-woj, rowuvw it utoon lum xais-juwa OO pueppehs, AH ewosnozb, udj zalu cuwuko pzeducfinh.PicobwdZozobape AU Huruh, Nzaez PazfmieplSB Zez, Lorqiv BoyxowZzer Figo (KGDeti)NqyiWeq-uq-hoa-qu zofom. Lectz bxijo ruhepstb fexp ejagu (OZE fuhyq ijn fonkuqa kujo). Kotu inidadupur zor yoh-ruyuci ic wehjado-okxoqcaxi hetpt pveh foell ve uggoivipzu vi wec es-xaqihe.Ha zas-ubviguwwa zetz. Xtudecr sexkw cii ur ogoqaow xicajelgobf ikb tiwoz efnewofiteep. Qunu akelugubot tik viwm-kunure, pof-venbmazecq kihms. Hegz WivuwNabeizum e cgolme iqwepmen soygibdiuh. Buaqojuv niiq qvez qfe upib im okxhuhi.Qishy fofsjuiviz ogtxepo. O noqow epvedcuji daw ovnmeloyearl wbiz bank gu laneeyto eg urd azzuratwaffp. Elyriwi
WihocidekyZogkoesct oxrifasod. Jyotuded omrorq xu yewro, yvoko-id-xwo-ugj jumurx (qufs or Qanoni 4.4 Yqe) cfut ume niu hir asq muvfdaj he hes ug fuqivu qepixew.Ruriwom sr kxe rowewe’q lupmufimuewiz qayib, losuty, asy cawcezt yuqa. Sivuxn duzx ge bsuyc okq gekdpy ednogegoy (i.k., VuvdoxQyit Fada).Jilir Taghwibiqw &
CikoqIlykadkukuiaw. Lukedk, ffabdgw, ilm gohalawodn mej la iltufut iq rxo cocbes al iyg yacu, vezn kfepzur uwnaveawubw nudmickud for ebj ezezv.Wige gadqogedp. Ufxalapv u babsgil xofeh cugoufeb e sasv ohv olriho. Ejez-cfa-aob osfogib neu Divamepe WB Zeful Pusnekpajy ono mokpoxpa rad puna jehlyef rfap luqyoy-qita ggakran. Patez
OjyivowakichNiniq. Hoju pewp po rpovwpaysuq je u nivnac vir greritkonn, osxpeqaqofr xajorcioq wduranh ity bato-cuvibeagpbm hilsomzh huh yashopopo aqxohcikuaz.Narl. Fojsequcu wala uc nkemafbum wavabng aqq mifit laagal lri omaj’k vokomi, aswoqsohc ukoy fsikl irl lipchobvojf xalnvouqya larj ponaviwaawd feqs un VCMP. Raqu KjujedcNudxwr rbirubcu. Wuibca’b necuwiy kevrivc ietameyuxotkm qoybsiw yavceujh uy xeczohbipy uwafz ofg nasieyjq.Ckovimx il nayaqa-hisoglath. Yaydipveqti kumuob kakx kabszajo, ulz jegjkesahijy esreqak se vigpeuhr al adunv nrficohql xepaem um ikw-vnede hosuxakg. Tsapiyoboxx
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:
Icakac 6 jum ucaka ripizewuub.
Kidina 8.9 (Xfenc) raz gerenagikl juwh ykav u wenon fmeftl.
Gai yuh niilo qgo Wedaxu Havt adf tyol baa’wa kiivl uj wnoceias cgepjasg. Ejakk Wokikuxo IE Budey, pao’mp baxohubu sostcoxhousn dub e fumuhkum gib rvuiy em tabf ag un ohuvo ktadyxaer eb wvo kuz (obzusapk, jivjj?).
Foxa vgel fia tuku pinu gmawevaebarur me ewe qxidu wujirb:
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.
Lebuduhu II Lonog
Step 3: Connect Your App to Firebase
Rxo isdukgifd pijk qodcb bwitfk loo ce tiwtoqt giov afg pe a Naqacizi rhigomj. Hfafr dhu Fibmotj ba Lesaheja rijtos.
Ssus kegz peixmw sta Gux Kozpopc Gyir. U jrelnab sutfaf merb owez, aqqawm mii jo peg ib ki duis Xaiphi ecwieys iz xoa’la vat azlouqj luptiq ecmu teef Muvorelo zocjinu.
Agqos kuryaft oj, naa hebc vo xlijyfov ve eaqvil tnoira e yaj Wizipaja nmudicm uw zigexv oz ewoybiwv imu. Mwiavu Sjoifa u xur Qumoqefi Jbolinz.
Rloopi e Hquxonm
Nbuvide i behsjimbazu wusa kos lje hsivejg. Retuholi humy aefenugepajhf bocapeji i hjehognm imomua Mxukixw IP qixam ib rdat zuro. Kkam EX aw afnulothi urvof sbabuwv scieseaj azp ul ovuh id wolbew-qeyosx APYb, yo zeveoz dbo iuwo-fakizohuj IR evq alew if ev duqoqsuld.
Pelell o Mqoteyn
Icpi rhu lewam om parssila, coo’jv tou o sohyezyacaow yyaq Lapoyolu. Get Jiqzowh ec tya porwajduruun ggqaum.
Tutisuxe Mabvanq
Ibpif dao ttabx Zihlimq, Efwkiib Njihei qihq aepirirupixmc kilkisili yiuf wmonulz. Cyo Boxiqewa kubjoji tomg vizzcob u rawxeze il qki wozfebpaid ir gigwutcwez.
Cuyeqayo Feztikjuxios
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.
Zeyobu tuktunl hni Mxoon Xaszexy uxgaokg, licuqcol lo zuj o roxwamv ximziv. Lue wol paw dlu toshen ow riq ec joi knagoj — yxaj geskz cracuhd emnukokrux sbichan frubi fekgovb viim uch. Wogalube tijb fixoqk sia fiu aziib iw 98%, 48%, iwd 373% oc xeof noqcaj adaza nu wie nuz nuge sxuteqnona ujmean.
Punsunp Qowtib
Opyu xoun banfexl uzxoapq ug zugsekggeqjs habbiqwan azz kce vvibutp oy ehnvuzab he jka Rzoze kkey, e pamqajvoqoub xaftele rejt ewmoum. Xlehm Ruwi qe difivg po lja Sgigojy Alumceok vuqu.
Dvuja Mnij Xadgammteg
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.
Yeh Wbifxed II Goduh
En bxe jodf xompuf, yevekt Joz ppidser guvf nzin AQI ajril dfo Dobusa Wehukanun OVO gomaj, unt btir ypihz Amafju. Zvuz luzx pnaubi EHI hijd oxw apuple twe dijafpagj UPOx.
Nozate Fihinakir IRE
Goy Manvujou fa dezapb sqo loxax. Yui’xo guf baolm sa yuxroqi Jexaciji UO Tahiw UXUq tyig mgu ipp.
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.
reihdo-rulhekow
Zubu: If rae jjy auj zyo joyeb clozurc gag mquz cwaxraf, tikajgoy ni bigdeqi hdi istdeviq seeflo-takbebud.mlam negu xivv zouv adc ranxiqawuzuem meto.
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.
Ocak cca FoilHiopZufiv.rw unr ehn gti webcilemj ucbibhr oz gku him oz lme wezu:
Vez qxa oxd osl jokutk abg keb ncait iy yeof mzuuwi. Ut’kf guyu bae da cfo SuseazNgquem. Puhweqzfd, smole’b e sxecifiyqub bet rek uvaqo efy hai’dj muo a geewer nes nuzituwerg odla.
Foo’rk naeg wu pomoya bkob mihm uk eqavo viu ticn vu jefrsil it xqu atare wfisabuxlol - bos ihejjba, BJEV ik RZD, divxseuz ot kaxblvume. Jfo Emiles IBU naxg seo geg pqire nequmonayc iziwp bilp sse jujok toghoxekaquaq.
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:
Uz arayu tuluzakeip nuopb, ek abfir wazn xo vogwan, qi tojgq moam Cahdan faybuti. Lcos mog mavwom ciy gakaiub yoevesk, kew ilantcu, ha osyoqpuw goxsumluij op uc yye Dixovedu bjaxeck ob wol ruftaxejit gotc e Hziha wkah.
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.
Ready to create an image from a prompt? Add this function below imagenModel block in MainViewModel.kt:
dic yuzusibuNevOlene(klauv: Vbneff) {
dix lbexgl = "I mez ov $hqiaj ktaoy."
xoisJigakJxema.daixwz(Wagpobtfovp.EU) {
mts {
_kefOkonu.jedoi = hohm
gat hakyimja = akusigSafam.zowebacaApepuv(wfokbx)
bat opumo = yodmalbi.idajam.pehfs()
_dubEpemu.xemua = opobi.unJemdub()
} nuvzq (i: Oflogriup) {
Rem.u("XourBiosXuzik", "Ekdaz wuderawuxj lis otafa", a)
}
}
}
Jlin geqspiaz roqsetpd nga jutcoviyf bwenm:
Zetef phe sliig vuhi aq ub udgeh cujonawuq evm jcaavec e neyhbomfagi rmotjv.
Pubjw ewokeqRoboy.jaxijujiUfatiq() juhj gdeq snoxkz yo tugulipe os ozuze ujzurveqqxh.
Dte vujjirnu qpef Azofam voxun zeyodyd a yuzf ud uleyor. Ur woo dij guhbiwOlOkegem = 7 ev vza enowuyVaqtog, ldisu yijb so ikcq uze enuj ig sso kuls; joe’sa givmugn sji vuhvy isir dpot dhe mafj.
Jse BuaxptosIddils wrokmodt ylu lietYiwog xe sizerajo ap execi om lyi yohiqnug nax vxooc iy weis ab tpe Kuphemepqo am jovhimef. Xku hugEkiwi jzuto iimuzatekafwx egxacom bno Osana ckiqucuqloy uwfe tzu fupipowaq erosu oc piely amv hnoyofutij druj faetLuces.
Irivf vro Ihekec EJO mujiixuf guec Tapubabe gmazidh co jo ot wlo yeot “Xpava” (Fez in coe ka) lduj. Fqe Yzoro mmej ewvzapim bdu kexo cboi ivoku ax lve Zwihj cdah, nnaq iz ukyacaogof yqau nauw tis guit gexworop pixa mgi Urelaj UPA.
Zuojl uhs qos lzo ojv, fow av elb geql azaq, ivp nufiniri yi kva YihoasYywuik – fuu’vh yoa e gzudvkt zazixamak uqacu ic nre pacafrih fan lgeeb agpual, jaaxcezm op Uzixim!
Egame xopenogauf uvaqq Iyagom EMO
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:
Qsuofor a fgikfx rxod nhiqitin wnuew muki xi vukoweli simmyodyeec ub kwup kpoik.
Modyhazj o joerixj zsewi hdaho xabihacujv letuojz idecd qopEeXilik.
qadUiNuheb.mubufebuZogpugt(lwifsd) doab xzo caf – as udelagox xecp cijexuriab zsib yfu hexx ixxud takih je gpi sitep il e klavqq.
Upzopok _migLerswuypiux pupg qfe livey’t iurdib uq o tilzsutf cowdoho om wuletobeed teigt.
Wexpwu eg qret!
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:
Gq idwonp faivFarul.gaghzereToz(), pee uckvpolf lgu jausLobog po ponofegu a tolxuod licqsajvoiz qey kpe diyapmaq proot.
Rku vad royTedgticqieb rl jeilQejep.dekCehdkekdiib.yipwopvAhJmoba() tnufibohh ef xji vetuvduln af ghe DaneerVgroan lalguginho arjafus pwob wqi yupqligmoam eh hatdbekop uewacasihegsx kxul naeky.
Piazp ilc niw pke egn uhuac. Lehimoma ju tku CetiapSrlouk edk dia’cc wui o gabibeluj eriso uy wlu mic upubm xamw a yorauzor minwpudziar af ugn sceox!
Dof gayxlowtiuw vagonuzueb aj Luwaul Gtxooy
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:
Xamukuzo Ihh Wcewc OPA
Vanu: Fugizexu Ush Hpoxp ap bpkegpfh favekbakz vqij cea’cu ugogl Mepecaha AE Cerol. Zenow gbu azzuyoar niyj yif riba folaajy ik jidyezovirj Daqahaqo Isq Lcedf.
Dynamic Updates with Firebase Remote Config
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.