Skip to content
Create account
or
Sign in
The Stripe Docs logo
/
Ask AI
Create account
Sign in
Get started
Payments
Finance automation
Platforms and marketplaces
Money management
Developer tools
Get started
Payments
Finance automation
Get started
Payments
Finance automation
Platforms and marketplaces
Money management
Overview
Billing
    Overview
    About 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
    Connect and Billing
    Tax and Billing
    Quotes
    Revenue recovery
    Automations
    Scripts
    Revenue recognition
    Customer management
    Entitlements
    Test your integration
Tax
Reporting
Data
Startup incorporation
HomeFinance automationBillingUsage-based billingChoose a usage-based billing setupUse products and prices

Transform quantities

Transform usage before applying the price.

Copy page

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.

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