How should I handle an abusive research mentor as an undergrad? The professor I do research with often puts me down for making mistakes and frequently calls me an idiot. I don't know the appropriate way to respond. I cannot just leave, since I still want to go to grad school. But this is severely affecting my mental health, and I have been suicidal recently as a result. I put a lot of effort into trying to be positive and friendly around him, but I'm not sure this has been particularly effective. 

The research I do with him is good in a technical sense; we have some solid results and have published at very good conferences together. He has agreed to write me a good letter of recommendation (but actually hasn't written it yet) and I believe him if only because he seems to care strongly about his reputation among his peers and writing me a poor letter would reflect badly on him. I do not know what to do.
How close are you to graduation? You have basically three paths here:


Stop working with your advisor. Depending on how bad it has gotten, escalating levels of this solution could be trying to get another member of your advisor's group to take over working with you so you have to see him less, to find a new advisor to continue your current work, to take a semester of mental health leave and start over on a new project afterwards, or even to drop out.
Try to make your advisor behave better. You know your advisor best and can better judge what he would be likely to respond to. Maybe if you just told him "Please don't call me an idiot," he would stop. Maybe if you could get the ear of a sympathetic member of your faculty, they could take your advisor aside and tell them to be more gentle. If your university offers counseling, maybe a counselor could help you raise the subject with him and negotiate some rules for how to work together. Maybe you can raise a formal complaint somewhere (dean, ombudsman?). (The last one will probably torpedo your chances of good recommendation letters, but might let you graduate without having to take more abuse.)
Tough it out. If it's only a few more weeks, maybe deciding that you choose to take it just a little bit longer because you think that the rewards (graduation, recommendation letters) are worth it helps you get through it. This also needs a good support network. Talking things through with a therapist or counselor can help distance yourself emotionally from your advisor's comments. Let your friends console you. Seek affirmation from other places: are there any other activities where you are doing well? Classes that you are excelling at? A hobby that produces things you can be proud of?


No matter which option you ultimately choose, I encourage you to at least informally talk to a university counselor and whoever handles complaints to be aware of all your options. For each of the options, what process exists? What are the upsides/downsides? Make a list, and then make a deliberate decision. Sometimes, even just knowing that you could leave and do something else but are actively choosing to stay in your current situation for now because you feel the recommendation letters are worth it makes all the difference.