Search code examples
apiaxle

Prepaid API credits with ApiAxle


I'm looking to use ApiAxle to offer a prepaid API to my customers. I want to collect payment in a different system, and have that system add credits for API calls to ApiAxle. ApiAxle would then decrement the amount of credits available whenever an API call is made, and return an error if the user is out of credits.

For example, the user would buy 1,000 API calls for $1 in my external system. The external system would make an ApiAxle API call to credit the user's API key with 1,000 calls. When they tried to make their 1,001th call, it would return an error instead of hitting my API endpoint.

Is this possible? If not, is there another free API management platform that could handle this?


Solution

  • I ended up modifying apiaxle-proxy/node_modules/apiaxle-base/app/model/redis/api_limits.js. I added a Quota that is decremented with every API hit, and is set directly in Redis by my billing system. Not ideal, but workable.

    I'm still really surprised this isn't built into ApiAxle. Prepaid APIs aren't that uncommon.