Set up usage-based billing
Learn how to charge customers based on their usage of your product or service.
Usage-based billing enables you to charge customers based on their usage of your product or service.
This guide demonstrates how to create a meter, set up pricing and billing, and send meter events to record customer usage. You’ll learn core concepts of a usage-based billing model through a fictional GenAI company called Alpaca AI. Alpaca AI charges their customers 0.04 USD per hundred tokens, and bills them at the end of the month in arrears.
The following diagram shows the core concepts of usage-based billing:
Create a meter
Meters specify how to aggregate meter events over a billing period. Meter events represent the raw actions that customers take in your system. Meters attach to prices and form the basis of what’s billed.
For the Alpaca AI example, meter events are the number of tokens a customer uses in a query. The meter is the sum of tokens over a month.
You can use the Stripe Dashboard or API to create a meter. If you want to use the API with the Stripe CLI to create a meter, learn how to get started with the Stripe CLI.
Create a pricing model
Use the Stripe Dashboard or API to create a pricing model that includes your products and their pricing options. Prices define the unit cost, currency, and billing cycle.
For the Alpaca AI example, you create a product with a metered price of 0.04 USD per hundred units, billed at a monthly interval. You use the meter that you created in the previous step.
Create a customer
Next, create a customer.
Create a subscription
Subscriptions allow you to charge recurring amounts by associating a customer with a specific price.
Use the Stripe Dashboard or API to create a subscription that includes your customer, product, and usage-based price.
For the Alpaca AI example, you create a subscription for the Alpaca AI product, with a metered price of 0.04 USD per unit, billed monthly to John Doe.
Note
You can associate a single metered price with one or more subscriptions.
Send a test meter event
Use meter events to record customer usage for your meter. At the end of the billing period, Stripe bills the reported usage.
You can test your usage-based billing by sending a meter event through the Stripe Dashboard or API. When using the API, specify the customer ID and value for the payload
.
After you send meter events, you can view usage details for your meter on the Meters page in the Dashboard.
Retrieve an upcoming invoice
Retrieve an upcoming invoice to see a preview of a customer’s invoice that includes details such as the meter price and usage quantity.