Class Models

java.lang.Object
com.google.genai.Models

public final class Models extends Object
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 Details

    • Models

      public Models(com.google.genai.ApiClient apiClient)
  • Method Details

    • recontextImage

      public RecontextImageResponse recontextImage(String model, RecontextImageSource source, RecontextImageConfig config)
      Recontextualizes an image.

      There are two types of recontextualization currently supported: 1) Imagen Product Recontext - Generate images of products in new scenes and contexts. 2) Virtual Try-On: Generate images of persons modeling fashion products.

      Parameters:
      model - the name of the GenAI model to use for image recontext
      source - a RecontextImageSource An object containing the source inputs (prompt, personImage, productImages) for image recontext. prompt is optional for product recontext and disallowed for virtual try-on. personImage is required for virtual try-on, disallowed for product recontext. productImages is required for both product recontext and virtual try-on. Only one product image is supported for virtual try-on, and up to 3 product images (different angles of the same product) are supported for product recontext.
      config - a RecontextImageConfig instance that specifies the optional configurations
      Returns:
      a RecontextImageResponse instance that contains the generated images.
    • segmentImage

      public SegmentImageResponse segmentImage(String model, SegmentImageSource source, SegmentImageConfig config)
      Segments an image, creating a mask of a specified area.
      Parameters:
      model - the name of the GenAI model to use for image segmentation
      source - a SegmentImageSource An object containing the source inputs (prompt, image, scribbleImmage) for image segmentation. The prompt is required for prompt mode and semantic mode, disallowed for other modes. scribbleImage is required for the interactive mode, disallowed for other modes.
      config - a SegmentImageConfig instance that specifies the optional configurations
      Returns:
      a SegmentImageResponse instance that contains the generated mask.
    • get

      public Model get(String model, GetModelConfig config)
      Fetches information about a model by name.
    • update

      public Model update(String model, UpdateModelConfig config)
      Updates a tuned model by its name.
      Parameters:
      model - The name of the tuned model to update
      config - A UpdateModelConfig instance that specifies the optional configurations
      Returns:
      A Model instance
    • delete

      public DeleteModelResponse delete(String model, DeleteModelConfig config)
      Fetches information about a model by name.
    • countTokens

      public CountTokensResponse countTokens(String model, List<Content> contents, CountTokensConfig config)
      Counts tokens given a GenAI model and a list of content.
      Parameters:
      model - the name of the GenAI model to use.
      contents - a List<Content> to send to count tokens for.
      config - a CountTokensConfig instance that specifies the optional configurations
      Returns:
      a CountTokensResponse instance that contains tokens count.
    • computeTokens

      public ComputeTokensResponse computeTokens(String model, List<Content> contents, ComputeTokensConfig config)
      Computes tokens given a GenAI model and a list of content.
      Parameters:
      model - the name of the GenAI model to use.
      contents - a List<Content> to send to compute tokens for.
      config - a ComputeTokensConfig instance that specifies the optional configurations
      Returns:
      a ComputeTokensResponse instance that contains tokens results.
    • generateContent

      public GenerateContentResponse generateContent(String model, List<Content> contents, GenerateContentConfig config)
      Generates content given a GenAI model and a list of content.
      Parameters:
      model - the name of the GenAI model to use for generation
      contents - a List<Content> to send to the generative model
      config - a GenerateContentConfig 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 generation
      content - a Content to send to the generative model
      config - a GenerateContentConfig 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 generation
      text - the text string to send to the generative model
      config - a GenerateContentConfig 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 list of content.
      Parameters:
      model - the name of the GenAI model to use for generation
      contents - a List<Content> to send to the generative model
      config - a GenerateContentConfig 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 generation
      content - a Content to send to the generative model
      config - a GenerateContentConfig 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 generation
      text - the text string to send to the generative model
      config - a GenerateContentConfig instance that specifies the optional configurations
      Returns:
      a GenerateContentResponse instance that contains response contents and other metadata
    • countTokens

      public CountTokensResponse countTokens(String model, String text, CountTokensConfig config)
      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 - a CountTokensConfig instance that specifies the optional configurations
      Returns:
      a CountTokensResponse instance that contains tokens count.
    • computeTokens

      public ComputeTokensResponse computeTokens(String model, String text, ComputeTokensConfig config)
      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 - a ComputeTokensConfig 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 images
      prompt - the prompt to generate images
      config - a GenerateImagesConfig 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 capabilities
      prompt - the prompt to edit the image
      referenceImages - a List<ReferenceImage> to send to use for editing. The 6 types of reference images are: RawReferenceImage, MaskReferenceImage, ControlReferenceImage, StyleReferenceImage, SubjectReferenceImage, ContentReferenceImage
      config - a EditImageConfig 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 upscaling
      image - a Image to send to the generative model
      upscaleFactor - the factor to upscale the image
      config - a UpscaleImageConfig instance that specifies the optional configurations
      Returns:
      a UpscaleImageResponse instance that contains the upscaled image.
    • generateVideos

      public GenerateVideosOperation generateVideos(String model, GenerateVideosSource source, GenerateVideosConfig config)
      Generates videos given a GenAI model, and a GenerateVideosSource source.

      This method is experimental.

      Parameters:
      model - the name of the GenAI model to use for generating videos
      source - a GenerateVideosSource that specifies the inputs (prompt, image, and/or video) to generate videos.
      config - a GenerateVideosConfig instance that specifies the optional configurations
      Returns:
      a GenerateVideosOperation instance that contains the generated videos.
    • generateVideos

      public GenerateVideosOperation generateVideos(String model, String prompt, Image image, Video video, GenerateVideosConfig config)
      Generates videos given a GenAI model, and an input (text, image, or video).

      This method is experimental.

      Parameters:
      model - the name of the GenAI model to use for generating videos
      prompt - the text prompt for generating the videos. Optional for image to video and video extension use cases.
      image - the input image for generating the videos. Optional if prompt is provided.
      video - the input video for video extension use cases. Optional if prompt or image is provided.
      config - a GenerateVideosConfig instance that specifies the optional configurations
      Returns:
      a GenerateVideosOperation instance that contains the generated videos.
    • generateVideos

      public GenerateVideosOperation generateVideos(String model, String prompt, Image image, GenerateVideosConfig config)
      Generates videos given a GenAI model, and an input (text, image).

      This method is experimental, and kept for backward compatibility.

      Parameters:
      model - the name of the GenAI model to use for generating videos
      prompt - 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 - a GenerateVideosConfig instance that specifies the optional configurations
      Returns:
      a GenerateVideosOperation instance that contains the generated videos.
    • embedContent

      public EmbedContentResponse embedContent(String model, String text, EmbedContentConfig config)
      Embeds content given a GenAI model and a text string.
      Parameters:
      model - the name of the GenAI model to use for embedding
      text - 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 embedding
      texts - the list of text strings to send to the embedding model
      Returns:
      a EmbedContentResponse instance that contains the embedding.
    • list

      public Pager<Model> list(ListModelsConfig config)
      Makes an API request to list the available models.

      If `queryBase` is set to True in the ListModelsConfig or not set (default), the API will return all available base models. If set to False, it will return all tuned models.

      Parameters:
      config - A ListModelsConfig for configuring the list request.
      Returns:
      A Pager object that contains the list of models. The pager is an iterable and automatically queries the next page once the current page is exhausted.