Class GoogleGenAiFiles

java.lang.Object
dev.langchain4j.model.google.genai.GoogleGenAiFiles

public final class GoogleGenAiFiles extends Object
Service for uploading and managing media files with Google AI Gemini using the official com.google.genai SDK.

The Gemini models support multimodal inputs including text, images, audio, videos, and documents. Use this API to upload media files when the total request size exceeds 20 MB.

Files are stored for 48 hours and can be referenced in content generation requests using their URI. The API supports up to 20 GB of files per project, with a maximum of 2 GB per individual file.

  • Method Details

    • builder

      public static GoogleGenAiFiles.Builder builder()
    • uploadFile

      public com.google.genai.types.File uploadFile(Path filePath, String displayName)
      Uploads a file to Gemini.

      Note: The Files API lets you store up to 20 GB of files per project, with a per-file maximum size of 2 GB. Files are stored for 48 hours.

      Parameters:
      filePath - path to the file to upload
      displayName - optional display name for the file
    • uploadFile

      public com.google.genai.types.File uploadFile(byte[] fileBytes, String mimeType, String name)
      Uploads a file to Gemini.

      Note: The Files API lets you store up to 20 GB of files per project, with a per-file maximum size of 2 GB. Files are stored for 48 hours.

      Parameters:
      fileBytes - byte array that is the file to be uploaded
      mimeType - mimetype of the file that is being uploaded
      name - optional display name for the file
    • getMetadata

      public com.google.genai.types.File getMetadata(String name)
      Retrieves metadata for a specific uploaded file.
      Parameters:
      name - the name of the file to retrieve metadata for (e.g., "files/abc123")
    • listFiles

      public List<com.google.genai.types.File> listFiles()
      Lists all uploaded files. Returns a list of uploaded files.

      Note: The Files API lets you store up to 20 GB of files per project, with a per-file maximum size of 2 GB. Files are stored for 48 hours.

    • deleteFile

      public void deleteFile(String name)
      Deletes an uploaded file by name.
      Parameters:
      name - the name of the file to delete (e.g., "files/abc123")