Black magic is a good term for it. If you've ever worked in a restaurant or pub and seen what goes into making a tap system work, it can be quite a project.
The simple answer:
Just enough to push the beer out of the keg at a nice pace, but not much more

If you're just tapping it off a short line, that'll work usually if it's properly carbonated.
A couple more thoughts:
1) Temperature is everything. If the beer warms up between the fridge/keg and the tap, it will releas CO2, which causes foaming. A real professional setup keeps the beer cold from keg to tap. Homebrewers just do their best with this in mind
2) Sometimes foaming can be caused by too little pressure. It's always intuitive to turn down the pressure when you see foam, but if the beer is pouring very slowly and foaming in the line, you probably need to turn up the pressure so that the beer stay carbonated in the lines.
3) Get beer line for hose.
And after all that, it's still black magic. Hose length, head pressure, keg pressure, temperature etc, etc play into it. But, it's a fun project no matter how well it's working. "Hmm...well, let's see if it's working better now....Nope...let's just try pouring another beer after I adjust this..." You get the idea
Janx