Azure cost management API returning 429 - Too Many Requests

Sahaj Khandelwal 15 Reputation points
2023-11-21T16:01:42.3166667+00:00

Hi, when making call to azure cost management API, after exactly 5 API calls in quick succession, I start getting 429.
But if I add the header x-ms-command-name with any value, it gives 200 all the time.

My question is, if I am using azure cost management API from azure SDK for java, how can I do this?

Azure Cost Management
Azure Cost Management
A Microsoft offering that enables tracking of cloud usage and expenditures for Azure and other cloud providers.
2,334 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Sahaj Khandelwal 15 Reputation points
    2023-11-30T04:48:20.0033333+00:00

    Got in touch with MSFT premium support.

    I was using the token that I got from the Azure portal (by trapping from network call). With that token and this header, it was working.

    But with the one we generate programmatically, it doesn't work since there is a limit of 4 calls per scope per minute. It was confusing because this limit is not there in Azure portal token, but that's understandable considering Azure won't keep a limit for its own portal.

    1 person found this answer helpful.
    0 comments No comments

  2. AnuragSingh-MSFT 21,241 Reputation points
    2023-11-27T08:28:24.1133333+00:00

    Sahaj Khandelwal, thank you for the reply.

    The configuration of the samples in the mentioned link is done using the steps as mentioned here (root directory) in the same repo, which I believed that you followed - Getting started

    In these steps, CostManagementManager instance is being created using the line below.

    CostManagementManager manager = CostManagementManager
        .authenticate(credential, profile);
    

    Instead of directly creating the manager instance using CostManagementManager.authenticate I would suggest using the

    CostManagementManager.Configurable Class method -> withHttpClient(HttpClient httpClient).

    Using this method, you can create your own HTTP client as mentioned here and use that client for all manager calls. Once you have configured configurable class, you can call the authenticate method on it and you get the manager instance for further use.

    Hope this helps.