firebase-ai-logic-basics

작성자: firebase

Firebase AI Logic(Gemini API)를 웹 애플리케이션에 통합하기 위한 공식 스킬입니다. 설정, 멀티모달 추론, 구조화된 출력 및 보안을 다룹니다.

npx skills add https://github.com/firebase/agent-skills --skill firebase-ai-logic-basics

Firebase AI Logic Basics

Overview

Firebase AI Logic is a product of Firebase that allows developers to add gen AI to their mobile and web apps using client-side SDKs. You can call Gemini models directly from your app without managing a dedicated backend. Firebase AI Logic, which was previously known as "Vertex AI for Firebase", represents the evolution of Google's AI integration platform for mobile and web developers.

It supports the two Gemini API providers:

  • Gemini Developer API: It has a free tier ideal for prototyping, and pay-as-you-go for production
  • Vertex AI Gemini API: Ideal for scale with enterprise-grade production readiness, requires Blaze plan

Use the Gemini Developer API as a default, and only Vertex AI Gemini API if the application requires it.

Setup & Initialization

Prerequisites

  • Before starting, ensure you have Node.js 16+ and npm installed. Install them if they aren’t already available.
  • Identify the platform the user is interested in building on prior to starting: Android, iOS, Flutter or Web.
  • If their platform is unsupported, Direct the user to Firebase Docs to learn how to set up AI Logic for their application (share this link with the user https://firebase.google.com/docs/ai-logic/get-started)

Installation

The library is part of the standard Firebase Web SDK.

npm install -g firebase@latest

If you're in a firebase directory (with a firebase.json) the currently selected project will be marked with "current" using this command:

npx -y firebase-tools@latest projects:list

Ensure there's at least one app associated with the current project

npx -y firebase-tools@latest apps:list

Initialize AI logic SDK with the init command

npx -y firebase-tools@latest init ailogic

This will automatically enable the Gemini Developer API in the Firebase console.

More info in Firebase AI Logic Getting Started

Core Capabilities

[!WARNING] CRITICAL: Use current model names: Always check the Firebase AI Logic Models documentation for the currently supported model names. Do NOT use gemini-2.0-pro or gemini-2.0-flash or other older models that are shutdown.

Text-Only Generation

Multimodal (Text + Images/Audio/Video/PDF input)

Firebase AI Logic allows Gemini models to analyze image files directly from your app. This enables features like creating captions, answering questions about images, detecting objects, and categorizing images. Beyond images, Gemini can analyze other media types like audio, video, and PDFs by passing them as inline data with their MIME type. For files larger than 20 megabytes (which can cause HTTP 413 errors as inline data), store them in Cloud Storage for Firebase and pass their URLs to the Gemini Developer API.

Chat Session (Multi-turn)

Maintain history automatically using startChat.

Streaming Responses

To improve the user experience by showing partial results as they arrive (like a typing effect), use generateContentStream instead of generateContent for faster display of results.

Generate Images with Nano Banana

[!WARNING] Use current Image model names: Always check the Firebase AI Logic Models documentation for the currently supported image generation (Nano Banana) model names.

  • Requires an upgraded Blaze pay-as-you-go billing plan.

Search Grounding with the built in googleSearch tool

Supported Platforms and Frameworks

Supported Platforms and Frameworks include Kotlin and Java for Android, Swift for iOS, JavaScript for web apps, Dart for Flutter, and C Sharp for Unity.

Advanced Features

Structured Output (JSON)

Enforce a specific JSON schema for the response.

On-Device AI (Hybrid)

Hybrid on-device inference for web apps, where the Firebase Javascript SDK automatically checks for Gemini Nano's availability (after installation) and switches between on-device or cloud-hosted prompt execution. This requires specific steps to enable model usage in the Chrome browser, more info in the hybrid-on-device-inference documentation.

Security & Production

App Check

[!WARNING] Critical Safety Requirement: In order to use AI Logic safely, you MUST set up App Check on your app. This prevents unauthorized clients from using your API quota and accessing your backend resources.

See App Check with reCAPTCHA Enterprise for setup instructions.

Remote Config

Consider that you do not need to hardcode model names (e.g., a specific model version string). Use Firebase Remote Config to update model versions dynamically without deploying new client code. See Changing model names remotely

[!WARNING] CRITICAL: Backend Provisioning Required For all platforms (Flutter, Android, iOS, Web), you MUST run npx firebase-tools init ailogic to provision the service. flutterfire configure ONLY handles client configuration and does NOT enable the AI service, leading to PERMISSION_DENIED errors.

Initialization Code References

Language, Framework, PlatformGemini API providerContext URL
Web Modular APIGemini Developer API (Developer API)firebase://docs/ai-logic/get-started
iOS (Swift)Gemini Developer APIios_setup.md
Flutter (Dart)Gemini Developer APIflutter_setup.md

[!WARNING] CRITICAL: Use current model names: Always check the Firebase AI Logic Models documentation for the currently supported model names. Do NOT use gemini-2.0-pro or gemini-2.0-flash or other older models that are shutdown.

References

Web SDK code examples and usage patterns iOS SDK code examples and usage patterns Flutter SDK code examples and usage patterns

Android (Kotlin) SDK usage patterns

firebase의 다른 스킬

firebase-remote-config-basics
firebase
Firebase Remote Config에 대한 포괄적인 가이드로, 템플릿 관리 및 SDK 사용법을 포함합니다. 사용자가 Remote Config 설정, 기능 플래그 관리, 또는 앱 동작을 동적으로 업데이트하는 데 도움이 필요할 때 이 스킬을 사용하세요.
officialdevelopmentapi
developing-genkit-dart
firebase
통합 AI SDK for Dart로 코드 생성, 구조화된 출력, 도구, 플로우 및 에이전트를 지원합니다. 단일 인터페이스로 생성, 도구 정의, 플로우 오케스트레이션, 임베딩 및 스트리밍을 위한 핵심 API를 제공합니다. LLM 제공업체(Google Gemini, Anthropic Claude, OpenAI GPT), Firebase AI, Model Context Protocol, Chrome 브라우저 통합, Shelf를 통한 HTTP 서버 호스팅을 위한 8개 이상의 플러그인을 포함합니다. 플로우 실행, 추적, 모델 실험 등을 위한 로컬 개발 UI가 포함된 내장 CLI를 제공합니다.
official
developing-genkit-go
firebase
Go에서 Genkit을 사용하여 AI 기반 애플리케이션을 개발합니다. 사용자가 Genkit을 사용하여 Go로 AI 기능, 에이전트, 플로우 또는 도구를 구축하거나 작업할 때 사용합니다.
official
developing-genkit-js
firebase
Genkit 플로우, 도구 및 멀티 모델 지원을 통해 AI 기반 Node.js/TypeScript 애플리케이션을 구축합니다. Genkit은 제공자에 구애받지 않으며, 플러그인을 통해 Google AI, OpenAI, Anthropic, Ollama 및 기타 LLM 제공자를 지원합니다. Zod를 사용하여 타입 안전 스키마로 플로우를 정의하고, 생성 요청을 실행하며, TypeScript로 다단계 AI 워크플로우를 구성합니다. Genkit CLI v1.29.0+가 필요하며, 최근 주요 API 변경 사항으로 인해 이전 지식이 아닌 현재 패턴을 위해 genkit docs:read 및 common-errors.md를 참조해야 합니다...
official
developing-genkit-python
firebase
Python에서 Genkit을 사용하여 AI 기반 애플리케이션을 개발합니다. 사용자가 Genkit, AI 에이전트, 플로우 또는 Python 도구에 대해 묻거나 Genkit을 접할 때 사용합니다…
official
firebase-ai-logic
firebase
웹 앱을 위한 클라이언트 측 Gemini 통합으로, 멀티모달 추론, 스트리밍, 온디바이스 하이브리드 실행을 지원합니다. 텍스트 전용 및 멀티모달 입력(이미지, 오디오, 비디오, PDF)을 지원하며, 20MB를 초과하는 파일은 Cloud Storage를 통해 라우팅됩니다. 자동 기록이 포함된 채팅 세션, 실시간 디스플레이를 위한 스트리밍 응답, 구조화된 JSON 출력 적용을 제공합니다. Chrome의 Gemini Nano를 통한 온디바이스 하이브리드 추론을 지원하며, 자동으로 클라우드 실행으로 폴백됩니다. 프로덕션 환경에서는 App Check가 필요합니다...
official
firebase-app-hosting-basics
firebase
Firebase App Hosting을 사용하여 Next.js, Angular 및 기타 지원되는 프레임워크로 풀스택 웹 앱을 배포하고 관리합니다. Firebase 프로젝트가 Blaze 요금제에 있어야 하며, 서버사이드 렌더링(SSR) 및 증분 정적 재생성(ISR) 워크플로를 지원합니다. 백엔드 설정을 위한 선택적 apphosting.yaml과 함께 firebase.json 구성을 통해 배포하거나, GitHub 통합을 통한 자동화된 "git push to deploy"를 활성화할 수 있습니다. 민감한 키에 대한 안전한 접근을 위해 CLI 명령을 통한 비밀 관리 기능을 포함합니다...
official
firebase-auth-basics
firebase
Firebase 인증을 여러 ID 제공업체와 함께 설정하고 데이터 접근 규칙을 보호합니다. 이메일/비밀번호, 전화번호, 익명, 연합 제공업체(Google, Facebook, Twitter, GitHub, Microsoft, Apple) 및 사용자 지정 인증 통합을 지원합니다. 각 인증된 사용자는 Firebase 서비스에 접근하기 위한 고유 ID와 JWT 기반 토큰(단기 ID 토큰 및 장기 갱신 토큰)을 받습니다. Google 로그인, 익명 및 이메일/비밀번호에 대해 CLI를 통해 제공업체를 활성화하고 Firebase Console을 사용합니다...
official