Search code examples
javaazureazure-billing-api

How to get the cost of a project from the usage quantity & meterRates using Azure's usage API?


Using Microsoft Azure's billing and usage API, I see that we can get the usage quantity of a resource for a project and the rate for the resource consumption from the rate card API. However, the rate card API, in some cases, has a list of key-value pairs.

For ex, consider the following MeterRates:

"MeterRates": {
                "0": 0.0832,
                "1024": 0.0819,
                "51200": 0.0806,
                "512000": 0.0794,
                "1024000": 0.0775,
                "5120000": 0.0775
            },

Here, if the usage quantity is, say, 102400; does it mean the cost of using the resource will be 102400 * 0.0784 or (102400 - 1023) * 0.0832 + (102400 - 1023 - 51200) * 0.0819?

N.B.: I have an issue on the github repository for the billing and usage API regarding the same.


Solution

  • Here, if the usage quantity is, say, 102400; does it mean the cost of using the resource will be 102400 * 0.0784 or (102400 - 1023) * 0.0832 + (102400 - 1023 - 51200) * 0.0819?

    It will actually be more like: 1023 * 0.0832 + 50176 * 0.0819 + 460800 * 0.0794 + 512000 * 0.0775

    Essentially these are pricing tiers so the way you read them is from 0 to 1023, it would be 0.0832 / unit. From 1024 - 51200, it would be 0.0819 units and so on.