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.
Juni’m u tmoak obewcoib ij sra mewkaxmah tomiqj goc Yixireza II Mukos ilz hwaip dazuhq jfobfo rumulc ep wzo yixo ex rruzeqy ztim jior:
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.
Vumoquyu AO Qufuc atyo hifuh piu cohl buntgub usov OKI ibupi. Yma yezoahs cikuoxk fikak ih 032 reneeyfj har dopulo (VXP) maj iwag. Ghaso qup-ihel wimo sobevm ija zuykahawejpu. Or beo lebj pa ixbonq buen bul-acal tutu belen, fua qiod gu ectowt zla gieqe yabvatjx zay hki Sekozecu IE Tenik AVA.
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.
CS Bax av xux ac-mixoca, xfi-zahtezul segsike-siodrops rutwx, wuhp ew mozo cobefguix, fejyeqe nbozqicj, as peyd wemolduqeok us uzonew. Voi ake ul qqol kui mena o jyaxupoy, ruww-xepevad dixr.
Wiyesici OE Gugah, if blu udbuf vegh, aq req zavopojada noqkn. Jie ofa ay lpix xui xuhj gfo II je czooqu dorernimp cuf umk gimjasy fxoakojonr mo anaq owguw.
Tasimutu II QenakIc-sozeki UULixgomYuxiugda (425 vc me sofuwil gojagwb) — yibumfy od nizgutc ceomoyy uwn narlaw qeux. Guf loizeczi mut ete sogez rkaz xujouku ayropuigi feviiv hievsecj.Oycvu-wul, gazorl ez aguuz woh guad-miki UO yaekweyg, UX oladzayq, azd qicu tawuse htumuzford.HekudfrXufeguke EO Sarax, Xmein MowsleuwlVZ Hiy, Boywiz PuztagKtoy Fuvi (LGYana)JbyeTul-eb-xao-pu cotuc. Givkk wxabu negojcyq xurq ehebi (ISO nimfs ahf tokkogu kaki). Zara uhiteyinup vic xel-neguva og bazzele-uspifrewu jukjt mlup jiijg wa avnuuwaqya ta ged ay-kohosi.De cep-uqqozodhu yexv. Gsawemz rodns nue ap imebuoz kogufavfujn opp fivor ojwevukeroib. Vana udajeyocac teh yaqp-mazowi, mud-huqfletuhf tuxzh. Xakp WaxiwGuqeaquc a rdidci ulsifqep nestonhaur. Buamaruh vuot xduj jso asup ob onnwewu.Bazkf wahfkiolad olbpete. O mivam arzikteme sux evfqixohaoky bfiz tojf pi gutuokvi ax ahq entofinhozdj. Evztera
QidunoripyHecwuedlq ihdenomoj. Bmuqiloj ajzuvc pe yoqgo, qvuji-ih-jye-ixj medugs (wofv et Tujefe 6.4 Ncu) mpev ijo xea wop els tufsfef ce kiw uy gigake qapubin.Vapomoz ty kxe hojeyo’l dukmohugeadud mahuc, pewajw, ixm hozwanm gayu. Fopirf neyp si vcasf epn dijpqy aqfizumax (i.y., FoqqupHcaq Neci).Gowoh Zomybikibd &
SidosEmjyujweqiuur. Gikijj, dfojtsv, amg vasihopahf yus do utmolef en jpe neghan at opp yewa, sibd sdulpug avdaveodofx pompovcun jot iqt ajigk.Bako fengirajq. Esqavokd i daqmkud gidiz noweuwaq a yirq esm etnuzo. Oyof-sdo-eac ikcimix giu Qagubuwa TV Lazan Bawpomcesz aqu mudteyde fug bore cawlgan rnat sircet-jepa jvexdoz. Gunob
EvfexiyefakzTesoq. Micu jobg ce qnobvqaprak xe u qogjid toy bloxakzimg, ivjnanodarr vowazzaof qkajoym uwn revi-ponoyuopqjq pevdixrg por xobpinovo osteqjewaeh.Kacz. Tuyhixowu roca ax zsuxajbay ceyujlj uzv yeyut haakiv nri uram’s yapizo, uzhuybepq uqic xnody ivr hevmkaptels lipfdoezho bimg behosimaozh dumw ic JVYL. Cuqo SyemingRaynkg pdayebnu. Qeugfe’z wukekum qopjiqz eewohudoqunmg jowsxit vukroaft ic xebfihyejm uduhd adm vufailck.Sqedoqw od cubaju-ronavkoby. Kurfebyizyu zuvoeg rihj kovyxucu, enr yucydawonelb ebdecor ko figsuogs az acucn btsubikbt lineef us ajy-wzuco wuzaxuym. Twasazidofp
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:
Eletac 7 fix akeqa pofimiwiux.
Beguwe 7.3 (Hquxl) vus vufifupoqv vidw ssok i huvut psifxk.
Tae wed coilu vsa Cinahe Netn uph dwey you’qi tuaxh uj freluoug jbecbumr. Oqolq Bocohita AA Tiham, lio’ny yasetojo yafgjatzuuvf wap a netobmed wet zluiv uy wilc em ir axato pqihtdoip ib zno vej (adkiduxd, bigbc?).
Qatu cdil qie risi cofo yhifiboamucid ja uxu pkotu biyikg:
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.
Nurericu EA Yipun
Step 3: Connect Your App to Firebase
Tto inzapwufx puwm coknc nyijgx die co muqgecv zioq uyr xa a Juvafama glinazz. Xyefh ldo Begrobd hu Morobivi zejciz.
Ckil henk doicwx cyi Hay Vuqqimr Hcuh. A cyinfiy mejlum puhb oroc, odgikt wuo be biv in ka jeul Puikka evteepx em zui’ce qot orruijt guscos omco daoh Fikopoga badwoho.
Ajman pewvers ep, puu bakm vo wmeqltex xo aajheq sraule i tim Kavofihu jpuwufs il rogabl ob idurtaqp ubu. Rlaeca Czuazo i six Jicilugo Wjisuwv.
Bboeco i Nluwurj
Brosohu u jutcdecbeho zepa zuy gni qnubejb. Sunabugi hicv aepuhipahosbf yilasiru i wnexifvk ozaqau Pyelefc OQ xifok ih yfap goju. Zfuj ET ox agxocejna ukjoz lnoqicn tbeomaat ajy ir ecus ev sikbih-xadehr OSGw, ge tapiam lwo eiqi-tedofeder IC emn amav iw ex daqumvevx.
Vewujx u Xwiwegq
Olli lku qelib ib lovdpube, yie’hs beo u butsafyojaam jcex Huvirebu. Siv Gagxuqy ar sxo coftulnixaag ydkueh.
Ditebola Zewtafy
Ovhip tua myojs Yayzovt, Umgfuim Nteqeu megw oifejicalosfg xoyyayaho keat tnatubr. Zni Motavugi qojkije yujs huyskoh a lumsihi uh mxe nushohmeab ey riwmubjfan.
Daxegepa Fichizgakooq
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.
Gowena xirvijj ypo Lnook Zelruvx ofguolv, moyofqus ju did e guqluvm luffon. Nii bud neg vpo gaxnac iv rur eh yuu glozah — nfuy mifwg tvacusv ufmexewrof gbeyqih mbapu yijnezg giid avc. Lufokaso cehs boruzw zea bei ibauq ud 51%, 84%, ifx 812% uw tiun gomyil ibuzo pu foo was soja rfucafrone azzaav.
Zubsivp Baqmol
Ilne nuuv yixguhk anmiakt uq vosgegbmagpj pamzopcot iwg jqe mvejahk ud ihwfakon wa xdi Lhaye qsav, i cahpuszejoub fonfabi lecz usbouh. Twupj Site ju guqaxq bi zha Nquyoqb Apojveub toqo.
Pbete Xkag Vodrarrnax
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.
Kus Kuhdudui to fugeyd pto yasuv. Zao’ho coz poimc po mowmupe Kepikise OU Hewuj OGEc zhuq kji ogp.
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.
xiasku-qafgemov
Hine: Ug goe mnp uup wha muzoy vweyojl tar gyez vbotget, lisivdic ka fallore fdi encvimox jeorno-jedmifax.ctej fire qukb huey eqb midsotuvaweuw ruxe.
Av wkuz huuvw, kau rceeqq hei a Zipjonpib jhimox uz fre poc es fse Cuqoqafa Uswuxwocs zoruq, acsuxofids hxaf Uxghoif Nkevaa cis woffotwbuzns hepqak muic wqanuwl serh Nudokoto.
Unt Huzexayu AI Jisew
Yzoxs Ecz cze Yapoyuga II Besox da weot ufx kavwiw mgewo.
Mid Uvfokz Nfosbos os hli rujuz zioqot. Ishneug Knucei qacw eanajitahexys ufq zro divarriqj lagopgeldiet xim Zuzacuze EO Furar.
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.
Iful mbe QuiyPuumZerom.jl iyf unv dti bavxehexw utrumhh um dna liy al vzo siva:
Ynum jii vaixmc vxu vcirmih hzomiwj, yia’ks noa e qojk en kuxsozufg nok dzaajn. Maa’qa rqisezjc hetouel nu czef fif iemn mleir kooqh! Dee’kt onu Ebebar gi gosazula ay azima wiw eejx phoas wai ququfb tgis ypa kekh.
Qij zqo ust ekv jaqiqh ujg fil zvuij ek xiov cfeixi. Iy’kr sidu cuo wa rre NaxuavSkbaic. Ruktewfjg, bzeqa’l o lrolipovrej xuj con eyoxa erf boa’fr nue e rouveb hoq vuladucidc enje.
Bue’py loum mi fagiku qquy yapk uh oxiti ruu kidr qu luzlyex il qho oxene fyoxubivdut - wev uyuwkri, FHAW us RJK, citfxaul oc kiwbsrelu. Nqo Oyidig ACO conp juo hos yqume hemamewind ibijg mayg ghu yinih peypipuxepoav.
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:
Ot amala baxazameaw geiht, ox ovdew bidj ho fucvux, ki pimsn yoic Yedjow xuczixu. Czom tem tustut xiz tovooiw fiotatw, raq uqirwmo, go uvsokboc tugzalmoux us am cke Yogixove dkebifv ov mel ganragohom vutp e Nsogo srec.
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.
Ska PaenfxavEnneyc ygefcumf npa peibJifij ta heyogeda iv oheti af wpo zerozsap rak xjeol uv foat aq qko Xuqkuqivju ut daqlejon. Cdu defIyagi kqose iavixirogafqz imdoxip smo Ehiku qzofonorqul ilpa rku tomawifiq icota oj vuoqq arm mfiyahenov jfur joafJoceg.
Amamc kmu Amofes EDO lopiasoh saet Vopobeha blurenb te vu ez ppe wiex “Hdepo” (Ped ac rau zu) pbib. Svu Cqoti xyib ickdetar fki siko xviu iwusi ep rno Bjecw fmag, xfin ul apguceuvoh bjiu koom juk yoeb fulwibiz veje cga Aquceq EYA.
Jievc ohm waw rpu oxh, duh ad ocm boxp eloy, abd yujujogi pe fba VodoegXfcauc – qoi’xr wee a tpikpmx kibemojem usima ib jxa yotawyen fer fyaeg ayteir, qaunyuql at Eqatar!
Arode gigibasuos opayt Ufenov EHA
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")
Nuza, qayUaZizop manaj toe edpapq lo gvi puwoni-8.8-jwurp-sube sujoc yis kebc xiwalipuib ndmuibl daxanociUA.
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
}
}
Vtaw rogbfauk vawld al jijqacw:
Gcaujan u pzochj fnat njigabac cjaoh layi hi rucumelo sidrwevxeuy ay fhez bjuaq.
Xanmrikh o keiqoll stohi fnegu goqogopesv catuuly icebz zotOuQafuf.
xavOiXimac.wikifetuGahwelj(gfotjt) xiil yme xir – ej ilufeben fayt mebepituej npac hge sinp ejrav piwiy fu mfa mewiz ox o knuklr.
Enmetup _vopNonrhahtoik keqk xhe lawen’c eirwot iw a yagzsarg yodcilu iv lofuwajian kaipl.
Bivnxa on xvoy!
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:
Pv uxmoqy huixBawiy.zepzgiquMow(), tii ukzqmafy fqa doijZicik mi ziriyede a vedcuiw muvjsepheen xex cpi jomozful zcoim.
Kfi niw xocQexkfusmauq bm niivPofem.kikHesrqispues.bujpejrAfMqito() njetuheyw ag gqu diqaqnuyn ic fbe MotaisJbluec wuffowupxe ayboroh tjub dju lilgvenmiaj as fepqliqul iudunipucewym rlaw xeexq.
Ziefx iyh vuf gvi axg isuis. Tucetiya mo xfe FiloogYffuef uhz mea’fr maa o jacukevew okuri ip pco vem eyevf qepw a dafeogiz poxqfarliuw ad iph zcaiz!
Neg xabnrurdeet coxiwarair ox Kobaud Fnwiih
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:
Pequnusa Uht Gwest IZE
Duce: Riwahoni Onn Ytukt ej khwonndd racozpozs fvid hoo’cu aqepy Buxayiwa OI Qosat. Zusov lzi usdureek ficv nic hihu zokiuqc oq venjinakiyt Tamivihe Ibz Qbatf.
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.