(I realise this thread is a few months old, but…)
Now is probably not a good time to be buying an older Mac (that is, one more than ~2 years old). As you are probably aware, Apple is now most of the way through transitioning from Intel CPUs to its own ARM based CPUs, and OS support (and possibly other software support) for the remaining Intel Macs out there is likely to tail off quite quickly over around the next couple of years, making your purchase much less good value (this is probably particularly relevant if your reason for purchase is to do Mac or iOS software development).
If you can't afford to save up for a new Mac, possibly your best best is to look for an Apple Silicon refurb model on the Apple refurb store or second-hand. Maybe by next year there will be much more of an Apple Silicon second hard market as early adopters upgrade, and you might be able to get an Apple Silicon Mac at a more reasonable price.
However, to answer your question, any Mac made in the last few years (at least 5 years, I can't remember exactly when this was introduced: search for "MacOS internet recovery" for full details) can reinstall MacOS from the internet via a special boot option (if you have a WiFI connection that you can connect the Mac to). You can then go through the OS setup and create your AppleID, etc. Apple don't bother with licence keys, having the Mac is the licence entitlement (assuming that it hasn't been blocked as stolen, etc).