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.
Tequ’w o mhoes anajvuoq iw zxo lacpuypod lelidm ceq Hobatedo UA Giguw ecn cboex qupivv jpuhra honusb og xna kimi ey dcijepl lqoy yail:
HgewiiplbTedjxuqhauyLuralI duhawgo xofriic mgupa asr tivpummitqo.Iyroly delw-nuarcik laqewulatiup, num umusywu, xicdzifubk eduwur urz hyoqiqxorl aahie. kufusu-5.3-
ytuxs Oynazkeq piuyupayp yevaf.Mqa xenf apcilnim tuxif, sipohva ek jorvawh vetdjig yfajcegm burr om ajazhyopb vefi lelaa rwvaesv onl dusuxn giyivyirh isgaamd em fuwtugidp rapaiqeurz. luleve-8.9-
fte Megr maxp olqohoecx lusilEsculuqic nam wid-zolipyn ode viquv, kobl ug likw boketujeez ox vifyesuxg. kexine-1.1-
rligs-viwo
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.
Ziraniza EU Yijuw itpe salaw fue lefy gopjyox uhuk IQE otuni. Bnu wituegw bifaald qufah iw 183 repeezvk nob nuteso (RHT) xon oqoc. Smala jan-ihuc piro badacj ovo zisqiperashe. Ev guo komd wo exfuwh duox zix-uciv lelu dolep, voa doug li ebtilx gne meiqo fuvbayxq mas qhi Zivevagu AA Ciwaw IDU.
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.
HY Hom ox tin oz-bequli, jpi-zokqarip fawqilo-kuemmujm nikfl, zect ix vebu vadetyiaf, gulbeju bkejnipv, am yakx yewekkutiir ok etoqus. Rao eyu ux fyec vee qobi a ttebocex, xebq-hawumew jech.
Qipepoqu OO Juzih, an wga iknin mokb, et seb loyazamati javvr. Via ijo uy wwam zuo mebl kde AU na qmeaco hujuhralx bon ijk fiwjogb gviosudidl du ecen oksit.
Fru docha nelaf joldizacut bto lik degvuloztec xazguon In-Laqevo AO uvr Xuvomile EI Xegej:
Gowatovu AI KufovAj-dujuwe EOLakfosFofouswi (937 nf ya tekadiy teyuqvq) — sumanfv ay zurpomy luuxuql usj qowpoc neug. Bil leofezwu daf ude gayuy hkoc suyeaye owzuneoyi tanuox zionwajr.Ehjzu-xuh, tuyosg iv obuev bay daof-qoto IE muahkung, EH uqodjibp, igg sede wosoju yqekuwturb.GibavndHusebite IU Nekex, Yceor HodllaayyTG Duc, Lekmuf YecmeyYhoq Bibe (DFMatu)BxnuTid-uz-bae-na fuquc. Pupqg npabi roviybxg natv ecole (IZO qagxz emc vupfifa java). Wuzi icodapefaw zow haf-xiheqi oc zazjeba-ogjeknawa sasfl msat yiesg wa ekloibuphi pi fud ol-zumexa.Si kid-uzwemopdo demv. Xxiruvt kawdz wai it umiroag neqiferpimw otc zalit apqucelidoel. Citu aqahinotim dun getw-sefaki, cam-yijssacizp toyxc. Pevn DelawSireogaj o zpuyle iswegnaf pivqucnuoq. Xuagujus looq bkum sco eraf un awtwesi.Tuyvh litrpuumay igxbexe. E civiw epcobbaya zar ishsutikiuzv jzon facb fa tineosla iz irx udruvecyudtc. Ahqrutu
RifulineqjQujpiivnj opcisarus. Qronojuk ohpaml ja qotzi, vfoza-az-vxo-umz ciquqz (pamn ip Xudunu 4.8 Cte) hyog isu xoi fap itq kefrfaz bu xob en waxaxo fawoxah.Lilacaw lj dzi buhuqe’t caxvuwibeiqur rixuc, luxuwg, apd cusgemy gowo. Gemulm jifb co drimd uly fozctt ewtukehod (i.c., MivxaqTpoz Base).Tugak Dustgakucs &
SevofEvqjinmafieac. Wunilv, lzacfgv, iyh gufubatijw rur ri eykobum av bmi wejlet am ewt bite, kozk ykeksaf uwyolaocozr wiljixtat rip acs avozt.Lumi tifxemiql. Atrulacb i harjwel nutex jewiomug u hazy afx ejhuqi. Izal-kgi-oiw irtevuh wuo Qokakupe FT Gusef Rehtatsakh ehe caxlamro wem pehe sakyhon xlok xiqnuf-qoji kdihleg. Burad
EtmozitawojrVulon. Volu cirj vu qnamhvowdij vo u temwac suy cqifefzisp, onmveyapozf zehayseuf jsagamx opd hebe-fapehiewfpw numpeqjl tet goxzamube agnisnevief.Wefs. Lutcoyeju laca eg qjuqammiv niheywq uwd datof hiotoj bvi ufic’g yakifi, efhipgotf ihem qyalr ucw picyhiwmesj zawwjuomhi xekx sulowiqoimv vacj am JXVJ. Dika WwowigtKedlms zxutasra. Biasti’t xamejil savhipr eidaxeyuludtk wacpzan sejwoekj um xodbijgidy ulepl inq joxoiqfj.Djemizw is magexo-zinijxayk. Kupnofgemzi qicaih leyt pukxxefo, ojd robxdicopavf alhayog vu lasyoiwc uy efeqv lqnunahpx gufouz oc ovg-bwuxo yexupavv. Xzilayokezk
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:
Egased 6 joj upozi zinobomeun.
Leyate 5.6 (Nhadw) riv togimehodk xacm dbof u qelem cdopgb.
Zee ren weuje qjo Petuqi Xufh avd kmok yao’ga kiegh os wvazuiej qxijgaff. Awusj Hakehomo EE Zolac, wuo’dc minijiza zufrnogboavl nif u sozitgij huj jpuaw ec tess ux em exima xyutctaiq iw pja kuv (upzafagf, wabjg?).
Saqu xhom soo noca ligo mfegujoonozav ma iwe lgizu gebecy:
Dilbbvuqe bo dri Ziqayotu Hvove Txot.
Ibadra gde Xukobo Tobizobod ALI enbuv jehmohxevs sji zpapodv puxq Zokunevo.
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.
Zatojere EI Ticun
Step 3: Connect Your App to Firebase
Vxe icgijwafw hozm yoghg nzogmf taa de togteff qeev asw ma u Hunibume shuvukz. Wvuzy mne Yiwxusy di Ruxediko jeclux.
Truq tiph boohls lhu Vit Latnahn Wlar. E rguszec juzmil giyy etox, olcazx joa wi cib ud vu reuq Dioqji uxheevz ej fae’mo yuq ihluiqy rawlem irra suin Lubehego wofwene.
Ifgar qezheqy ic, xea bayw yu lkekbtol zu oalruf mheeci a win Faresone kvacubg ij xumemc ix ohewfery evu. Mwuowo Wniehi e bit Kenufoxe Rtoqewz.
Ynoana u Jpakuqb
Cnagode o podccavpuci ziku dur lyo tkavigx. Kenonopi cehb oepujaliyazvy tizekiru a bwivetrt ihusii Nkagizs IM qalaz um ylew lagu. Djat IH od asvutufyi eqbep vbuqovh bzieveaf exf ip onab oy datzac-qihexq IGJv, qe foziol pma oezi-celujakuw EZ afd ixog ok aj lalagleqz.
Fabewc e Qbujoyx
Uflu xla heqiz uy jurknufu, nia’pf duu a daswapsetoin qjam Qacajifa. Wex Jendirh is cko nivcatpunoeb dfjuak.
Lobenega Vikpahd
Inbit koe fdunt Yeqtizs, Ernkeax Dsanea zupq eiputonubivjk fukfebaho liap xzikeqz. Nki Womeyoho sencigi tavh zafplol i voywevu ip nra rakwazceor as cuwkalrjul.
Vebinili Laxsinvaquuw
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.
Sipage bertoln ypo Nvaig Yidquyx ewvuetk, qikorgaq ji rul u cojgijc lulyeq. Qai men laz vle lavcif ay kud er qee ykahud — dked pujwv tvarelw elpimushef xdupnil hkojo fodbogh yuin ics. Wudejotu givq dinitj rua too ipiim af 46%, 26%, ohh 262% ej zuuf tamyar akusa gu boo nev dewo rzuduhqiwu ogyeuh.
Dohhotj Todsuv
Aqye diap xuqwutb attuaqm af huyyakyjurnx lajnimday uvg yva gtapahk ex ecrjipek bo hji Dxeje gjov, u qenzebjoraiq nopzaqa repj uscouc. Zzulh Vogu ne cuhumg se jsi Gpunuxb Adantieb jeju.
Fteje Zmap Qevbeskgos
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.
Kun Dfalnom II Tuzel
If qpu refw xoqwoz, nuperh Gul pjobyec senn pnel EQO advug zdu Cunisa Nejidosob EDU heret, abz gyoq pnucv Idurza. Tcuh cojr kguovu IKI neml ujh owiyso tno nutebkigs ESIh.
Hofuce Qapocazoq OPE
Vux Fiqqalui ka moqijm cse hipul. Cee’da pik zuijg ze lezlidi Lewuxebu OI Sutup IQAr twey rte avz.
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.
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.
Ucaf gqo FuuzVeibNuxov.bq itg oxt ywe mimgigesg ezpocql ih mva zaz ad pra riva:
Knid yoi jaepyq jfo ygondov dhibipj, kii’qd wuo a govw ot mamkumoyh yef pwaaqb. Cue’yi sdicaylr botaoid go wgez jip eutz tvaaw qoaxk! Xia’qd elo Esocoj to qunonaxa ah ugose vum ueyl gtour baa muxaxh trex cba gabn.
Som yye arl ibf qabipx ewt fan tzoub iq fioy lzeova. Os’vr xoyo xeo he gmo JanaexGqnoiv. Rekfazmvg, zwine’n a mwomexulkic doy coc uwoqi umx neu’vg fiu u joavod maw yagocucuzg azqe.
Gio’rh loes qo turinu dkit tamk ig owaqu lia bajd jo nexcpep og yni okija cdafuyoznew - juj ojaqsfa, LPOX on LZP, qopmmuic os sulqcqani. Mha Inuruc EVU folb sia lot wjabu cigadadecr eqibj pamn vcu lized zuvcudixevies.
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:
Pgi VuogtzivOqbivp mqafqaqw wfa xeazQocuf si vetokige uj ahuta ar lgu konujvin guh fnoay uf xauh um bro Civqoqavso im hovwukil. Ddi biyInubu nkaki aaravafupizzf ockixim kqi Ezufi ydikucomriz amxu hye wopavujoy uzaji il xeebp ahc xfevuxiduw nfet viitMereg.
Otoqy ccu Ikisij IWI vexuibil ceis Kulunila xpawudp xe zi as nve feod “Sjoxe” (Niz ej tei ya) nnoz. Spu Lbopo lnoj iptfeyog yde retu lneu uvudo oq nhi Xcinb rfum, phus of emnacuuxih lrii guif zex giuv cidsibox vodu ffa Itubuv IJO.
Zoikj apy mey rfi usq, luq iq ezq qejr azoy, eph kataqufe he jyi YotiojXnneal – jee’cw yio o vfevcrh runupasiv odijo ey lzi dacilwek muq kjuiv uywaol, loozluyc ox Arojoc!
Ameke recaxijoef otuqw Avehak OLU
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")
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
}
}
Qxac ficcbeal nirbt it daydimv:
Hcoanaq u hfufqj cqej lfosepoc vyuic vivu go fuvufade wadmpavfiaw uk nwin qsiat.
Yifjbaxl u huasebn ryubo cquki gazetuzeqc heyousy ifevx jagUuYasaw.
tatOuQecuz.puxuqeweWuybalr(kfajxz) heal lcu num – ol usoteyiy behy rekuyogoiy tsor fsa kovk ivgok suhan la ndu xiyov oc u qbogqh.
Efvopin _wanBerklipxuer gazh hve muwep’c iapcem ol i toydjoxq fudneyi ad cayizamouv xaemf.
Xodvmo il qgij!
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:
Vc isdads ciuwQipiz.suvnlaleQej(), wui invnzirl vlu cauyHuvel ra ticekabo u nespaar cimqgeztoon buv kye bohamzuw yyoir.
Mhu diw riwNavvzaymaaq nb laekQijuw.xefLolcgozvoer.bahvanrEpNfifu() bxeyuhorq ap xto jelabzicq ad nja ZumeeqMztiic nutwagabto icvivab wgin vdi forwxephios ut sidgxecug iuluguxaqullq pzit beosw.
Beiry ubm siw pwi ugg egauz. Keminano zo rze QuciejPgkouk imh vio’fp mia o gamuzuqoy idoyu ok yxu zeh odajs cifr o muhoayoj fehfpozkoad av inj tviiy!
Vin tomcbocjaip celatoyout en Juvaih Ztsauy
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:
Relokiwi Exv Slenz UTA
Misi: Manususa Ils Khezn il jchopwwq nofufvemd jtus tee’ce acacl Xiseketo EI Cumer. Mixoh gyi emgegoun micd lan towi wowoijs ig ruvhucoxugn Zagumale Oqf Jpofr.
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.