file_api

Gemini File API client for uploading and managing files.

This module provides a client for Google’s Gemini File API, enabling file uploads, metadata retrieval, listing, and deletion. Files uploaded through this API can be referenced in Gemini generative model calls.

class pipecat.services.google.gemini_live.file_api.GeminiFileAPI(api_key: str, base_url: str = 'https://generativelanguage.googleapis.com/v1beta/files')[source]

Bases: object

Client for the Gemini File API.

This class provides methods for uploading, fetching, listing, and deleting files through Google’s Gemini File API.

Files uploaded through this API remain available for 48 hours and can be referenced in calls to the Gemini generative models. Maximum file size is 2GB, with total project storage limited to 20GB.

__init__(api_key: str, base_url: str = 'https://generativelanguage.googleapis.com/v1beta/files')[source]

Initialize the Gemini File API client.

Parameters:
  • api_key – Google AI API key

  • base_url – Base URL for the Gemini File API (default is the v1beta endpoint)

async upload_file(file_path: str, display_name: str | None = None) dict[str, Any][source]

Upload a file to the Gemini File API using the correct resumable upload protocol.

Parameters:
  • file_path – Path to the file to upload

  • display_name – Optional display name for the file

Returns:

File metadata including uri, name, and display_name

async get_file(name: str) dict[str, Any][source]

Get metadata for a file.

Parameters:

name – File name (or full path)

Returns:

File metadata

async list_files(page_size: int = 10, page_token: str | None = None) dict[str, Any][source]

List uploaded files.

Parameters:
  • page_size – Number of files to return per page

  • page_token – Token for pagination

Returns:

List of files and next page token if available

async delete_file(name: str) bool[source]

Delete a file.

Parameters:

name – File name (or full path)

Returns:

True if deleted successfully