How to retrieve historical monthly allocated quota (the custom quota limit in policy) for previous months?

Ashish Gupta 20 Reputation points
2025-11-20T18:18:00.4833333+00:00

Hi Microsoft Team,

I am working with Azure API Management quotas, and I need to retrieve the custom monthly allocated quota for past months per subscription.

<policies>
    <inbound>
        <base />
        <set-backend-service id="apim-generated-policy" backend-id="dev-backend" />
        <rate-limit-by-key calls="120" renewal-period="60" counter-key="@(context.Subscription?.Key ?? "anonymous")" />
        <choose>
            <when condition="@(context.Subscription?.Name == "SPECIFIC_CUSTOMER'S_SUBSCRIPTION_NAME_HERE")">
                <quota-by-key calls="200000" 
renewal-period="2592000"
 counter-key="@(context.Subscription?.Key ?? "anonymous")" 
first-period-start="2025-08-01T00:00:00Z"
 />
            </when>
            <otherwise>
                <quota-by-key calls="100000" 
renewal-period="2592000"
 counter-key="@(context.Subscription?.Key ?? "anonymous")" 
first-period-start="2025-08-01T00:00:00Z"
 />
            </otherwise>
        </choose>
    </inbound>
    <backend>
        <base />
    </backend>
    <outbound>
        <base />
    </outbound>
    <on-error>
        <base />
    </on-error>
</policies>

What I already know:

  • The API quota-by-counter-keys (/quotaByCounterKeys?api-version=2024-05-01) returns only the current active quota period (based on periodKey, periodStartTime, periodEndTime).

This endpoint does not return quota details for previous months.

  • However, using the reports API (/reports/byRequest or /reports/bySubscription), I can still see historical API request logs from earlier months (e.g., October, September, June), depending on APIM log retention.

My requirement:

For each APIM subscription, I want to know:

  • How many calls were consumed in each past monthly quota cycle, starting from the policy’s first-period-start, (e.g., October, September) month cycle
  • Essentially, I need historic monthly quota counters, not just logs.

Problem:

quota-by-counter-keys only returns:

{  
  "periodStartTime": "2025-10-31T06:00:00Z",
  "periodEndTime": "2025-11-30T16:00:00Z",
  "value": { "callsCount": 5851 }
}

Even though the subscription has been making calls for many previous months.

Questions:

Is there any API or method in Azure API Management to retrieve historic monthly quota usage per subscription (previous quota cycles), or does APIM only store the current cycle’s quota counter?

If Azure APIM does not store past quota cycles:

Is there any recommended approach to reconstruct per-month quota usage reliably?

Or any API to fetch previous quota start/end boundaries?

Thanks in advance!

Azure Policy
Azure Policy
An Azure service that is used to implement corporate governance and standards at scale for Azure resources.
0 comments No comments
{count} votes

Answer accepted by question author
  1. Siva shunmugam Nadessin 3,025 Reputation points Microsoft External Staff Moderator
    2025-11-20T18:53:52.2766667+00:00

    Hello Ashish Gupta,

    No, Azure API Management does not persist historical quota counters. The quota-by-counter-keys API only returns the current active quota period (with periodStartTime, periodEndTime, and callsCount). There is no built-in API to retrieve previous cycles or historic quota counters this is basically because quota counters are designed for real-time enforcement, not historical reporting. APIM analytics and reports are the only source for historical data.

    No direct API exists for historical quota boundaries. The first-period-start attribute in your policy defines the initial cycle start, and subsequent cycles are calculated based on renewal-period. However, APIM does not expose past cycle metadata.

    Recommended approach to reconstruct per-month quota usage

    Since APIM only stores the current cycle, you need to reconstruct historical usage from logs:

    Use the Reports API:

    Endpoints like /reports/bySubscription or /reports/byRequest allow filtering by timestamp to get API call counts for any date range.

    GET https://management.azure.com/subscriptions/{subId}/resourceGroups/{rg}/providers/Microsoft.ApiManagement/service/{serviceName}/reports/bySubscription?$filter=timestamp ge datetime'2025-09-01T00:00:00' and timestamp le datetime'2025-09-30T23:59:59'&api-version=2024-05-01
    

    This returns aggregated metrics like callCountTotal, bandwidth, etc.

    Reference Document:

    Reports - List By Subscription - REST API (Azure API Management) | Microsoft Learn

    Define monthly windows manually:

    • Use your policy’s first-period-start and renewal-period (e.g., 2,592,000 seconds ≈ 30 days) to compute cycle boundaries.
    • Query /reports/bySubscription for each cycle range.

    Alternative:

    • Export APIM logs to Azure Monitor / Log Analytics and run KQL queries for monthly aggregation.

    Reference Document:

    Monitor Azure API Management | Microsoft Learn

    Let us know if you have any questions?


0 additional answers

Sort by: Most helpful

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.