Skip to main content
Files are only supported in the Gemini Developer API, not Vertex AI.
The Files API allows you to upload files to use with the Gemini models.

Upload files

Upload a file from your local filesystem:
file1 = client.files.upload(file='2312.11805v3.pdf')
file2 = client.files.upload(file='2403.05530.pdf')

print(file1)
print(file2)
The upload method automatically detects the file type and uploads it to the Gemini API.

Upload response

The upload method returns a File object with the following properties:
  • name - The unique identifier for the file
  • uri - The URI to reference the file in API calls
  • mime_type - The detected MIME type
  • size_bytes - File size in bytes
  • create_time - When the file was uploaded

Get file metadata

Retrieve information about an uploaded file:
file1 = client.files.upload(file='2312.11805v3.pdf')
file_info = client.files.get(name=file1.name)

print(file_info)

Delete files

Remove a file from the Gemini API:
file3 = client.files.upload(file='2312.11805v3.pdf')

client.files.delete(name=file3.name)

Using files with models

Once uploaded, you can reference files in your model requests:
# Upload a PDF
file = client.files.upload(file='document.pdf')

# Use the file in a generate_content call
response = client.models.generate_content(
    model='gemini-2.5-flash',
    contents=[
        types.Part.from_uri(file.uri, file.mime_type),
        'Summarize this document',
    ],
)

print(response.text)

Supported file types

The Files API supports various file types including:
  • PDF documents
  • Images (JPEG, PNG, WebP)
  • Audio files (MP3, WAV)
  • Video files (MP4, MOV)
  • Text files

File storage and lifecycle

  • Files are stored temporarily on Google’s servers
  • Files are automatically deleted after a period of inactivity
  • You should delete files you no longer need to manage storage

Build docs developers (and LLMs) love