GenerativeModel

public final classGenerativeModel


This class is deprecated.
The Vertex AI in Firebase SDK (firebase-vertexai) has been replaced with the FirebaseAI SDK (firebase-ai) to accommodate the evolving set of supported features and services.For migration details, see the migration guide: https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk

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

Summary

Public methods

final @NonNullCountTokensResponse

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

final @NonNullCountTokensResponse

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

final @NonNullCountTokensResponse

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

final @NonNullGenerateContentResponse

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

final @NonNullGenerateContentResponse

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

final @NonNullGenerateContentResponse

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

final @NonNullFlow<@NonNullGenerateContentResponse>

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

final @NonNullFlow<@NonNullGenerateContentResponse>

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

final @NonNullFlow<@NonNullGenerateContentResponse>

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

final @NonNullChat

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

Public methods

countTokens

public final @NonNullCountTokensResponse countTokens(@NonNullBitmap prompt)

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

Parameters
@NonNullBitmap prompt

The image given to the model as a prompt.

Returns
@NonNullCountTokensResponse

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

Throws
com.google.firebase.vertexai.type.FirebaseVertexAIException com.google.firebase.vertexai.type.FirebaseVertexAIException

if the request failed.

See also
FirebaseVertexAIException

for types of errors.

countTokens

public final @NonNullCountTokensResponse countTokens(@NonNullContent prompt)

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

Parameters
@NonNullContent prompt

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

Returns
@NonNullCountTokensResponse

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

Throws
com.google.firebase.vertexai.type.FirebaseVertexAIException com.google.firebase.vertexai.type.FirebaseVertexAIException

if the request failed.

See also
FirebaseVertexAIException

for types of errors.

countTokens

public final @NonNullCountTokensResponse countTokens(@NonNullString prompt)

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

Parameters
@NonNullString prompt

The text given to the model as a prompt.

Returns
@NonNullCountTokensResponse

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

Throws
com.google.firebase.vertexai.type.FirebaseVertexAIException com.google.firebase.vertexai.type.FirebaseVertexAIException

if the request failed.

See also
FirebaseVertexAIException

for types of errors.

generateContent

public final @NonNullGenerateContentResponse generateContent(@NonNullBitmap prompt)

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

Parameters
@NonNullBitmap prompt

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

Throws
com.google.firebase.vertexai.type.FirebaseVertexAIException com.google.firebase.vertexai.type.FirebaseVertexAIException

if the request failed.

See also
FirebaseVertexAIException

for types of errors.

generateContent

public final @NonNullGenerateContentResponse generateContent(@NonNullContent prompt)

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

Parameters
@NonNullContent prompt

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

Returns
@NonNullGenerateContentResponse

The content generated by the model.

Throws
com.google.firebase.vertexai.type.FirebaseVertexAIException com.google.firebase.vertexai.type.FirebaseVertexAIException

if the request failed.

See also
FirebaseVertexAIException

for types of errors.

generateContent

public final @NonNullGenerateContentResponse generateContent(@NonNullString prompt)

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

Parameters
@NonNullString prompt

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

Returns
@NonNullGenerateContentResponse

The content generated by the model.

Throws
com.google.firebase.vertexai.type.FirebaseVertexAIException com.google.firebase.vertexai.type.FirebaseVertexAIException

if the request failed.

See also
FirebaseVertexAIException

for types of errors.

generateContentStream

public final @NonNullFlow<@NonNullGenerateContentResponsegenerateContentStream(@NonNullBitmap prompt)

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

Parameters
@NonNullBitmap prompt

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

Returns
@NonNullFlow<@NonNullGenerateContentResponse>

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

Throws
com.google.firebase.vertexai.type.FirebaseVertexAIException com.google.firebase.vertexai.type.FirebaseVertexAIException

if the request failed.

See also
FirebaseVertexAIException

for types of errors.

generateContentStream

public final @NonNullFlow<@NonNullGenerateContentResponsegenerateContentStream(@NonNullContent prompt)

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

Parameters
@NonNullContent prompt

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

Returns
@NonNullFlow<@NonNullGenerateContentResponse>

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

Throws
com.google.firebase.vertexai.type.FirebaseVertexAIException com.google.firebase.vertexai.type.FirebaseVertexAIException

if the request failed.

See also
FirebaseVertexAIException

for types of errors.

generateContentStream

public final @NonNullFlow<@NonNullGenerateContentResponsegenerateContentStream(@NonNullString prompt)

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

Parameters
@NonNullString prompt

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

Returns
@NonNullFlow<@NonNullGenerateContentResponse>

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

Throws
com.google.firebase.vertexai.type.FirebaseVertexAIException com.google.firebase.vertexai.type.FirebaseVertexAIException

if the request failed.

See also
FirebaseVertexAIException

for types of errors.

startChat

public final @NonNullChat startChat(@NonNullList<@NonNullContent> history)

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.