↑ ↓ navigate↵ selectesc close

Add image generation to your apps with Imagen 3 in Firebase: Web Architecture & Implementation Guide

CodingCat.dev tutorial cover image

Calling frontier multimodal models directly from a web or mobile client is a security minefield if you expose raw API keys or hardcode brittle system prompts in your frontend bundle. Following the announcement of Add image generation to your apps with Imagen 3 by Miguel Ramos on the Official Firebase Blog (2025-03-03), here is our hands-on CodingCat.dev breakdown of what actually shipped, how it works under the hood, and how we wire it into production TypeScript, Next.js, Astro, SvelteKit, React, and Angular applications. Update: As of May 2025, Vertex AI in Firebase has evolved into an offering named Firebase AI Logic to give developers more options for easily integrating generative AI models into their apps. Check out the documentation to learn more.

The Mental Model: Why Add image generation to your apps with Imagen 3 Matters for Web Devs

As a Google Developer Expert (GDE) for Firebase and Senior Solutions Engineer at CodingCat.dev, I evaluate every Firebase update through one lens: does it reduce boilerplate while keeping our runtime security and cloud bills predictable? Firebase AI Logic lets you invoke Gemini and Imagen models from client and edge apps using the Firebase Web SDK while keeping your API credentials off the wire, enforcing Firebase App Check, and managing server-side prompt templates centrally.

AJ Pro-Tip from Alex: Combine Firebase AI Logic with server prompt templates, Firebase Remote Config feature flags, and project spend caps so you can iterate on prompts or swap Gemini models instantly without redeploying your Next.js or Astro frontend.

How It Works: Technical Breakdown & Implementation

Vertex AI in Firebase allows developers to integrate generative AI into their applications by providing a streamlined, serverless, and secure way to access the Gemini AI models. Used by thousands of apps today, it handles the complexities of AI infrastructure, simplifies development, letting you focus on building great user experiences.

Now, we’re taking that further adding support for the Imagen models (Imagen 3 and Imagen 3 Fast), in addition to the Gemini family of models. This lets you add image generation directly to your Android, iOS, Flutter, and Web applications, bringing the same ease of use and scalability you expect.

What can you do with Imagen 3 in Firebase

The Vertex AI in Firebase SDKs allow to choose between speed and quality giving you access to both Imagen 3 models:

  • Imagen 3: A high-quality image generation model, capable of producing detailed images.
  • Imagen 3 Fast: A low-latency version of Imagen 3, optimized for speed. Choose this when responsiveness is paramount.

Here’s what’s possible, directly within your client-side code:

  • Generate images from text: String prompt = "A futuristic cityscape at sunset"; - that’s all it takes.
  • Various formats: create images in a range of resolutions, allowing you to optimize for storage and display.
  • Text within images: generate images that incorporate text, opening up possibilities for dynamic content creation within your app.
  • Watermarking: add watermarks for image attribution and provenance.
  • Safety settings: adjust safety filters to help control the content generated.
  • Up to 4 images: generate a maximum of four images per request to manage device resources.

Take a look at these photos generated with Imagen 3:

Getting started

To integrate Imagen 3 into your Firebase project, you should enable Vertex AI in Firebase, add the Firebase SDK to your project, and initialize the service. Once set up, generate an image by initializing your chosen Imagen model and calling generateImages() with your text prompt.

// Initialize the Vertex AI service
let

// Initialize with an Imagen 3 model that supports your use case
// like "imagen-3.0-generate-002" or "imagen-3.0-fast-generate-001"
let

// Provide an image generation prompt – this could come from user input
let

// To generate an image, call generateImages with the text prompt
let

// Handle the generated image
guard
  fatalError
}
let
// Specify the number of images
final
  model
    generationConfig
);
const

final

final
for
  // Process the image
}

If you need more control over the image generation, you can configure the model and even set safety settings, for example:

const
  aspectRatio: ImagenAspectRatio.LANDSCAPE_16x9,
  imageFormat: ImagenImageFormat.
  addWatermark: 
};

const
  model: 
  generationConfig,
  safetySettings: {
    safetyFilterLevel: ImagenSafetyFilterLevel.BLOCK_LOW_AND_ABOVE,
    personFilterLevel: ImagenPersonFilterLevel.ALLOW_ADULT,
  }
});

const

// If fewer images were generated than were requested,
// then filteredReason will describe the reason they were filtered out
if
  console.
}

Current limitations

While this release brings significant power to your client-side code, some advanced Imagen 3 features are not yet supported:

  • Image editing: features like upscaling are not available.
  • Including images as input: not supported on the client SDK.
  • Generating using a predefined style: not available.

Production Web Architecture & Security Checklist

Whether we are deploying on Firebase App Hosting, Cloudflare Workers, or Vercel, shipping AI features to production requires defense-in-depth across three layers:

  • Enforce Firebase App Check & Attestation: Protect your web endpoints, Cloud Functions, Data Connect GraphQL resolvers, and Firebase AI Logic calls against unauthorized replay or billing abuse using Firebase App Check with reCAPTCHA Enterprise.
  • Validate Locally with the Firebase Emulator Suite: Run deterministic integration tests against local Firestore, Auth, Functions, and Data Connect PostgreSQL emulators before promoting schema or rule changes to production.
  • Keep Server & Client Boundaries Type-Safe: Use the modular Firebase Web SDK and generated TypeScript bindings so SSR frameworks like Next.js, Astro, SvelteKit, and Angular serialize state cleanly without hydration flickers.

Conclusion

Accelerate your full-stack web and AI development by pairing Add image generation to your apps with Imagen 3 with strict Security Rules, Firebase App Check, and local emulator testing. Come tell us on X (@CodingCatDev) and LinkedIn (CodingCat.dev) how you are using Firebase in your stack, and subscribe to the CodingCat.dev YouTube Channel so you don't miss what we build next!

Watch Our Related Firebase Video Tutorial on YouTube

Want to see how we architect and debug Firebase web applications live? Watch our related CodingCat.dev session Firebase SQL with Data Connect below, and make sure to Subscribe to CodingCat.dev on YouTube for weekly full-stack web and AI deep dives:

Resources, Official Docs & Related CodingCat.dev Guides

Frequently Asked Questions (FAQ)

What are the key capabilities introduced in Add image generation to your apps with Imagen 3?

Add image generation to your apps with Imagen 3 (announced 2025-03-03 by the Firebase team) enhances the platform for Firebase, Google Cloud, Web Dev, AI, TypeScript, Serverless workloads. Update: As of May 2025, Vertex AI in Firebase has evolved into an offering named Firebase AI Logic to give developers more options for easily integrating generative AI models into their apps. Check out the documentation to learn more. Developers can review the primary announcement on the Firebase Blog alongside our implementation patterns and production checklist above.

How do web developers use Add image generation to your apps with Imagen 3 with Next.js, SvelteKit, React, or Angular?

Web developers can integrate these features using the modular Firebase JavaScript/TypeScript SDK, Firebase Data Connect web bindings, and Firebase App Hosting. Always pair client-side SDK initialization with Firebase App Check and strict Security Rules, and test locally with the Firebase Local Emulator Suite before deploying.

Where can I watch video tutorials on Firebase Web and AI development?

You can watch our hands-on Firebase video walkthroughs on the CodingCat.dev YouTube Channel, including Firebase SQL with Data Connect, and follow us on X (@CodingCatDev) for weekly full-stack tutorials.