An Azure service that enables managed service providers, independent software vendors, and enterprise IT teams to deliver turnkey solutions through the Azure Marketplace or service catalog.
Hello Prateek Srivastava,
Thank you for reaching out to the Microsoft Q&A forum.
When investigated we see that you can pull “on-demand” usage and cost details directly from Azure’s Cost Management or Consumption APIs—no need to guess service rates from the Pricing Calculator. Here are two common approaches:
Consumption UsageDetails API (good for Pay-As-You-Go & Visual Studio subscriptions) • Endpoint GET https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.Consumption/usageDetails?api-version=2019-10-01
• Filter by time range and service name/meter category. For example:
$filter=properties/usageStart ge '2023-07-01'
and properties/usageEnd le '2023-07-02'
and properties/meterCategory eq 'Virtual Machines'
• Response items include:
properties.usageQuantity (units consumed)
properties.pretaxCost (cost in USD)
properties.usageStart / usageEnd (timestamps you can group by hour) • Consume page-by-page in your code via the Azure SDK’s ConsumptionManagementClient.
Cost Management Query API (supports EA, MCA, CSP, PAYG; returns hourly/daily aggregates)
• Endpoint POST https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.CostManagement/query?api-version=2021-10-01
• Request body example (hourly granularity, filtered to your service):
{
"type": "Usage",
"timeframe": "Custom",
"timePeriod": { "from": "2023-07-01T00:00:00Z", "to": "2023-07-02T00:00:00Z" },
"dataset": {
"granularity": "Hourly",
"filter": {
"dimensions": {
"name": "ServiceName",
"operator": "In",
"values": [ "Virtual Machines" ]
}
},
"aggregation": {
"totalCost": { "name": "Cost", "function": "Sum" },
"totalUsage": { "name": "UsageQuantity", "function": "Sum" }
}
}
}
• The response table has columns like UsageQuantity and Cost for each hourly slice.
You can implement either in your preferred language by using:
- Azure.CostManagement.CostManagementClient (for Cost Management API)
- Microsoft.Azure.Management.Consumption.ConsumptionManagementClient (for UsageDetails API)
Both will give you usageQuantity + costInUsd so you can sum up hourly data into a monthly total.
Let me know if you need any more details—like code samples in a specific language or details about filtering by meter, dealing with paging, or distinguishing Actual vs Amortized cost.
— References
• Consumption Usage Details API examples https://learn.microsoft.com/azure/cost-management-billing/automate/get-usage-details-legacy-customer#example-consumption-usage-details-api-requests
• Cost Management “Query” API (generateCostDetailsReport) https://learn.microsoft.com/azure/cost-management-billing/manage/review-subscription-billing?wt.mc_id=knowledgesearch_inproduct_azure-cxp-community-insider
• Pricing calculator & general pricing docs https://azure.microsoft.com/pricing/calculator/ https://docs.microsoft.com/azure/billing/billing-understand-your-bill https://docs.microsoft.com/azure/azure-monitor/platform/usage-estimated-costs