All skills
firebase avatar

/firebase-ai-logic-basics

@eca0362 official
by firebasefirebase/agent-skills461 stars
102

Official skill for integrating Firebase AI Logic (Gemini API) into web applications. Covers setup, multimodal inference, structured output, and security.

Use this Skill: https://skilld.dev/gh/firebase/agent-skills/firebase-ai-logic-basics

This session only. Nothing lands on disk.

referencesflutter_setup.md

≈834 tokens on demand. Your agent reads this file only when SKILL.md points to it.

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:

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.

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: Refer to Firebase AI Logic Models to find the latest supported model. Do not use old models like gemini-2.0-pro or gemini-2.0-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 Agent Platform Gemini API (formerly branded Vertex AI) unless the app and business use case specifically require enterprise-grade scalability or data residency requirements. Note that the Gemini Developer API usually does not require the Firebase project to be on the pay-as-you-go Blaze pricing plan; however, the Agent Platform Gemini API does require the Blaze plan.

Text Generation

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);
  
  // [AGENT] Replace '<latest_supported_model>' with the latest model from https://firebase.google.com/docs/ai-logic/models.md.txt
  final model = googleAI.generativeModel(model: '<latest_supported_model>');

  final response = await model.generateContent([Content.text(prompt)]);
  return response.text ?? 'No response';
}

Chat Session

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?'));

Source: SKILL.md on GitHub

No alerts13d3 checks · Risk SAFE
  • Gen Agent Trust Hub13d

    The skill provides legitimate instructions and code samples for integrating Firebase AI Logic into web, mobile, and Flutter applications. It correctly identifies security requirements such as App Check and encourages the use of managed secrets for CI/CD pipelines.

  • Socket13d

    No alerts

  • Snyk13d

    Risk: LOW · No issues

Signed by skilld at eca0362. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 days ago.

Activeupdated 2 weeks ago
version
1.0.1
metadata
{
  "category": "AiAndMachineLearning"
}

README badge

README badge for firebase/agent-skills/firebase-ai-logic-basics