FirebaseAI

classFirebaseAI


Entry point for allFirebase AI functionality.

Summary

Public companion functions

FirebaseAI

TheFirebaseAI instance for the providedFirebaseApp using the Google AI Backend.

FirebaseAI

Returns theFirebaseAI instance for the providedFirebaseApp andbackend.

FirebaseAI
getInstance(
    app: FirebaseApp,
    backend: GenerativeBackend,
    useLimitedUseAppCheckTokens: Boolean
)

Returns theFirebaseAI instance for the providedFirebaseApp andbackend.

Public companion properties

FirebaseAI

TheFirebaseAI instance for the defaultFirebaseApp using the Google AI Backend.

Public functions

GenerativeModel
generativeModel(
    modelName: String,
    generationConfig: GenerationConfig?,
    safetySettings: List<SafetySetting>?,
    tools: List<Tool>?,
    toolConfig: ToolConfig?,
    systemInstruction: Content?,
    requestOptions: RequestOptions
)

Instantiates a newGenerativeModel given the provided parameters.

ImagenModel
imagenModel(
    modelName: String,
    generationConfig: ImagenGenerationConfig?,
    safetySettings: ImagenSafetySettings?,
    requestOptions: RequestOptions
)

Instantiates a newImagenModel given the provided parameters.

LiveGenerativeModel
@PublicPreviewAPI
liveModel(
    modelName: String,
    generationConfig: LiveGenerationConfig?,
    tools: List<Tool>?,
    systemInstruction: Content?,
    requestOptions: RequestOptions
)

Instantiates a newLiveGenerationConfig given the provided parameters.

TemplateGenerativeModel

Instantiates a newTemplateGenerativeModel given the provided parameters.

TemplateImagenModel

Instantiates a newTemplateImagenModel given the provided parameters.

Public companion functions

getInstance

fun getInstance(app: FirebaseApp): FirebaseAI

TheFirebaseAI instance for the providedFirebaseApp using the Google AI Backend.

getInstance

fun getInstance(app: FirebaseApp = Firebase.app, backend: GenerativeBackend): FirebaseAI

Returns theFirebaseAI instance for the providedFirebaseApp andbackend.

Parameters
backend: GenerativeBackend

the backend reference to make generative AI requests to.

getInstance

fun getInstance(
    app: FirebaseApp = Firebase.app,
    backend: GenerativeBackend,
    useLimitedUseAppCheckTokens: Boolean
): FirebaseAI

Returns theFirebaseAI instance for the providedFirebaseApp andbackend.

Parameters
backend: GenerativeBackend

the backend reference to make generative AI requests to.

useLimitedUseAppCheckTokens: Boolean

when sending tokens to the backend, this option enables the usage of App Check's limited-use tokens instead of the standard cached tokens. Learn more aboutlimited-use tokens, including their nuances, when to use them, and best practices for integrating them into your app.

This flag is set tofalse by default.

Public companion properties

instance

val instanceFirebaseAI

TheFirebaseAI instance for the defaultFirebaseApp using the Google AI Backend.

Public functions

generativeModel

fun generativeModel(
    modelName: String,
    generationConfig: GenerationConfig? = null,
    safetySettings: List<SafetySetting>? = null,
    tools: List<Tool>? = null,
    toolConfig: ToolConfig? = null,
    systemInstruction: Content? = null,
    requestOptions: RequestOptions = RequestOptions()
): GenerativeModel

Instantiates a newGenerativeModel given the provided parameters.

Parameters
modelName: String

The name of the model to use. See the documentation for a list ofsupported models.

generationConfig: GenerationConfig? = null

The configuration parameters to use for content generation.

safetySettings: List<SafetySetting>? = null

The safety bounds the model will abide to during content generation.

tools: List<Tool>? = null

A list ofTools the model may use to generate content.

toolConfig: ToolConfig? = null

TheToolConfig that defines how the model handles the tools provided.

systemInstruction: Content? = null

Content instructions that direct the model to behave a certain way. Currently only text content is supported.

requestOptions: RequestOptions = RequestOptions()

Configuration options for sending requests to the backend.

Returns
GenerativeModel

The initializedGenerativeModel instance.

imagenModel

fun imagenModel(
    modelName: String,
    generationConfig: ImagenGenerationConfig? = null,
    safetySettings: ImagenSafetySettings? = null,
    requestOptions: RequestOptions = RequestOptions()
): ImagenModel

Instantiates a newImagenModel given the provided parameters.

Parameters
modelName: String

The name of the model to use. See the documentation for a list ofsupported models.

generationConfig: ImagenGenerationConfig? = null

The configuration parameters to use for image generation.

safetySettings: ImagenSafetySettings? = null

The safety bounds the model will abide by during image generation.

requestOptions: RequestOptions = RequestOptions()

Configuration options for sending requests to the backend.

Returns
ImagenModel

The initializedImagenModel instance.

liveModel

@PublicPreviewAPI
fun liveModel(
    modelName: String,
    generationConfig: LiveGenerationConfig? = null,
    tools: List<Tool>? = null,
    systemInstruction: Content? = null,
    requestOptions: RequestOptions = RequestOptions()
): LiveGenerativeModel

Instantiates a newLiveGenerationConfig given the provided parameters.

Parameters
modelName: String

The name of the model to use. See the documentation for a list ofsupported models.

generationConfig: LiveGenerationConfig? = null

The configuration parameters to use for content generation.

tools: List<Tool>? = null

A list ofTools the model may use to generate content.

systemInstruction: Content? = null

Content instructions that direct the model to behave a certain way. Currently only text content is supported.

requestOptions: RequestOptions = RequestOptions()

Configuration options for sending requests to the backend.

Returns
LiveGenerativeModel

The initializedLiveGenerativeModel instance.

templateGenerativeModel

@PublicPreviewAPI
fun templateGenerativeModel(requestOptions: RequestOptions = RequestOptions()): TemplateGenerativeModel

Instantiates a newTemplateGenerativeModel given the provided parameters.

Parameters
requestOptions: RequestOptions = RequestOptions()

Configuration options for sending requests to the backend.

Returns
TemplateGenerativeModel

The initializedTemplateGenerativeModel instance.

templateImagenModel

@PublicPreviewAPI
fun templateImagenModel(requestOptions: RequestOptions = RequestOptions()): TemplateImagenModel

Instantiates a newTemplateImagenModel given the provided parameters.

Parameters
requestOptions: RequestOptions = RequestOptions()

Configuration options for sending requests to the backend.

Returns
TemplateImagenModel

The initializedTemplateImagenModel instance.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-11-14 UTC.