Skip to main content
Firebase Cloud Functions is a natural host for Genkit flows. Your flows run on demand, scale automatically, and have built-in access to other Firebase and Google Cloud services through the service account attached to the function.
Firebase Functions supports Node.js. For Python or Go deployments see Cloud Run.

Prerequisites

  • A Firebase project with Blaze (pay-as-you-go) billing enabled.
  • Firebase CLI: npm install -g firebase-tools
  • Node.js 20+

Project setup

1

Initialize Firebase

If you do not already have a Firebase project configured:
Choose TypeScript when prompted. This creates a functions/ directory with package.json, tsconfig.json, and src/index.ts.
2

Install Genkit packages

3

Write your function

Edit functions/src/index.ts:
4

Configure environment variables

If you are using the Gemini API key model plugin, store the key in Firebase Secret Manager:
Then reference the secret in your function configuration:
Vertex AI reads credentials directly from the Cloud Function’s service account via Application Default Credentials (ADC). No API key or secret is required when deploying to Firebase/GCP.
5

Deploy

After deployment the URL is printed to the console:
Invoke a flow:

Firebase telemetry

The @genkit-ai/firebase package provides enableFirebaseTelemetry, which routes traces, metrics, and structured logs to Google Cloud Observability (Cloud Trace, Cloud Monitoring, Cloud Logging) using the same pipeline as the @genkit-ai/google-cloud plugin.
See Production monitoring and observability for details on what is traced and how to view it. The @genkit-ai/firebase package exports defineFirestoreRetriever, which wires a Genkit retriever to Firestore’s native vector-search feature (findNearest). Use it to build RAG flows that query documents stored in Firestore.
You must create a vector index on the embedding field in Firestore before nearest-neighbor queries will work. See the Firestore vector search documentation for index creation.

Durable streaming

For long-running flows, use FirestoreStreamManager (or RtdbStreamManager) so that clients can disconnect and reconnect without losing stream state:
Firestore durable streaming stores each stream’s full history in a single document. Firestore has a 1 MB per-document limit. Flows that produce very large outputs should use RtdbStreamManager or a custom StreamManager implementation.

firebase.json configuration

Next steps

Cloud Run

Deploy containerised Genkit apps with more control over the runtime.

Observability

Configure tracing and monitoring for production.