com.google.firebase.ai.type

Interfaces

LiveServerMessage

Parent interface for responses from the model during live interactions.

Part

Interface representing data sent to and received from requests.

Classes

AspectRatio

Represents the aspect ratio that the generated image should conform to.

AudioTranscriptionConfig

The audio transcription configuration.

AutoFunctionDeclaration

Defines a function that the model can use as a tool.

BlockReason

Describes why content was blocked.

Candidate

A Candidate represents a single response generated by the model for a given request.

Citation

Represents a citation of content from an external source within the model's output.

CitationMetadata

A collection of source attributions for a piece of content.

CodeExecutionResultPart

Represents the code execution result from the model.

Content

Represents content sent to and received from the model.

Content.Builder

Builder class to facilitate constructing complex Content objects.

ContentModality

Content part modality.

ContextWindowCompressionConfig

Enables context window compression to manage the model's context window.

CountTokensResponse

The model's response to a count tokens request.

Dimensions

Represents the dimensions of an image in pixels

ExecutableCodePart

Represents the code that was executed by the model.

FileDataPart

Represents file data stored in Cloud Storage for Firebase, referenced by URI.

FinishReason

Represents the reason why the model stopped generating content.

FunctionCallPart

Represents function call name and params received from requests.

FunctionCallingConfig

The configuration that specifies the function calling behavior.

FunctionDeclaration

Defines a function that the model can use as a tool.

FunctionResponsePart

Represents function call output to be returned to the model when it requests a function call.

GenerateContentResponse

A response from the model.

GenerateObjectResponse

A GenerateContentResponse augmented with class information.

GenerationConfig

Configuration parameters to use for content generation.

GenerationConfig.Builder

Builder for creating a GenerationConfig.

GenerativeBackend

Represents a reference to a backend for generative AI.

GoogleMaps

A tool that allows a Gemini model to connect to Google Maps to access and incorporate location-based information into its responses.

GoogleMapsGroundingChunk

A grounding chunk from Google Maps.

GoogleSearch

A tool that allows the generative model to connect to Google Search to access and incorporate up-to-date information from the web into its responses.

GroundingAttribution

This class is deprecated. Use GroundingChunk instead

GroundingChunk

Represents a chunk of retrieved data that supports a claim in the model's response.

GroundingMetadata

Metadata returned to the client when grounding is enabled.

GroundingSupport

Provides information about how a specific segment of the model's response is supported by the retrieved grounding chunks.

HarmBlockMethod

Specifies how the block method computes the score that will be compared against the HarmBlockThreshold in SafetySetting.

HarmBlockThreshold

Represents the threshold for a HarmCategory to be allowed by SafetySetting.

HarmCategory

Category for a given harm rating.

HarmProbability

Represents the probability that some HarmCategory is applicable in a SafetyRating.

HarmSeverity

Represents the severity of a HarmCategory being applicable in a SafetyRating.

ImageConfig

Configuration options for generating images with Gemini models.

ImageConfig.Builder

Builder for creating a ImageConfig.

ImagePart

Represents image data sent to and received from requests.

ImageSize

The size of images to generate.

ImagenAspectRatio

This class is deprecated. All Imagen models are deprecated.

ImagenBackgroundMask

This class is deprecated. All Imagen models are deprecated.

ImagenControlReference

This class is deprecated. All Imagen models are deprecated.

ImagenControlType

This class is deprecated. All Imagen models are deprecated.

ImagenEditMode

This class is deprecated. All Imagen models are deprecated.

ImagenEditingConfig

This class is deprecated. All Imagen models are deprecated.

ImagenForegroundMask

This class is deprecated. All Imagen models are deprecated.

ImagenGenerationConfig

This class is deprecated. All Imagen models are deprecated.

ImagenGenerationConfig.Builder

This class is deprecated. All Imagen models are deprecated.

ImagenGenerationResponse

This class is deprecated. All Imagen models are deprecated.

ImagenImageFormat

This class is deprecated. All Imagen models are deprecated.

ImagenImagePlacement

This class is deprecated. All Imagen models are deprecated.

ImagenInlineImage

This class is deprecated. All Imagen models are deprecated.

ImagenMaskReference

This class is deprecated. All Imagen models are deprecated.

ImagenPersonFilterLevel

This class is deprecated. All Imagen models are deprecated.

ImagenRawImage

This class is deprecated. All Imagen models are deprecated.

ImagenRawMask

This class is deprecated. All Imagen models are deprecated.

ImagenReferenceImage

This class is deprecated. All Imagen models are deprecated.

ImagenSafetyFilterLevel

This class is deprecated. All Imagen models are deprecated.

ImagenSafetySettings

A configuration for filtering unsafe content or images containing people.

ImagenSemanticMask

This class is deprecated. All Imagen models are deprecated.

ImagenStyleReference

This class is deprecated. All Imagen models are deprecated.

ImagenSubjectReference

This class is deprecated. All Imagen models are deprecated.

ImagenSubjectReferenceType

