Agree with schizo, with the addition of "and the community". Avoid fin nippers, aggressive fish, fish that even mildly resemble another betta (no other long, flowing fins), guaramis (they're related and will fight), and really fast active fish that'll stress the betta out. Bettas like things slow and peaceful. A lot of people have success with neon tetras, harlequin rasboras, cory catfish, shrimp may or may not work depending on if the betta has a taste for them, same with snails....but for any of that to work, you need a bigger tank. It also helps to go with a well planted tank, bettas like their privacy and a place to get away from the activity. I'd go with a 10 gallon for a solo betta, a 20 or larger if adding any community fish with him since most other peaceful fish like to be kept in schools so you'd be pushing the bioload on a ten. And always have a backup home for the betta if it turns out to be too aggressive and harasses the other fish or the other fish harass him (even peaceful fish might go after those delectable fins). I've kept my betta in my 46gallon community for a little over a month without issue...but it's a large tank with lots of plants and territories for the different fish species.
*Edit* All that said, it can be hard to find the right betta and the right tankmates if any work at all. It can be very hit and miss. And even with mine in a community tank, he does not socialize with the other fish. He doesn't pay them any attention good or bad...he hangs out in the water lettuce and the hygro, reacts to me when I'm around. But he really doesn't seem to notice the others exist except during feeding time, and then he flares if they get too close to his special pellets. So I don't think they get lonely for other fish. I had a betta once that seemed to be the exception and played tag with my otos sometimes, would race my rainbows...but you don't hear of a lot like him, and he died after catching something from a fish I didn't quarantine long enough. And even he was solitary most of the time, I think he played with them because they were there, but would have been just as happy left alone in a well decorated 10.