You can get pet insurance before surgery, but that doesn’t necessarily mean you should. The condition your pet needs surgery for would be considered a pre-existing condition, which means the surgery would not be covered. Neither would any follow-up care (medication, rehab, etc.) or future recurrences of the condition. Pet insurance covers future injuries and illnesses — the stuff you can’t see coming.
The only pet insurance recommended by The Dodo