Skip to main content
DELETE
/
v1
/
files
/
{file_id}
Delete File
curl --request DELETE \
  --url https://api.gravixlayer.com/v1/files/{file_id} \
  --header 'Authorization: Bearer <token>'
Overview The Delete File API permanently removes a file from your Gravix Layer organization. This action cannot be undone, so use with caution. Deleted files are immediately removed from storage and cannot be recovered. Key Features
  • Immediate deletion with instant storage reclaim
  • Cascade handling for dependent operations
  • Confirmation response to verify deletion success
  • Error prevention for files in active use
  • Audit logging for security and compliance
Common Use Cases
Remove unnecessary files to manage storage costs:
# Delete expired or unused files
files = client.files.list()

for file in files.data:
    if should_delete(file):
        client.files.delete(file.id)
        print(f"Deleted {file.filename}")
Path Parameters
ParameterTypeRequiredDescription
file_idstringYesThe ID of the file to delete

Example Request

curl -X DELETE https://api.gravixlayer.com/v1/files/file-abc123 \
  -H "Authorization: Bearer $GRAVIXLAYER_API_KEY"

Response

{
  "id": "file-abc123",
  "object": "file",
  "deleted": true
}

Response Fields

FieldTypeDescription
idstringID of the deleted file
objectstringAlways “file”
deletedbooleantrue if deletion was successful

Error Responses

Status CodeError TypeDescription
404file_not_foundFile with the specified ID does not exist
401authentication_errorInvalid or missing API key
403permission_deniedFile belongs to a different organization
409file_in_useFile is currently being used and cannot be deleted

Use Cases

Delete files older than a certain age:
import time

def cleanup_old_files(max_age_days=30):
    """Delete files older than specified days"""
    current_time = time.time()
    deleted_count = 0
    
    # List all files
    files = client.files.list()
    
    for file in files.data:
        file_age_days = (current_time - file.created_at) / (24 * 60 * 60)
        
        if file_age_days > max_age_days:
            try:
                client.files.delete(file.id)
                print(f"🗑️  Deleted old file: {file.filename} ({file_age_days:.1f} days old)")
                deleted_count += 1
            except Exception as e:
                print(f"❌ Failed to delete {file.filename}: {e}")
    
    print(f"✅ Cleanup complete: {deleted_count} files deleted")

# Delete files older than 30 days
cleanup_old_files(30)

Best Practices

File deletion is permanent and cannot be undone. Always verify file IDs and consider backing up important files before deletion.

Safe Deletion Pattern

def production_safe_delete(file_id):
    """Production-safe file deletion with all checks"""
    
    # 1. Verify file exists and get info
    try:
        file_info = client.files.retrieve(file_id)
    except Exception as e:
        print(f"❌ File not found or accessible: {e}")
        return False
    
    # 2. Check if file might be in use (for certain purposes)
    high_risk_purposes = ["fine-tune", "batch"]
    if file_info.purpose in high_risk_purposes:
        print(f"⚠️  Warning: Deleting {file_info.purpose} file may affect active processes")
    
    # 3. Log the deletion attempt
    print(f"🗑️  Attempting to delete file:")
    print(f"   ID: {file_info.id}")
    print(f"   Name: {file_info.filename}")
    print(f"   Purpose: {file_info.purpose}")
    
    # 4. Perform deletion with error handling
    try:
        result = client.files.delete(file_id)
        
        if result.deleted:
            print(f"✅ File deleted successfully")
            # Log successful deletion
            return True
        else:
            print(f"❌ Deletion returned false")
            return False
            
    except Exception as e:
        print(f"❌ Deletion failed: {e}")
        return False

Authorizations

Authorization
string
header
required

API key authentication. Get your API key from the Gravix Layer Dashboard.

Path Parameters

file_id
string
required

The ID of the file to delete

Response

200

File deleted successfully