API billing for uploaded data volume

For APIs which imply a significant incoming traffic from customers (e.g. image processing API, file hosting API, etc.), the ability to bill customers for the amount of uploaded data is an absolute must.
Project X Quotas are an extremely powerful mechanism enabling API vendors to account and bill for various items: number of API calls, number of uploaded bytes, number of keywords in a search phrase, number of synthesized characters for Text-To-Speech APIs, etc.
Let’s see how Project X Quotas can be leveraged in order to bill for the amount of uploaded data.
First, let’s add an example endpoint POST /upload-file/ to the API:

We assume that the file content is sent in the request body.
Then, there is a plan “Basic” with no quotas so far:

Let’s add one which will limit the number of uploaded bytes by 1Gb (1bn bytes) per month:

The checkbox “Is hard limit” controls whether overages are allowed. I.e., whether an API user is allowed to overuse the quota.

If the checkbox is unchecked, the customer can upload more data than the quota allows, and the actual per-customer usage (and possible overuse) can be seen on the subscription dashboard.
Now, after adding a quota, Project X allows to specify the way calls to the endpoint affect the quota.
Let’s define, how many quota units are used by a single call to the /upload-file/ endpoint:

By default, each call to an endpoint consumes 1 quota unit, which means the quota limits a number of calls per N seconds/minutes/hours/days/weeks/months/years.
However, for the purpose of the current demo, each call to /upload-file/ should consume as many quota units as bytes in the request body.
Since the field “Quantity used by a single call” accepts a valid JavaScript expression, we can achieve our goal by changing its value as follows:

Now, for each call, the engine will calculate the length of the body and consume the appropriate amount of the quota quantity. Once it’s used up, customer access will be automatically cut until next month.
That’s it. Project X makes it extremely easy to implement a wide variety of subscription plans with no need for integration of any kind.