Package com.google.genai
Class Models
java.lang.Object
com.google.genai.Models
Provides methods for interacting with the available GenAI models. Instantiating this class is not
required. After instantiating a
Client
, access methods through
`client.models.methodName(...)` directly.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncomputeTokens
(String model, String text, ComputeTokensConfig config) Computes tokens given a GenAI model and a text string.computeTokens
(String model, List<Content> contents, ComputeTokensConfig config) countTokens
(String model, String text, CountTokensConfig config) Counts tokens given a GenAI model and a text string.countTokens
(String model, List<Content> contents, CountTokensConfig config) editImage
(String model, String prompt, List<ReferenceImage> referenceImages, EditImageConfig config) Edits an image given a GenAI model, a prompt, and a list of reference images.embedContent
(String model, String text, EmbedContentConfig config) Embeds content given a GenAI model and a text string.embedContent
(String model, List<String> texts, EmbedContentConfig config) Embeds content given a GenAI model and a list of text strings.generateContent
(String model, Content content, GenerateContentConfig config) Generates content given a GenAI model and a content object.generateContent
(String model, String text, GenerateContentConfig config) Generates content given a GenAI model and a text string.generateContent
(String model, List<Content> contents, GenerateContentConfig config) Generates content given a GenAI model and a content object.generateContentStream
(String model, Content content, GenerateContentConfig config) Generates content with streaming support given a GenAI model and a content object.generateContentStream
(String model, String text, GenerateContentConfig config) Generates content with streaming support given a GenAI model and a text string.generateContentStream
(String model, List<Content> contents, GenerateContentConfig config) Generates content with streaming support given a GenAI model and a content object.generateImages
(String model, String prompt, GenerateImagesConfig config) Generates images given a GenAI model and a prompt.generateVideos
(String model, String prompt, Image image, GenerateVideosConfig config) Generates videos given a GenAI model, and a prompt or an image.upscaleImage
(String model, Image image, String upscaleFactor, UpscaleImageConfig config) Upscales an image given a GenAI model and an image and an upscale factor.
-
Constructor Details
-
Models
public Models(com.google.genai.ApiClient apiClient)
-
-
Method Details
-
countTokens
public CountTokensResponse countTokens(String model, List<Content> contents, CountTokensConfig config) -
computeTokens
public ComputeTokensResponse computeTokens(String model, List<Content> contents, ComputeTokensConfig config) -
generateVideos
public GenerateVideosOperation generateVideos(String model, String prompt, Image image, GenerateVideosConfig config) Generates videos given a GenAI model, and a prompt or an image.This method is experimental.
- Parameters:
model
- the name of the GenAI model to use for generating videosprompt
- the text prompt for generating the videos. Optional for image to video use cases.image
- the input image for generating the videos. Optional if prompt is provided.config
- aGenerateVideosConfig
instance that specifies the optional configurations- Returns:
- a
GenerateVideosOperation
instance that contains the generated videos.
-
generateContent
public GenerateContentResponse generateContent(String model, List<Content> contents, GenerateContentConfig config) Generates content given a GenAI model and a content object.- Parameters:
model
- the name of the GenAI model to use for generationcontents
- aList<Content>
to send to the generative modelconfig
- aGenerateContentConfig
instance that specifies the optional configurations- Returns:
- a
GenerateContentResponse
instance that contains response contents and other metadata
-
generateContent
public GenerateContentResponse generateContent(String model, Content content, GenerateContentConfig config) Generates content given a GenAI model and a content object.- Parameters:
model
- the name of the GenAI model to use for generationcontent
- aContent
to send to the generative modelconfig
- aGenerateContentConfig
instance that specifies the optional configurations- Returns:
- a
GenerateContentResponse
instance that contains response contents and other metadata
-
generateContent
public GenerateContentResponse generateContent(String model, String text, GenerateContentConfig config) Generates content given a GenAI model and a text string.- Parameters:
model
- the name of the GenAI model to use for generationtext
- the text string to send to the generative modelconfig
- aGenerateContentConfig
instance that specifies the optional configurations- Returns:
- a
GenerateContentResponse
instance that contains response contents and other metadata
-
generateContentStream
public ResponseStream<GenerateContentResponse> generateContentStream(String model, List<Content> contents, GenerateContentConfig config) Generates content with streaming support given a GenAI model and a content object.- Parameters:
model
- the name of the GenAI model to use for generationcontents
- aList<Content>
to send to the generative modelconfig
- aGenerateContentConfig
instance that specifies the optional configurations- Returns:
- a
GenerateContentResponse
instance that contains response contents and other metadata
-
generateContentStream
public ResponseStream<GenerateContentResponse> generateContentStream(String model, Content content, GenerateContentConfig config) Generates content with streaming support given a GenAI model and a content object.- Parameters:
model
- the name of the GenAI model to use for generationcontent
- aContent
to send to the generative modelconfig
- aGenerateContentConfig
instance that specifies the optional configurations- Returns:
- a
GenerateContentResponse
instance that contains response contents and other metadata
-
generateContentStream
public ResponseStream<GenerateContentResponse> generateContentStream(String model, String text, GenerateContentConfig config) Generates content with streaming support given a GenAI model and a text string.- Parameters:
model
- the name of the GenAI model to use for generationtext
- the text string to send to the generative modelconfig
- aGenerateContentConfig
instance that specifies the optional configurations- Returns:
- a
GenerateContentResponse
instance that contains response contents and other metadata
-
countTokens
Counts tokens given a GenAI model and a text string.- Parameters:
model
- the name of the GenAI model to use.text
- the text string to send to count tokens for.config
- aCountTokensConfig
instance that specifies the optional configurations- Returns:
- a
CountTokensResponse
instance that contains tokens count.
-
computeTokens
Computes tokens given a GenAI model and a text string.- Parameters:
model
- the name of the GenAI model to use.text
- the text string to send to compute tokens for.config
- aComputeTokensConfig
instance that specifies the optional configurations- Returns:
- a
ComputeTokensResponse
instance that contains tokens results.
-
generateImages
public GenerateImagesResponse generateImages(String model, String prompt, GenerateImagesConfig config) Generates images given a GenAI model and a prompt.- Parameters:
model
- the name of the GenAI model to use for generating imagesprompt
- the prompt to generate imagesconfig
- aGenerateImagesConfig
instance that specifies the optional configurations- Returns:
- a
GenerateImagesResponse
instance that contains the generated images.
-
editImage
public EditImageResponse editImage(String model, String prompt, List<ReferenceImage> referenceImages, EditImageConfig config) Edits an image given a GenAI model, a prompt, and a list of reference images.- Parameters:
model
- the name of the GenAI model to use for editing capabilitiesprompt
- the prompt to edit the imagereferenceImages
- aList<ReferenceImage>
to send to use for editing. The 5 types of reference images are:RawReferenceImage
,MaskReferenceImage
,ControlReferenceImage
,StyleReferenceImage
,SubjectReferenceImage
,config
- aEditImageConfig
instance that specifies the optional configurations- Returns:
- a
EditImageResponse
instance that contains the edited image.
-
upscaleImage
public UpscaleImageResponse upscaleImage(String model, Image image, String upscaleFactor, UpscaleImageConfig config) Upscales an image given a GenAI model and an image and an upscale factor.- Parameters:
model
- the name of the GenAI model to use for upscalingimage
- aImage
to send to the generative modelupscaleFactor
- the factor to upscale the imageconfig
- aUpscaleImageConfig
instance that specifies the optional configurations- Returns:
- a
UpscaleImageResponse
instance that contains the upscaled image.
-
embedContent
Embeds content given a GenAI model and a text string.- Parameters:
model
- the name of the GenAI model to use for embeddingtext
- the text string to send to the embedding model- Returns:
- a
EmbedContentResponse
instance that contains the embedding.
-
embedContent
public EmbedContentResponse embedContent(String model, List<String> texts, EmbedContentConfig config) Embeds content given a GenAI model and a list of text strings.- Parameters:
model
- the name of the GenAI model to use for embeddingtexts
- the list of text strings to send to the embedding model- Returns:
- a
EmbedContentResponse
instance that contains the embedding.
-