Set up a credit-based pricing model
Charge customers for pre-purchase credits.
Credits allow you to offer a fixed, monetary amount of usage across your usage-based products. This model works well when you want to give customers upfront predictability while aligning revenue directly to usage. For example, if you sell an API that processes images and cloud storage, a customer might buy 100 USD of credits at the start of the month. They can spend any combination of API usage and cloud storage up to the monetary amount, and pay an overage charge for either service at the end of the month if they exceed 100 USD of usage.
Credits apply indiscriminately across meters. To set specific limits on your various consumption based products,(for example 100 API requests and 3GB’s of storage) use the flat fee and overage model.
What you’ll build
In this guide, build the following subscription for a fictional company called Alpaca.ai, which provides LLM. They charge customers at the following rates:
Credits | Fee |
---|---|
Per user | 10 USD |
Usage | Fee |
---|---|
Input token | 0.03 USD per token |
Output token | 0.05 USD per token |
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 Alpaca AI example, meter events are the number of input and output tokens a customer uses in a query. The meter is the sum of tokens over a month. In this example. you create a meter for each token type.
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.
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 Alpaca AI example, you create two products each with a meter billed at a monthly interval. Use the meter that you created in the previous step.
Create a customer
Next, create a customer.
Grant billing credits to your customer
Use the Stripe Dashboard or API to create a credit grant for your customer.
Billing credits only apply to subscription line items that link to a meter price. The Usage Records API isn’t supported.
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 both the Alpaca AI Input Token and Alpaca AI Output Token products, billed monthly to Jenny Rosen.
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.
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.
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.
Apply billing credits to invoices
After the invoice finalizes, Stripe automatically applies all applicable billing credits. The available balance on the credit grant updates based on the amount of billing credits applied to the invoice.
You can find the amount of billing credits applied to an invoice in the Stripe Dashboard.
- On the Customers page, select the customer name.
- On the customer page, under Invoices, select an invoice.
- On the invoice page, under Subtotal, find the line for Credit grant applied.
Retrieve the available billing credit balance
Use the Stripe Dashboard or API to see the available billing credit balance for a customer. When using the API, retrieve the Credit Balance Summary endpoint.
List transactions for a credit grant
Use the Stripe Dashboard or API to see the transactions for a specific credit grant or customer. When using the API, call the Credit Balance Transaction endpoint.
OptionalRetrieve usage for a custom time period
Use the Meter Event Summary to retrieve total usage for a custom time period. The meter event summary returns a customer’s aggregated usage for a period, based on the aggregation formula defined by the meter.
In the Alpaca AI example, the meter event summary returns the sum of tokens for a specific customer, meter, and time window.
Because Stripe processes meter events asynchronously, meter event summaries might not immediately reflect recently received meter events.