Imagine the following scenario:
I've built an API and a web application. A user would sign up through the web app, and receive a unique API key. They may then purchase "credits" for their account, which are simply a 1:1 representation of dollars.
When the user performs an API call, they pass in their API key. This key is used to identify the customer, and subtract credits as necessary.
There is an obvious issue here. If the user performs this call from their own server, and the key is kept private, all is well. However, how would I handle customers who do not have their own server? For example, take a user who has published a simple Android app to the Play Store without a server, and wants to integrate my product. The key would have to be kept client side. A malicious user could then deobfuscate the application, and potentially perform unauthorized API calls spending the credits of the owner of the key.
How can this problem be solved? Is there any way to handle this scenario?