firebase/firebase-ai-logic-basics

Skill oficial para integrar Firebase AI Logic (API de Gemini) en aplicaciones web. Cubre configuración, inferencia multimodal, salida estructurada y seguridad.

¿Qué es firebase-ai-logic-basics?

Este skill oficial proporciona una guía completa para integrar Firebase AI Logic, basado en la API de Gemini de Google, en aplicaciones web. Está diseñado para desarrolladores que desean añadir capacidades de inteligencia artificial generativa a sus proyectos, ya sea para chatbots, asistentes virtuales o procesamiento de contenido. El skill cubre desde la configuración inicial del SDK de Firebase y la autenticación, hasta la realización de inferencias multimodales (procesamiento de texto, imágenes, audio y video) y la generación de salidas estructuradas (como JSON con esquemas definidos). También incluye buenas prácticas de seguridad, como el manejo de claves API y la implementación de reglas de seguridad en Firebase. Compatible con plataformas web (JavaScript/TypeScript) y entornos Node.js, este skill es útil para cualquier agente de IA que necesite guiar a los desarrolladores en la implementación de funciones de IA generativa con Firebase.

Compatible con~Claude Code~Codex CLI~Cursor✓Gemini CLI
npx skills add https://github.com/firebase/agent-skills/tree/main/skills/firebase-ai-logic-basics

Installed? Explore more Productividad y colaboración skills: steipete/gemini, steipete/gh-issues, steipete/skill-creator · View all 6 →

Preguntar en tu IA favorita

Abre un nuevo chat con esta habilidad de agente ya precargada.

Documentación

¿Qué hace firebase-ai-logic-basics?

Skill oficial para integrar Firebase AI Logic (API de Gemini) en aplicaciones web. Cubre configuración, inferencia multimodal, salida estructurada y seguridad.

Introducción

Este skill te permite utilizar la API de Gemini a través de Firebase para añadir capacidades de IA generativa a tus aplicaciones web.

Requisitos previos

  • Un proyecto de Firebase con el plan Blaze (pago por uso).
  • Node.js 18 o superior.
  • Una clave de API de Google Generative AI.

Configuración

  1. Instala el SDK de Firebase:
npm install firebase
  1. Inicializa Firebase en tu aplicación:
import { initializeApp } from "firebase/app";
import { getVertexAI } from "firebase/vertexai";

const firebaseConfig = {
  apiKey: "TU_API_KEY",
  authDomain: "TU_PROYECTO.firebaseapp.com",
  projectId: "TU_PROYECTO",
  storageBucket: "TU_PROYECTO.appspot.com",
  messagingSenderId: "TU_SENDER_ID",
  appId: "TU_APP_ID"
};

const app = initializeApp(firebaseConfig);
const vertexai = getVertexAI(app);

Inferencia básica

Para generar texto a partir de una instrucción:

const model = vertexai.getGenerativeModel({ model: "gemini-1.5-pro" });
const result = await model.generateContent("Escribe un poema sobre la inteligencia artificial.");
console.log(result.response.text());

Inferencia multimodal

Puedes enviar imágenes junto con texto:

import { GenerativeModel } from "firebase/vertexai";

const model = vertexai.getGenerativeModel({ model: "gemini-1.5-pro" });
const imagePart = fileToGenerativePart("ruta/a/imagen.jpg");

const result = await model.generateContent(["Describe esta imagen:", imagePart]);
console.log(result.response.text());

function fileToGenerativePart(path, mimeType) {
  return {
    inlineData: {
      data: Buffer.from(fs.readFileSync(path)).toString("base64"),
      mimeType
    },
  };
}

Salida estructurada

Para obtener JSON con un esquema definido:

const schema = {
  type: "object",
  properties: {
    nombre: { type: "string" },
    edad: { type: "number" },
    hobbies: { type: "array", items: { type: "string" } }
  },
  required: ["nombre", "edad"]
};

const model = vertexai.getGenerativeModel({ model: "gemini-1.5-pro" });
const result = await model.generateContent({
  contents: [{ role: "user", parts: [{ text: "Genera un perfil de usuario aleatorio." }] }],
  generationConfig: {
    responseMimeType: "application/json",
    responseSchema: schema
  }
});

const perfil = JSON.parse(result.response.text());
console.log(perfil);

Seguridad

  • Claves API: No incluyas la clave API directamente en el código. Usa variables de entorno.
  • Autenticación: Implementa Firebase Authentication para controlar el acceso a las funciones de IA.
  • Reglas de seguridad: Define reglas en Firestore o Realtime Database para limitar el uso de la API de Gemini.

Ejemplo de variable de entorno:

