Lidded bins tend to have this problem because they run hotter than traditional heaps and seem to be covered because of the lid. Do not underestimate the value of adding newspaper and card to the bin on a regular basis - every time you add anything else in fact. Often times the layers of dry should be as frequent and slightly thicker than the layers of moist (most stuff).
The top might be just damp but that can often hide that the lower levels are soaked and attracting too many flies or it can be that rotting food is calling them in.
I have seen a lot of bins that the owners swear blind are balanced but are in fact just too wet. This can be a health hazard when blow fly are involved.
If it is too wet
If the bin is too moist you can often tell by the bad smell when you get in close and/or by excessive seepage from the bottom.
Sometimes the issue is drainage - the liquid is not able to escape the bin into the soil below. Maybe the soil is too hard, too much clay and not enough sand or looser material. In which case the bin needs a lot more dry especially lower down.
You can try sprinkling fine (silver) sand into the compost bin or you may need to simply refrain from adding any vegetative or other most/wet in for a few weeks.
Stale bread, card, wax free paper plates, most animal bedding, sawdust, toilet role tubes, pizza boxes, egg cartons, hair... there is a lot of dry that you could be adding but your real issue is that the dry is on top and the damp is at the bottom. I can't really recommend mucking that out with a big spade because... let's just say slime and stink and stop there. The problem is that turning it is the best bet... sorry.
If it is a shady spot bringing it into full sunlight will help. It's better to need to give the pile a drink once a month in the summer than to have it too wet.
A big culprit is grass cuttings laid in too thick (also teabags and kitchen waste piled too high without dry). The grass can seem almost dry but releases a lot of moisture as it breaks down. Try to get a thin layer of grass between to layers of dry. It never hurts to have sand or twigs below grass to let the air in.
If the problem is fruit, black or vinegar flies
If you have a lot of tiny flies these may be vinegar flies in which case then the compost might be about right for moisture but not for containment. These guys look a lot like fruit flies and can be killed off by simply leaving a container of vinegar with a small opening nearby. They will often drown themselves for you. However you need to stop them moving in to start with.
Killing them efficiently does not deal with the problem that attracted too many black flies, fruit flies and vinegar flies to your garden. They have come for the food and one way to stop this is to cover it up. Cover any food or vegetative scraps with a light layer of soil and follow this up with a few inches of brown material (ripped up newspaper, leaves, pencil shavings, plastic free junk mail or straw are all good). Two to four inches should do it.
You should certainly never leave food scraps on the top exposed. This is asking for trouble but most of us have done it. The lid is only going to protect the bin so much. I know of one gentleman who found that his wife had been dumping the peelings into the compost bin and not putting the lid on correctly- when he came back from a week long business trip in mid summer he had a garden full of flies.
If you have been growing and curing tobacco it can make a natural pesticide but if you are growing your own you probably are trying to avoid toxins to start with.