Kai is a technique for releasing one from a genjutsu, the user first stops there chakra flow and then quickly releases a large surge of it through there chakra network. This will hopefully regulate his/her chakra flow again removing the influence of the genjutsu. Genjutsu can also be released by another person injecting there chakra in the affected person to achieve the same result. Genjutsu can also be released if the influenced person can cause enough pain to there body. Such as breaking a limb/appendage or biting off there tongue. The pain from this event also serves to re-balance the chakra flow.
Okay. Even though you have an idea of it, I feel the need to add this as well;
Okay, there are several ways to get out of a Genjutsu.
1. Is to temporary stop your chakra flow whereafter letting go off it, making it flow through your body again, like a burst which will overwhelm the opponents chakra. This is called Kai, literally meaning Release, it's the most often used in the Narutoverse. Though people tend to make rules about not using it.
2. Is to transfer pain to yourself as you said yourself. For an instant, let's say you're are put under a genjutsu where... Mhm.. ants are pissing on your legs, lol. You would simply be needed in this sitaution to for an example, stab yourself, whereever you please, lol. Or bite your tonuge(Spelled),though it would be riduclious idiotic as you would die of blood loss then.
3. Is to send bursts of chakra through your body, kinda like the first example(Look above.), the burst would make disruption in your chakra network causing the opponent's chakra to get blown out nd stuff. A Jutsu that can do that is like, Nagashi where you release an electric current throughout your entire body, thus creating disruption and thereby breaking you out of genjutsus.
4. Clones, or allies; Fightning a Genjutsu user it would be most likely smart to have clones or allies within you, where you keep an eye on each and another, being put under a genjutsu can often cause you to not follow up on your movements and thereby your clones nd allies would be alerted. In such sitaution you would be needed to make them transfer chakra into your body by placing their palms on you. Their chakra will go through your chakra network and send the opponent's chakra out of your body.
5. The Sharigan, it's pretty self explantorary, and I'm getting tired of writing this wall of text, so you can catch me via VM later asking if it.
This is basically what explanation I give to all my students, and yes it is copy pasted(From one of my earlier student's thread. <.<), so it may be well, to say old. Some things may have changed, however if in doubt you can VM a sensei or RPmoderator for that sake.