export VITE_FIREBASE_API_KEY="TU_API_KEY"

Referencias

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

firebase/developing-genkit-dart

Generates code and provides documentation for the Genkit Dart SDK. Use when the user asks to build AI agents in Dart, use Genkit flows, or integrate LLMs into Dart/Flutter applications.

firebase/developing-genkit-go

Develop AI-powered applications using Genkit in Go. Use when the user asks to build AI features, agents, flows, or tools in Go using Genkit, or when working with Genkit Go code involving generation, prompts, streaming, tool calling, or model providers.

firebase/developing-genkit-js

Develop AI-powered applications using Genkit in Node.js/TypeScript. Use when the user asks about Genkit, AI agents, flows, or tools in JavaScript/TypeScript, or when encountering Genkit errors, validation issues, type errors, or API problems.

firebase/developing-genkit-python

Develop AI-powered applications using Genkit in Python. Use when the user asks about Genkit, AI agents, flows, or tools in Python, or when encountering Genkit errors, import issues, or API problems.

firebase/firebase-ai-logic

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

firebase/firebase-app-hosting-basics

Deploy and manage web apps with Firebase App Hosting. Use this skill when deploying Next.js/Angular apps with backends.

firebase/firebase-auth-basics

Guide for setting up and using Firebase Authentication. Use this skill when the user's app requires user sign-in, user management, or secure data access using auth rules.

firebase/firebase-basics

Provides foundational setup, authentication, and project management workflows for Firebase using the Firebase CLI. Use when checking Firebase CLI version (must use 'npx -y firebase-tools@latest --version'), initializing a Firebase environment, authenticating, setting active projects, or setting up `google-services.json` or `GoogleService-Info.plist` files.

firebase/firebase-crashlytics

Comprehensive guide for Firebase Crashlytics, including provisioning and SDK usage. Use this skill when the user needs help setting up Crashlytics, adding crash reporting, or using the Crashlytics SDK in their application.

firebase/firebase-data-connect

Builds and deploys Firebase SQL Connect (aka Firebase Data Connect) backends with PostgreSQL securely. Use when designing schemas with tables and relations, writing authorized queries and mutations, configuring real-time data updates, or generating type-safe SDKs. Use when you need a relational database with Firebase, or when the user mentions SQL Connect or Data Connect.

firebase/firebase-firestore

Sets up, manages, and executes queries against Cloud Firestore database instances, including advanced native full-text search and relational joins using pipelines. You MUST unconditionally activate this skill if you plan to use Firestore in any way. Use when listing or creating Firestore databases, configuring security rules, designing data models, writing client SDK queries (including search/joins), or checking indexes.

firebase/firebase-firestore-basics

Comprehensive guide for Firestore basics including provisioning, security rules, and SDK usage. Use this skill when the user needs help setting up Firestore, writing security rules, or using the Firestore SDK in their application.

firebase/firebase-firestore-enterprise-native-mode

Comprehensive guide for Firestore enterprise native including provisioning, data model, security rules, and SDK usage. Use this skill when the user needs help setting up Firestore Enterprise with the Native mode, writing security rules, or using the Firestore SDK in their application.

firebase/firebase-firestore-standard

Comprehensive guide for Firestore Standard Edition, including provisioning, security rules, and SDK usage. Use this skill when the user needs help setting up Firestore, writing security rules, or using the Firestore SDK in their application.

firebase/firebase-hosting-basics

Skill for working with Firebase Hosting (Classic). Use this when you want to deploy static web apps, Single Page Apps (SPAs), or simple microservices. Do NOT use for Firebase App Hosting.

firebase/firebase-local-env-setup

Bare minimum INITIAL setup for getting started with Firebase (Node.js, CLI installation, first-time login). Use ONLY for first-time setup. For updating, troubleshooting, or refreshing an existing environment, use the firebase-basics skill instead.

firebase/firebase-remote-config-basics

Comprehensive guide for Firebase Remote Config, including template management and SDK usage. Use this skill when the user needs help setting up Remote Config, managing feature flags, or updating app behavior dynamically.

firebase/firebase-security-rules-auditor

A skill to evaluate how secure Firestore security rules are. Use this when Firestore security rules are updated to ensure that the generated rules are extremely secure and robust.

firebase/firestore-security-rules-auditor

A skill to evaluate how secure Firestore security rules are. Use this when Firestore security rules are updated to ensure that the generated rules are extremely secure and robust.

firebase/xcode-project-setup

Safely modifies Xcode projects (.pbxproj) to add Swift Packages and link files. Use this skill whenever an iOS project needs dependencies installed (e.g. Firebase, Alamofire).

Skills relacionados