The Vertex AI in Firebase SDKs give you access to the Imagen 3 models (via the Imagen API) so that you can generate images from a text prompt. With this capability, you can do things like:
- Generate images from prompts written in natural language
- Generate images in a wide range of formats and styles
- Render text in images
Note that Vertex AI in Firebase doesn't yet support all the features available for the Imagen models. Learn more in Supported capabilities and features later on this page.
Jump to code for text-only input
Before you begin
If you haven't already, complete the getting started guide. This includes setting up your Firebase project, connecting your app to Firebase, adding the SDK, and initializing the Vertex AI service — these are all required tasks before you can send a prompt request to an Imagen model using the Vertex AI in Firebase SDKs.
Note that to generate images using Imagen models:
Make sure that you're using at minimum these Firebase library versions:
iOS+: v11.9.1+ | Android: v16.2.0+ (BoM: v33.10.0+) | Web: v11.4.1+ | Flutter: v1.4.0+ (BoM: v3.8.0+)Initialize an
ImagenModel
(not aGenerativeModel
)Send your prompt in a call to
generateImages()
(not togenerateContent()
orgenerateContentStream()
)
This initialization of an ImagenModel
and use of generateImages()
are shown in the examples on this page.
Models that support this capability
Image generation is supported by the Imagen 3 models. Support for image generation by Gemini 2.0 models is coming soon.
Generate images from text-only input
You can ask an Imagen model to generate images by prompting with text. You can generate one image or multiple images.
Generate one image from text-only input
Make sure that you've completed the Before you begin section of this guide before trying this sample.
You can ask an Imagen model to generate a single image by prompting with text.
Learn how to choose a model and optionally a location appropriate for your use case and app.
Generate multiple images from text-only input
Make sure that you've completed the Before you begin section of this guide before trying this sample.
By default, Imagen 3 models generate only one image per request.
However, you can ask an Imagen model to generate multiple images
per request by providing a generationConfig
during model initialization.
Learn how to choose a model and optionally a location appropriate for your use case and app.
Supported features and requirements
The Imagen 3 models offer many features related to image generation. This section describes what's supported when using the models with Vertex AI in Firebase.
Supported capabilities and features
Vertex AI in Firebase supports these features of Imagen 3 models.
Generating people and faces (given that your Firebase project has approval from Google Cloud)
Generating text within generated images
Adding a watermark to generated images
Configuring image generation parameters, like number of generated images, aspect ratio, and watermarking
Configuring safety settings
Vertex AI in Firebase does not support these advanced features of Imagen 3 models.
Note that most of these features require being on an approved list of users even when using Imagen models server-side.
Image editing or manipulation features, which includes upscaling images
Including images in the request to the model (like for few-shot learning)
Verifying digital watermarks using the SDKs
If you want to verify that an image has a watermark, you can upload the image into Vertex AI Studio using its Media tab.Generating "live images" from text (MP4 generation)
Generating images using a predefined style
Enabling
includeSafetyAttributes
, which means thatsafetyAttributes.categories
andsafetyAttributes.scores
cannot be returnedDisabling prompt enhancement (the
enhancePrompt
parameter), which means that an LLM-based prompt rewriting tool will always automatically add more detail to the provided prompt to deliver higher quality images that better reflect the prompt providedWriting a generated image directly into Google Cloud Storage as part of the response from the model (the
storageUri
parameter). Instead, images are always returned as base64-encoded image bytes in the response.
If you want to upload a generated image to Cloud Storage, you can use Cloud Storage for Firebase.
Specifications and limitations
Limits (per request) | Imagen 3 | Imagen 3 Fast |
---|---|---|
Max number of input tokens | 480 tokens | 480 tokens |
Max number of output images | 4 images | 4 images |
Supported output image resolutions (pixels) |
|
|
What else can you do?
- Start thinking about preparing for production, including setting up Firebase App Check to protect the APIs you use in your app from abuse by unauthorized clients. Also, make sure to review the production checklist.
Learn how to control content generation
- Understand prompt design, including best practices, strategies, and example prompts.
- Configure Imagen model parameters like aspect ratio, person generation, and watermarking.
- Use safety settings to adjust the likelihood of getting responses that may be considered harmful.
Learn more about the supported models
Learn about the models available for various use cases and their quotas and pricing.Give feedback about your experience with Vertex AI in Firebase