Just use
if not API_KEY:
sys.exit("Missing YOUTUBE_API_KEY.")
It will print message to sys.stderr and do system exit with code 1.P.S. exit() is just an alias to sys.exit(), I prefer longer form.