This class is deprecated. All Imagen models are deprecated.

InlineData

Represents binary data with an associated MIME type.

InlineDataPart

Represents binary data with an associated MIME type sent to and received from requests.

JsonSchema

Definition of a data type.

LatLng

An object that represents a latitude/longitude pair.

LiveAudioConversationConfig

Configuration parameters to use for conversation config.

LiveAudioConversationConfig.Builder

Builder for creating a LiveAudioConversationConfig.

LiveGenerationConfig

Configuration parameters to use for live content generation.

LiveGenerationConfig.Builder

Builder for creating a LiveGenerationConfig.

LiveServerContent

Incremental server update generated by the model in response to client messages.

LiveServerGoAway

Notification that the server is initiating a disconnect of the session.

LiveServerSetupComplete

The model is ready to receive client messages.

LiveServerToolCall

Request for the client to execute the provided functionCalls.

LiveServerToolCallCancellation

Notification for the client to cancel a previous function call from LiveServerToolCall.

LiveServerUnknownMessage
LiveSession

Represents a live WebSocket session capable of streaming content to and from the server.

LiveSessionResumptionUpdate

An update of the session resumption state.

MediaData

This class is deprecated. Use `InlineData` instead

ModalityTokenCount

Represents token counting info for a single modality.

PromptFeedback

Feedback on the prompt provided in the request.

RequestOptions

Configurable options unique to how requests to the backend are performed.

ResponseModality

Represents the type of content present in a response (for example, text, image, audio).

RetrievalConfig

The configuration that specifies information which can be used by tools during inference calls.

RetrievalConfig.Builder

Builder for creating a RetrievalConfig.

SafetyRating

An assessment of the potential harm of some generated content.

SafetySetting

A configuration for a HarmBlockThreshold of some HarmCategory allowed and blocked in responses.

Schema

Definition of a data type.

SearchEntryPoint

Represents a Google Search entry point.

Segment

Represents a specific segment within a Content object, often used to pinpoint the exact location of text or data that grounding information refers to.

SessionResumptionConfig

Configuration for the session resumption mechanism.

SlidingWindow

Configures the sliding window context compression mechanism.

SpeechConfig

Speech configuration class for setting up the voice of the server's response.

StringFormat
StringFormat.Custom
TemplateAutoFunctionDeclaration

A function declaration for a template tool that can be called by the model automatically.

TemplateFunctionDeclaration

A function declaration for a template tool.

TemplateTool

Contains a set of tools (like function declarations) that the server template model has access to.

TemplateToolConfig

Config for template tools to use with server prompts.

TextPart

Represents text or string based data sent to and received from requests.

ThinkingConfig

Gemini 2.5 series models and newer utilize a thinking process before generating a response.

ThinkingConfig.Builder
ThinkingLevel

Specifies the quality of the thinking response.

Tool

Contains a set of tools (like function declarations) that the model has access to.

ToolConfig

Contains configuration for the function calling tools of the model.

Transcription

Audio transcription message.

UrlContext

Specifies the URL context configuration.

UrlContextMetadata

Metadata related to the UrlContext tool.

UrlMetadata

Metadata for a single URL retrieved by the UrlContext tool.

UrlRetrievalStatus

The status of a URL retrieval.

UsageMetadata

Usage metadata about response(s).

Voice

Various voices supported by the server.

Voices

This class is deprecated. Use the Voice class instead.

WebGroundingChunk

A grounding chunk from the web.

Exceptions

APINotConfiguredException

The Firebase project has not been configured and enabled for the selected API.

AudioRecordInitializationFailedException

Audio record initialization failures for audio streaming

ContentBlockedException
FirebaseAIException

Parent class for any errors that occur from the FirebaseAI SDK.

FirebaseAIOnDeviceInvalidRequestException

The parameters used in the request are not valid.

FirebaseAIOnDeviceNotAvailableException

An operation has been requested, but device doesn't support local models, or they are not available.

FirebaseAIOnDeviceUnknownException

Catch all case for exceptions not explicitly expected.

FirebaseAutoFunctionException

Thrown when a function invoked by the model has an error that should be returned to the model

InvalidAPIKeyException

The provided API Key is not valid.

InvalidLocationException

The specified Vertex AI location is invalid.

InvalidStateException

Some form of state occurred that shouldn't have.

PermissionMissingException

The request is missing a permission that is required to perform the requested operation.

PromptBlockedException

A request was blocked.

QuotaExceededException

The request has hit a quota limit.

RequestTimeoutException

A request took too long to complete.

ResponseStoppedException

A request was stopped during generation for some reason.

SerializationException

Something went wrong while trying to deserialize a response from the server.

ServerException

The server responded with a non 200 response code.

ServiceConnectionHandshakeFailedException

Handshake failed with the server

ServiceDisabledException

The service is not enabled for this Firebase project.

SessionAlreadyReceivingException

Streaming session already receiving.

UnknownException

Catch all case for exceptions not explicitly expected.

UnsupportedUserLocationException

