Skip to content
Create account
or
Sign in
The Stripe Docs logo
/
Ask AI
Create account
Sign in
Get started
Payments
Revenue
Platforms and marketplaces
Money management
Developer resources
Overview
Billing
OverviewAbout the Billing APIs
Subscriptions
Invoicing
Usage-based billing
    Choose a usage-based billing setup
      Use products and prices
        Manage billing setup
        Transform quantities
      Use rate cards
    Record usage for billing
    Offer billing credits
    Monitor usage
    Usage-based pricing models
Quotes
Customer management
Billing with other products
Revenue recovery
Automations
Revenue recognition
Test your integration
Tax
Overview
Use Stripe tax
Manage compliance
Reporting
Overview
Select a report
Configure reports
Reports API
Reports for multiple accounts
Revenue recognition
Data
OverviewSchema
Custom reports
Data Pipeline
Data management
HomeRevenueUsage-based billingChoose a usage-based billing setupUse products and prices

Transform quantities

Transform usage before applying the price.

You can use the transform_quantity option to transform usage before applying the price, which you can use when you want pricing on packages of a product instead of individual units. This allows you to divide the reported usage by a specific number and round the result up or down.

Note

Quantity transformation isn’t compatible with tiered pricing.

For example, say you have a car rental service and you want to charge customers for each hour they rent a car. In this case, you report usage as a number of minutes.

Command Line
cURL
curl https://api.stripe.com/v1/products \ -u "
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:"
\ -d name="Car Rental Service"

Create a price for the car rental service product. Charge 10 USD per hour, and round up to charge for a full hour, even if the customer uses only part of the hour.

Command Line
cURL
curl https://api.stripe.com/v1/prices \ -u "
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:"
\ -d nickname="Car Rental Per Hour Rate" \ -d unit_amount=1000 \ -d currency=usd \ -d "recurring[interval]"=month \ -d "recurring[usage_type]"=metered \ -d product={{CAR_RENTAL_SERVICE_PRODUCT_ID}} \ -d "transform_quantity[divide_by]"=60 \ -d "transform_quantity[round]"=up

If a customer rents the car for 150 minutes, that customer is charged 30 USD for 3 hours of rental (2 hours and 30 minutes, rounded up).

Was this page helpful?
YesNo
Need help? Contact Support.
Join our early access program.
Check out our changelog.
Questions? Contact Sales.
LLM? Read llms.txt.
Powered by Markdoc
Related Guides
Usage-based billing overview
How to record usage
Products Used
Billing