The costs (called a "premium") for this are usually charged monthly, depending on the balance owed, and depending on the usage of the loan or line, could almost double the cost of it (on the opposite spectrum clever usage could avoid having to pay almost any premium at all).
The sale of credit insurance is controversial because it is almost always cheaper for an individual to forgo credit insurance, and instead have a term life insurance to cover the credit balance.
In addition, there is a even more very contraversial practice (called single premium credit insurance), usually associated with the sub prime lending industry, of charging the premium only one time at the begining of the loan. For example, charging 5000 dollars at the time of a mortgage refinance, which is usually financed (added to the total loan amount) as part of the loan. This is considered very bad by critics, since doing this is only cheaper if one is sure that one is going to stay with the loan forever and not refinance. Critics contend most people do not realize this and lose money by refininaning once again, thereby loosing the benifits of the credit insurance.