The user's location (region) is not supported by the API.

Annotations

Top-level functions summary

Content
content(role: String?, init: Content.Builder.() -> Unit)

Function to build a new Content instances in a DSL-like manner.

GenerationConfig

Helper method to construct a GenerationConfig in a DSL-like manner.

ImageConfig

Helper method to construct an ImageConfig in a DSL-like manner.

ImagenGenerationConfig

This function is deprecated. All Imagen models are deprecated.

LiveAudioConversationConfig

Helper method to construct a LiveAudioConversationConfig in a DSL-like manner.

LiveGenerationConfig

Helper method to construct a LiveGenerationConfig in a DSL-like manner.

RetrievalConfig

Helper method to construct a RetrievalConfig in a DSL-like manner.

ThinkingConfig

Helper method to construct a ThinkingConfig in a DSL-like manner.

Extension functions summary

FileDataPart?

Returns the part as a FileDataPart if it represents a file, and null otherwise

Bitmap?

Returns the part as a Bitmap if it represents an image, and null otherwise

InlineDataPart?

Returns the part as a InlineDataPart if it represents inline data, and null otherwise

String?

Returns the part as a String if it represents text, and null otherwise

ImagenInlineImage

This function is deprecated. All Imagen models are deprecated.

Top-level functions

content

fun content(role: String? = "user", init: Content.Builder.() -> Unit): Content

Function to build a new Content instances in a DSL-like manner.

Contains a collection of text, image, and binary parts.

Example usage:

content("user") {
text("Example string")
)

generationConfig

fun generationConfig(init: GenerationConfig.Builder.() -> Unit): GenerationConfig

Helper method to construct a GenerationConfig in a DSL-like manner.

Example Usage:

generationConfig {
temperature = 0.75f
topP = 0.5f
topK = 30
candidateCount = 4
maxOutputTokens = 300
stopSequences = listOf("in conclusion", "-----", "do you need")
}

imageConfig

fun imageConfig(init: ImageConfig.Builder.() -> Unit): ImageConfig

Helper method to construct an ImageConfig in a DSL-like manner.

imagenGenerationConfig

fun imagenGenerationConfig(init: ImagenGenerationConfig.Builder.() -> Unit): ImagenGenerationConfig

Helper method to construct a ImagenGenerationConfig in a DSL-like manner.

Example Usage:

imagenGenerationConfig {
negativePrompt = "People, black and white, painting"
numberOfImages = 1
aspectRatio = ImagenAspecRatio.SQUARE_1x1
imageFormat = ImagenImageFormat.png()
addWatermark = false
}

Deprecation Notice: All Imagen models are deprecated and will shut down as early as June 2026. As a replacement, you can migrate your apps to use Gemini Image models (the 'Nano Banana' models)

liveAudioConversationConfig

fun liveAudioConversationConfig(init: LiveAudioConversationConfig.Builder.() -> Unit): LiveAudioConversationConfig

Helper method to construct a LiveAudioConversationConfig in a DSL-like manner.

Example Usage:

liveAudioConversationConfig {
functionCallHandler = ...
initializationHandler = ...
...
}

liveGenerationConfig

fun liveGenerationConfig(init: LiveGenerationConfig.Builder.() -> Unit): LiveGenerationConfig

Helper method to construct a LiveGenerationConfig in a DSL-like manner.

Example Usage:

liveGenerationConfig {
temperature = 0.75f
topP = 0.5f
topK = 30
maxOutputTokens = 300
...
}

retrievalConfig

fun retrievalConfig(init: RetrievalConfig.Builder.() -> Unit): RetrievalConfig

Helper method to construct a RetrievalConfig in a DSL-like manner.

Example Usage:

retrievalConfig {
latLng = aLatLng
languageCode = "en_US"
}

thinkingConfig

fun thinkingConfig(init: ThinkingConfig.Builder.() -> Unit): ThinkingConfig

Helper method to construct a ThinkingConfig in a DSL-like manner.

Example Usage:

thinkingConfig {
thinkingBudget = 0 // disable thinking
}

Extension functions

asFileDataOrNull

fun Part.asFileDataOrNull(): FileDataPart?

Returns the part as a FileDataPart if it represents a file, and null otherwise

asImageOrNull

fun Part.asImageOrNull(): Bitmap?

Returns the part as a Bitmap if it represents an image, and null otherwise

asInlineDataPartOrNull

fun Part.asInlineDataPartOrNull(): InlineDataPart?

Returns the part as a InlineDataPart if it represents inline data, and null otherwise

asTextOrNull

fun Part.asTextOrNull(): String?

Returns the part as a String if it represents text, and null otherwise

toImagenInlineImage

@PublicPreviewAPI
fun Bitmap.toImagenInlineImage(): ImagenInlineImage

Helper method to convert an Android bitmap to an Imagen inline data image.

Deprecation Notice: All Imagen models are deprecated and will shut down as early as June 2026. As a replacement, you can migrate your apps to use Gemini Image models (the 'Nano Banana' models)