Disclaimer: Not a lawyer here.
In a nutshell, it is illegal under federal law and under most, but not all, states' laws to require a new hire employee in any industry to pay for their own training as a condition of hire.
That said, it is perfectly legal for a company to LOAN you money to pay for training costs, and then recoup all or part of that money should you leave them before the specified contract length. It is, in fact, a de fecto training contract.
Look at the contract you're being offered. Dollars to donuts it's worded as a "loan" to you that you'd be on the hook for repaying.