Monetization
Report usage with the API
Report usage to Apiable with POST /api/subscriptions/usage on your portal's Platform API endpoint. Send the subscription, a quantity, and the increment action with the new usage only. Stripe bills the metered total at the end of the cycle.
You report usage to Apiable with a POST to /api/subscriptions/usage on your portal's Platform API endpoint. The body names the subscription and carries the quantity of new usage. Apiable records it on the subscription's Stripe meter, and Stripe bills the metered total when the billing cycle closes.
When do you report usage with the API?
When the plan's Bill Processing is Customer - Own Billing Units. Then Apiable does not count usage for you: you count it in your own systems and report it. With Apiable - API Calls, Apiable counts calls from your gateway logs, and a report would add to that count.
Reporting applies to subscriptions on metered prices: Usage-based - Postpaid - Volume Pricing, Usage-based - Postpaid - Graduated Pricing and Flat-fee - Upfront - Plus Overage. See Usage-based billing for how Apiable counts usage from gateway logs.
How do you report usage with the API?
Get an access token, then POST a JSON body to /api/subscriptions/usage on your Platform API endpoint, https://your-portal.api.apiable.io. Send increment with the usage that is new since your last report.
/api/subscriptions/usage - Exchange your Platform API client ID and secret for an access token at
https://developer.apiable.io/api/oauth2/token. - POST the report to
https://your-portal.api.apiable.io/api/subscriptions/usagewithAuthorization: Bearer <token>andContent-Type: application/json. - Read the response. A
200means the usage was recorded.
What goes in the request body?
Identify the subscription with subscriptionId or integrationId, and send a quantity greater than 0. Leave the rest out unless the notes below apply to you.
| Field | Required | Type | What it is |
|---|---|---|---|
subscriptionId | One of the two | String | The Apiable subscription id. |
integrationId | One of the two | String | The id of the subscription's credential on your gateway, for example the API key ID on Amazon API Gateway. Apiable looks the subscription up from it. |
quantity | Yes | Integer | The units of new usage to add. Must be greater than 0. |
action | No | String | Leave it out, or send increment. See increment or set. |
timestamp | No | Integer | Unix seconds. Defaults to the current time. Leave it out and report usage soon after it happens. |
lookupkey | No | String | Needed only for some older subscriptions that carry several prices. Current subscriptions ignore it. |
Should you send increment or set?
Send increment, which is the default, with only the usage that is new since your last report. Do not send set. On subscriptions billed by usage, set does not replace the running total, so it cannot correct or restate a total.
| Your system tracks | What to send |
|---|---|
| Each batch of usage as it happens | increment with the size of the batch. |
| A running total for the period | increment with the difference since your last report. |
What does a request look like?
First get a token, then send the report. This example adds 25 units to one subscription.
curl -X POST "https://developer.apiable.io/api/oauth2/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d grant_type=client_credentials \
-d client_id="$APIABLE_CLIENT_ID" \
-d client_secret="$APIABLE_CLIENT_SECRET"Use the access_token from the response:
curl -X POST "https://your-portal.api.apiable.io/api/subscriptions/usage" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-H "X-API-Version: 2024-09-25" \
-d '{
"subscriptionId": "664f1c2a9b1e4a0012ab34cd",
"quantity": 25,
"action": "increment"
}'The dashboard shows the same call for a subscription on a volume or graduated plan with Customer - Own Billing Units. Open the subscription and choose Show API call example.
What does Apiable do with the report?
Apiable checks the body, finds the subscription, and records the quantity on the subscription's Stripe meter. It returns 200 with a summary of what it recorded. Stripe adds the report to the period's total and bills it when the billing cycle closes.
The response carries subscriptionId, usageReportId, the id Stripe gave the report, and usageData, which echoes the quantity, time and action that were recorded. For volume and graduated plans, the subscription's page in the dashboard shows the running figure as Total reported consumption for the current period.
Troubleshooting
Match the response to the fix.
| What you get | What to do |
|---|---|
401 with "error": "invalid_token" | The Bearer value must be the access_token from the token response. Tokens expire, so request a fresh one. Do not send the client secret itself. |
400 "Quantity must be greater than 0" | Send a positive whole number of units. Skip the report when there is no new usage. |
400 "Either 'subscriptionId' or 'integrationId' must be provided" | Add one of the two fields. |
404 "Could not find subscription with integrationId" | The gateway credential id matches no subscription. Check the id, or send subscriptionId instead. |
400 "Action must be either 'increment' or 'set'" | Send increment, or leave action out. |
400 "Could not meter usage for subscription with id" | The subscription is not billed through Stripe by usage. Check that its plan has a metered price and the subscriber completed checkout. |
| Usage appears twice as high as expected | Check that you send only new usage with increment, and that the plan's Bill Processing is not also counting calls from your gateway logs. |