Added a function for API calls

I'm a bit unsure if the raise ValueError is appropriate here (Instead of just sys.exit as it was before).
What do you think?

Any better suggested exception to raise? Or handle it differently?
I like raise instead of sys.exit, but I guess the output can confusing to some.