Depending on the age of your iMac you should be able to install your new SSD into your system and then run the Internet restore using the start up keys: '''Command (⌘)''' & '''R''' keys
Reference: [https://support.apple.com/en-us/HT201314|About macOS Recovery]
To gain access to the older macOS’s use the startup keys '''Shift''' & '''Option-⌘''' & '''R''' keys
Reference: [https://support.apple.com/en-us/HT204904|Reinstall from macOS Recovery]