Set up a pay-as-you-go pricing model
Charge customers based on their usage of your product or service.
Pay-as-you-go pricing is a flexible, scalable model that lets you charge customers in arrears for the usage they accrue. AI businesses, SaaS platforms, and cloud services often use this pricing model.
What you’ll build
This guide describes how to implement pay-as-you-go pricing on Stripe for a fictional company called Hypernian. Hypernian charges their customers the following rates for their LLM models:
| Usage | Fee |
|---|---|
| Token | 0.04 CAD per 100 tokens |
To implement this pricing model, you create a meter, set up pricing and billing, and send meter events to record customer usage using Products and Prices.
Create a meter
Meters specify how to aggregate meter events over a billing period. Meter events represent all actions that customers take in your system (for example, API requests). Meters attach to prices and form the basis of what’s billed.
For the Hypernian 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 configure a meter. To use the API with the Stripe CLI to create a meter, get started with the Stripe CLI.
- On the Meters page, click Create meter.
- In the meter editor:
- For Meter name, enter the name of the meter to display and for organization purposes. For the Hypernian example, enter “Hypernian tokens.”
- For Event name, enter the name to display in meter events when reporting usage to Stripe. For the Hypernian example, enter “hypernian_tokens.”
- Set the Aggregation method in the dropdown:
- For the Hypernian example, select Sum. This will sum the values reported (in this example, number of tokens a customer uses) to determine the usage to bill for.
- Choose Count to bill based on the number of events reported.
- Choose Last to bill based on the last value reported.
- Use the preview pane to set example usage events and verify the aggregation method.
- Click Create meter.
- (Optional) Under Advanced settings, specify the Dimensions that you want to tag your usage data with. To generate granular segment specific alerts, or to granularly price usage based on a combination of attributes, submit your usage data with dimensions that are populated for analytics and reporting. Some example dimensions are LLM model, token type, region, and event type.
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 period.
For the Hypernian 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.
- On the Product catalog page, click Create product.
- On the Add a product page, do the following:
- For Name, enter the name of your product. For the Hypernian example, enter
Hypernian. - (Optional) For Description, add a description that appears in Checkout, in the customer portal and in quotes.
- Select Recurring.
- Under Billing period, select More pricing options.
- For Name, enter the name of your product. For the Hypernian example, enter
- On the Add price page, do the following:
- Under Choose your pricing model, select Usage-based.
- Choose your pricing structure:
- For the Hypernian example, select Per package. Under Price, set the Amount to
0.per04 USD 100units. - Select Per unit to price by number of users, units, or seats.
- Select Per tier to enable tiered pricing and change the unit cost with quantity or usage.
- For the Hypernian example, select Per package. Under Price, set the Amount to
- Under Meter, select the meter you created in step 1. For the Hypernian example, select Hypernian tokens from the dropdown.
- Select the appropriate Billing period. For the Hypernian example, select Monthly.
- Click Next.
- On the Add a product page, click Add product.
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 Hypernian example, you create a subscription for the Hypernian product, with a metered price of 0.04 USD per 100 units, billed monthly to John Doe.
Note
You can associate a single metered price with one or more subscriptions.
When you create a billing_ subscription, Stripe excludes metered line items from the first invoice since no prior usage exists to bill. Stripe creates an invoice only if the subscription is backdated with previously accrued usage or if pending invoice items exist. When you create a billing_ subscription, Stripe generates a zero monetary value invoice line item for each metered subscription item.
- On the Subscriptions page, click Create test subscription.
- On the Create a test subscription page, do the following:
- Under Customer, select the name of your customer. For the Hypernian example, select John Doe.
- Under Product, select your price. For the Hypernian example, select the price under Hypernian.
- (Optional) Modify the subscription details and settings as needed.
- Click Create test subscription.
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.
- On the Meters page, select the meter name. For the Hypernian example, select Hypernian tokens.
- On the meter page, click Add usage > Manually input usage.
- On the Add usage page, do the following:
- Select your customer from the Customer dropdown.
- For Value, enter a sample value. For the Hypernian example, enter
3000. - Click Submit.
Create a preview invoice
Create a preview invoice to see a preview of a customer’s invoice that includes details such as the meter price and usage quantity.
On the Subscriptions page, select a subscription. For the Hypernian example, select the subscription for John Doe.
On the subscription details page, scroll down to the Upcoming invoice section. The preview invoice shows the subscription amount to bill the customer on the specified date.
Click View full invoice to see complete details for the upcoming invoice, including:
- Customer
- Billing method
- Creation date
- Connected subscription
- Subscription details (usage quantity and meter price)
- Amount due
Because Stripe processes meter events asynchronously, upcoming invoices might not immediately reflect recently received meter events.