Skip to main content
Deletes a remotely stored file from the Gemini File API.

Method Signature

Parameters

string
required
The file resource name to delete.Format: "files/abc123" or just "abc123"
DeleteFileConfig
Optional configuration for the request.Available options:
  • http_options: Custom HTTP request options

Returns

DeleteFileResponse
A response object confirming the deletion.Contains:
  • sdk_http_response: HTTP response metadata

Examples

Delete File by Name

Delete After Using

Delete with Short Name

Delete Multiple Files

Cleanup Old Files

Async Delete

Delete All Files

Safe Delete with Verification

Batch Delete with Error Handling

Context Manager Pattern

Error Handling

Important Notes

  • Files are automatically deleted after 48 hours
  • Deleting a file that doesn’t exist will raise an error
  • Once deleted, a file cannot be recovered
  • File deletion is immediate and cannot be undone

API Availability

This method is only available in the Gemini API (not Vertex AI).