Share via

How can I fetch the on-demand cost of a particular services using its subscriptionId?

Prateek Srivastava 0 Reputation points
2026-04-02T06:43:41.57+00:00

I want to fetch the on-demand cost of any particular service using its subscription Id and i don't want to use the pricing API or management API because I've already tried them and they are not useful for me.

Is there any client by which I can fetch the required on-demand cost a service with particular specifications?

Looking forward for the possible solution as early as possible.

Thank You

Azure Managed Applications
Azure Managed Applications

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.


2 answers

Sort by: Most helpful
  1. Siva shunmugam Nadessin 9,625 Reputation points Microsoft External Staff Moderator
    2026-04-03T19:32:48.2566667+00:00

    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

     

     


  2. Q&A Assist
    2026-04-02T06:44:07.8066667+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    There is no dedicated Azure client that can return on-demand cost for a particular service using only the subscriptionId outside of the existing pricing/management APIs.

    Available Java management clients that work with subscription IDs (for example BillingManagementClient, ConsumptionManagementClient, QuotaManagementClient, ServiceFabricManagementClient, and SubscriptionsClient) expose subscription metadata, usage, quota, or specific resource operations, but not a direct "on-demand price for a service with given specs" endpoint.

    For example:

    • ConsumptionManagementClient.getSubscriptionId() and related consumption APIs deal with usage and cost data already incurred, not list/on-demand prices.
    • BillingManagementClient.getSubscriptionId() and UsageAggregation.subscriptionId() expose billing/usage context, not pricing for arbitrary configurations.
    • SubscriptionsClient.get(String subscriptionId) returns subscription details, not pricing.

    To obtain on-demand cost for a specific configuration, the supported approach remains to use Azure pricing and cost/consumption APIs or the portal-based pricing calculators. No alternative client in the provided SDK references exposes a direct on-demand pricing lookup by subscriptionId and service specification.


    References:

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.