
Firebase Ai Logic Basics
Wire Gemini-powered Firebase AI Logic into a Flutter app with the correct CLI provisioning and `firebase_ai` client setup.
Overview
firebase-ai-logic-basics is an agent skill for the Build phase that integrates Firebase AI Logic (Gemini) into Flutter apps using CLI provisioning and the `firebase_ai` SDK.
Install
npx skills add https://github.com/firebase/agent-skills --skill firebase-ai-logic-basicsWhat is this skill?
- Mandatory `npx firebase-tools init ailogic` before client use—skipping causes PERMISSION_DENIED
- `flutterfire configure` only for `firebase_options.dart`, not for enabling AI Logic
- Use `firebase_ai` (not deprecated `firebase_vertexai`) with firebase_core, firebase_auth, and firebase_ai versions from
- Requires reviewing foundational `firebase-basics` workflow before platform-specific steps
- Anonymous or authenticated Firebase Auth sign-in before calling AI Logic APIs
- Recommends firebase_core ^4.0.0, firebase_auth ^6.0.0, firebase_ai ^3.0.0 in pubspec
- `npx firebase-tools init ailogic` described as mandatory for service provisioning
Adoption & trust: 39.7k installs on skills.sh; 345 GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
You want Gemini in a Flutter app but Firestore-style console toggles or `flutterfire configure` alone leave AI Logic unprovisioned and API calls blocked.
Who is it for?
Indie builders already on Firebase who are adding AI features to a Flutter codebase and want the official init sequence spelled out.
Skip if: Teams that need only web/JavaScript Firebase AI, server-only Gemini without Firebase, or apps with no Firebase project yet—start with `firebase-basics` and project setup first.
When should I use this skill?
Integrating Firebase AI Logic (Gemini) into Flutter; when PERMISSION_DENIED suggests AI Logic was not CLI-provisioned.
What do I get? / Deliverables
After following the skill, your Firebase project has AI Logic enabled via CLI, Flutter dependencies and init/auth order are correct, and the agent can implement calls with `firebase_ai`.
- Updated pubspec.yaml with firebase_ai dependencies
- Initialized Firebase + auth + AI Logic client wiring in Dart
Recommended Skills
Journey fit
Canonical shelf is Build because the skill is implementation-focused: dependencies, init, and app code for Firebase AI on Flutter. Integrations fits Firebase backend services plus on-device/client SDK wiring rather than pure UI or docs work.
How it compares
Firebase-specific Flutter integration playbook, not a generic LLM prompt or non-Firebase Gemini SDK guide.
Common Questions / FAQ
Who is firebase-ai-logic-basics for?
Solo and indie developers using Flutter with Firebase who need a repeatable path to enable and call Firebase AI Logic (Gemini) from the client.
When should I use firebase-ai-logic-basics?
During Build when you add `firebase_ai` to a Flutter app, after Firebase core is in place, and especially before first model calls so you run `firebase-tools init ailogic` and auth initialization in the right order.
Is firebase-ai-logic-basics safe to install?
Treat it as official Firebase agent guidance that will suggest CLI and dependency changes; review the Security Audits panel on this Prism page and your Firebase/API keys policy before running commands in production projects.
Workflow Chain
Requires first: firebase basics
SKILL.md
READMESKILL.md - Firebase Ai Logic Basics
# Flutter Setup for Firebase AI Logic This guide covers how to integrate Firebase AI Logic (Gemini API) into your Flutter applications. > [!IMPORTANT] > **Foundational Workflows & CLI-First Approach:** > 1. **Review Foundation:** Before implementing platform-specific code, ALWAYS review the foundational `firebase-basics` skill to ensure familiarity with core workflows. > 2. **Backend Provisioning via CLI:** Use the Firebase CLI for backend setup. Running `npx firebase-tools init ailogic` is MANDATORY to provision the service. `flutterfire configure` does NOT enable the AI service and will result in `PERMISSION_DENIED` if skipped. > 3. **Client Configuration:** Use `flutterfire configure` strictly for generating `firebase_options.dart`. Avoid manual Console configuration. > [!NOTE] > `firebase_vertexai` has been replaced by `firebase_ai`. Always use `firebase_ai` for new projects. ## Installation Add the necessary Firebase dependencies to your `pubspec.yaml`: ```yaml dependencies: flutter: sdk: flutter firebase_core: ^4.0.0 firebase_auth: ^6.0.0 firebase_ai: ^3.0.0 ``` Run `flutter pub get` to install the packages. ## Initialization Initialize Firebase and sign in (anonymously or via authenticated user) before using AI Logic. ```dart import 'package:firebase_core/firebase_core.dart'; import 'package:firebase_auth/firebase_auth.dart'; import 'package:firebase_ai/firebase_ai.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp(); await FirebaseAuth.instance.signInAnonymously(); runApp(const MyApp()); } ``` ## Usage Use `FirebaseAI.googleAI` for the **Gemini Developer API**. > [!IMPORTANT] > **Model Selection:** Always use **`gemini-flash-latest`**. DO NOT USE `gemini-1.5-flash`. > [!IMPORTANT] > **Choose the Right API Provider:** Always use `FirebaseAI.googleAI` (Gemini Developer API) as the default for prototyping and standard use. Avoid using the Vertex AI Gemini API unless your application specifically requires enterprise-grade scalability and is configured for the Blaze plan. ### Text Generation ```dart import 'package:firebase_ai/firebase_ai.dart'; import 'package:firebase_auth/firebase_auth.dart'; Future<String> generateText(String prompt) async { final googleAI = FirebaseAI.googleAI(auth: FirebaseAuth.instance); // Use the latest Gemini Flash model final model = googleAI.generativeModel(model: 'gemini-flash-latest'); final response = await model.generateContent([Content.text(prompt)]); return response.text ?? 'No response'; } ``` ### Chat Session ```dart final chat = model.startChat(history: [ Content.text('Hello, I am a user.'), Content.model([TextPart('Hello! How can I help you today?')]), ]); final response = await chat.sendMessage(Content.text('What is CBT?')); ``` # Firebase AI Logic iOS Setup Guide ## 1. Import and Initialize Ensure you have installed the `FirebaseAILogic` SDK via Swift Package Manager. ```swift import FirebaseAILogic // Initialize the Firebase AI service and the generative model. let ai = FirebaseAI.firebaseAI() // Specify a model that's appropriate for your use case. let model = ai.generativeModel(modelName: "gemini-flash-latest") ``` ## 2. SwiftUI Integration (Best Practices) Use the `@Observable` pattern to manage AI state and provide a smooth UX with loading indicators and error handling. > **⛔️ CRITICAL WARNING:** Do NOT initialize the model inline as a class property if there's any chance the view model is instantiated before `FirebaseApp.configure()` executes in the app root. > To be safe, initialize the model lazily or pass it in from a point in the hierarchy where Firebase is guaranteed to be configured. ```swift import SwiftUI import FirebaseAILogic @MainActor @Observable final class AIViewModel { // Initialize lazily to ensure FirebaseApp is configured first private lazy var model = FirebaseAI.firebaseAI().generativeModel(modelName: "gemini-flash-latest") va