exception 429 too many requests for Azure Cost Management API

Anil Guliyaan 55 Reputation points
2023-08-03T11:41:02.0166667+00:00

While fetching cost details using Azure Cost Management API

I am getting error “429 too many requests”

 I have also implemented the following solution suggested by Azure community: 

“retry after waiting for the time specified in the x-ms-ratelimit-microsoft.consumption-retry-after header”

I have implemented the logic to try 3 times with waiting and retry after time (given in subsequent response header)

But still post retry getting following exception logs from different tenant/subscriptions :

Error:Too Many Requests || Statuscode 429

HeadersPragma: no-cache  session-id: e39f5aab-651d-4116-8e27-a2459f3565c5 

x-ms-request-id: 5e3707a8-405c-416e-9173-61df08ce45b0 

x-ms-ratelimit-remaining-microsoft.costmanagement-entity-requests: DefaultQuota:3 

x-ms-ratelimit-remaining-microsoft.costmanagement-tenant-requests: DefaultQuota:19 

x-ms-ratelimit-microsoft.costmanagement-clienttype-retry-after: 58 

x-ms-ratelimit-remaining-microsoft.costmanagement-clienttype-requests: DefaultQuota:0 

 

Error:Too Many Requests || Statuscode 429

HeadersPragma: no-cache  session-id: d482db0f-72e9-4c68-888e-dd80cbffdd8f 

x-ms-request-id: ac3fc7c8-f922-46fd-8d22-5cfb44cd2449 

x-ms-ratelimit-remaining-microsoft.costmanagement-entity-requests: DefaultQuota:2 

x-ms-ratelimit-remaining-microsoft.costmanagement-tenant-requests: DefaultQuota:18 

x-ms-ratelimit-microsoft.costmanagement-clienttype-retry-after: 58 

x-ms-ratelimit-remaining-microsoft.costmanagement-clienttype-requests: DefaultQuota:0 

 

Error:Too Many Requests || Statuscode 429

HeadersPragma: no-cache  session-id: c56fa2d3-3260-4828-bcde-6e0ca514bddb 

x-ms-request-id: df13ad6f-e6c8-4376-a5c7-a911f0c622ff 

x-ms-ratelimit-microsoft.costmanagement-entity-retry-after: 46 

x-ms-ratelimit-remaining-microsoft.costmanagement-entity-requests: DefaultQuota:0 

x-ms-ratelimit-remaining-microsoft.costmanagement-tenant-requests: DefaultQuota:14 

x-ms-ratelimit-microsoft.costmanagement-clienttype-retry-after: 58 

x-ms-ratelimit-remaining-microsoft.costmanagement-clienttype-requests: DefaultQuota:0 

Please suggest a solution

Azure Cost Management
Azure Cost Management
A Microsoft offering that enables tracking of cloud usage and expenditures for Azure and other cloud providers.
3,612 questions
{count} vote

Accepted answer
  1. SadiqhAhmed-MSFT 49,331 Reputation points Microsoft Employee Moderator
    2023-08-03T17:05:51.2366667+00:00

    Hello @Anil Guliyaan Thank you for contacting us on Microsoft Q&A platform. Happy to help!

    If the APIs in the below discussion are Query or Forecast, we have been seeing an increase in customers abusing the shared capacity and by that impacting the experience of other customers. Due to that, we revisited our rate limiting.

    Here are the response headers that you should look for in case of a 429 response. They will tell you how long to wait before making the next call.

    x-ms-ratelimit-microsoft.costmanagement-qpu-retry-after

    x-ms-ratelimit-microsoft.costmanagement-entity-retry-after

    x-ms-ratelimit-microsoft.costmanagement-tenant-retry-after

    x-ms-ratelimit-microsoft.costmanagement-client-retry-after

    The rate limits are not specific to a user – and limits are shared with other callers/users in the tenant/account. We can recommend the right APIs if we understand what you are trying to achieve.

    Receiving a 429 usually means that we had to protect our service from the caller. Of course, every case can have some recommendations (different calling patterns, different API to use, etc).

    I looked at the calling pattern for the tenant id “02cf-f8-48-20-a**b20****5b”, you are not making a lot of calls. You are being rate limited by our ClientType filter (which allows 2000 calls per minute per ClientType). And since you are not providing a ClientType in the request headers, you will share the number with ALL customers that don’t provide a ClientType. 

    In short, can you please provide a clientType value when making an api call.

    Example:

    “ClientType” : “AwesomeType” 

    PS: Please choose one type value for all your calls, that will help us investigate any issue you face in the future.

    Hope this helps. Please write back if you need any further assistance!


    If the response helped, do "Accept Answer" and up-vote it

    3 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Broeder, drs. N. den (Nico) DOMC 5 Reputation points
    2024-02-23T10:41:26.0233333+00:00

    Same result as @Sahaj Khandelwal Adding this header solved the issue: X-Ms-Command-Name: CostAnalysis Adding the ClientType header does not make any difference.


Your answer

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