GenerativeModel

classGenerativeModel


Represents a multimodal model (like Gemini), capable of generating content based on various input types.

Summary

Public functions

suspendCountTokensResponse

Counts the number of tokens in an image prompt using the model's tokenizer.

suspendCountTokensResponse

Counts the number of tokens in a prompt using the model's tokenizer.

suspendCountTokensResponse

Counts the number of tokens in a text prompt using the model's tokenizer.

suspendCountTokensResponse
countTokens(prompt: Content, vararg prompts: Content)

Counts the number of tokens in a prompt using the model's tokenizer.

suspendGenerateContentResponse

Generates new content from the image input given to the model as a prompt.

suspendGenerateContentResponse

Generates new content from the inputContent given to the model as a prompt.

suspendGenerateContentResponse

Generates new content from the text input given to the model as a prompt.

suspendGenerateContentResponse
generateContent(prompt: Content, vararg prompts: Content)

Generates new content from the inputContent given to the model as a prompt.

Flow<GenerateContentResponse>

Generates new content as a stream from the image input given to the model as a prompt.

Flow<GenerateContentResponse>

Generates new content as a stream from the inputContent given to the model as a prompt.

Flow<GenerateContentResponse>

Generates new content as a stream from the text input given to the model as a prompt.

Flow<GenerateContentResponse>
generateContentStream(prompt: Content, vararg prompts: Content)

Generates new content as a stream from the inputContent given to the model as a prompt.

Chat
startChat(history: List<Content>)

Creates aChat instance using this model with the optionally provided history.

Public functions

countTokens

suspend fun countTokens(prompt: Bitmap): CountTokensResponse

Counts the number of tokens in an image prompt using the model's tokenizer.

Parameters
prompt: Bitmap

The image given to the model as a prompt.

Returns
CountTokensResponse

TheCountTokensResponse of running the model's tokenizer on the input.

Throws
com.google.firebase.ai.type.FirebaseAIException: com.google.firebase.ai.type.FirebaseAIException

if the request failed.

See also
FirebaseAIException

for types of errors.

countTokens

suspend fun countTokens(prompt: List<Content>): CountTokensResponse

Counts the number of tokens in a prompt using the model's tokenizer.

Parameters
prompt: List<Content>

The input(s) given to the model as a prompt.

Returns
CountTokensResponse

TheCountTokensResponse of running the model's tokenizer on the input.

Throws
com.google.firebase.ai.type.FirebaseAIException: com.google.firebase.ai.type.FirebaseAIException

if the request failed.

See also
FirebaseAIException

for types of errors.

countTokens

suspend fun countTokens(prompt: String): CountTokensResponse

Counts the number of tokens in a text prompt using the model's tokenizer.

Parameters
prompt: String

The text given to the model as a prompt.

Returns
CountTokensResponse

TheCountTokensResponse of running the model's tokenizer on the input.

Throws
com.google.firebase.ai.type.FirebaseAIException: com.google.firebase.ai.type.FirebaseAIException

if the request failed.

See also
FirebaseAIException

for types of errors.

countTokens

suspend fun countTokens(prompt: Content, vararg prompts: Content): CountTokensResponse

Counts the number of tokens in a prompt using the model's tokenizer.

Parameters
prompt: Content

The input(s) given to the model as a prompt.

Returns
CountTokensResponse

TheCountTokensResponse of running the model's tokenizer on the input.

Throws
com.google.firebase.ai.type.FirebaseAIException: com.google.firebase.ai.type.FirebaseAIException

if the request failed.

See also
FirebaseAIException

for types of errors.

generateContent

suspend fun generateContent(prompt: Bitmap): GenerateContentResponse

Generates new content from the image input given to the model as a prompt.

Parameters
prompt: Bitmap

The image to be converted into a single piece ofContent to send to the model.

Throws
com.google.firebase.ai.type.FirebaseAIException: com.google.firebase.ai.type.FirebaseAIException

if the request failed.

See also
FirebaseAIException

for types of errors.

generateContent

suspend fun generateContent(prompt: List<Content>): GenerateContentResponse

Generates new content from the inputContent given to the model as a prompt.

Parameters
prompt: List<Content>

The input(s) given to the model as a prompt.

Returns
GenerateContentResponse

The content generated by the model.

Throws
com.google.firebase.ai.type.FirebaseAIException: com.google.firebase.ai.type.FirebaseAIException

if the request failed.

See also
FirebaseAIException

for types of errors.

generateContent

suspend fun generateContent(prompt: String): GenerateContentResponse

Generates new content from the text input given to the model as a prompt.

Parameters
prompt: String

The text to be send to the model as a prompt.

Returns
GenerateContentResponse

The content generated by the model.

Throws
com.google.firebase.ai.type.FirebaseAIException: com.google.firebase.ai.type.FirebaseAIException

if the request failed.

See also
FirebaseAIException

for types of errors.

generateContent

suspend fun generateContent(prompt: Content, vararg prompts: Content): GenerateContentResponse

Generates new content from the inputContent given to the model as a prompt.

Parameters
prompt: Content

The input(s) given to the model as a prompt.

Returns
GenerateContentResponse

The content generated by the model.

Throws
com.google.firebase.ai.type.FirebaseAIException: com.google.firebase.ai.type.FirebaseAIException

if the request failed.

See also
FirebaseAIException

for types of errors.

generateContentStream

fun generateContentStream(prompt: Bitmap): Flow<GenerateContentResponse>

Generates new content as a stream from the image input given to the model as a prompt.

Parameters
prompt: Bitmap

The image to be converted into a single piece ofContent to send to the model.

Returns
Flow<GenerateContentResponse>

AFlow which will emit responses as they are returned by the model.

Throws
com.google.firebase.ai.type.FirebaseAIException: com.google.firebase.ai.type.FirebaseAIException

if the request failed.

See also
FirebaseAIException

for types of errors.

generateContentStream

fun generateContentStream(prompt: List<Content>): Flow<GenerateContentResponse>

Generates new content as a stream from the inputContent given to the model as a prompt.

Parameters
prompt: List<Content>

The input(s) given to the model as a prompt.

Returns
Flow<GenerateContentResponse>

AFlow which will emit responses as they are returned by the model.

Throws
com.google.firebase.ai.type.FirebaseAIException: com.google.firebase.ai.type.FirebaseAIException

if the request failed.

See also
FirebaseAIException

for types of errors.

generateContentStream

fun generateContentStream(prompt: String): Flow<GenerateContentResponse>

Generates new content as a stream from the text input given to the model as a prompt.

Parameters
prompt: String

The text to be send to the model as a prompt.

Returns
Flow<GenerateContentResponse>

AFlow which will emit responses as they are returned by the model.

Throws
com.google.firebase.ai.type.FirebaseAIException: com.google.firebase.ai.type.FirebaseAIException

if the request failed.

See also
FirebaseAIException

for types of errors.

generateContentStream

fun generateContentStream(prompt: Content, vararg prompts: Content): Flow<GenerateContentResponse>

Generates new content as a stream from the inputContent given to the model as a prompt.

Parameters
prompt: Content

The input(s) given to the model as a prompt.

Returns
Flow<GenerateContentResponse>

AFlow which will emit responses as they are returned by the model.

Throws
com.google.firebase.ai.type.FirebaseAIException: com.google.firebase.ai.type.FirebaseAIException

if the request failed.

See also
FirebaseAIException

for types of errors.

startChat

fun startChat(history: List<Content> = emptyList()): Chat

Creates aChat instance using this model with the optionally provided history.

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-07-21 UTC.