Is there a Microsoft-recommended way to proactively monitor APIM rate-limit utilization before throttling?

NIDHIN JOSEPH 20 Reputation points
2026-11-15T16:42:52.1366667+00:00

We are currently using Azure API Management and receive native quota notifications (e.g., "Quota counter is approaching a quota limit") for 24-hour quota policies.

We are exploring a similar proactive monitoring approach for short-duration rate-limit policies (e.g., rate-limit-by-key with a 5-minute renewal period).

Our objective is to be notified when a subscription approaches 80% or 90% of its configured rate limit before throttling (HTTP 429) occurs.

A few questions:

  • Does APIM provide any built-in capability to generate notifications when a rate-limit counter reaches a configurable threshold (similar to quota notifications)?
  • Is there a Microsoft-recommended architecture for proactive rate-limit monitoring?
  • Has anyone implemented this using Azure Monitor, Log Analytics, Application Insights, or Splunk?
  • If APIM Management APIs expose configured rate limits, what is the recommended method to calculate near real-time utilization against those limits?
  • For short renewal windows (e.g., 5 minutes), what approach is recommended to avoid excessive alerts while still providing proactive visibility?

We are evaluating whether a dashboard-based approach or threshold-based alerting would be more appropriate and would appreciate any guidance or best practices from the APIM product team or community.

Azure API Management
Azure API Management

An Azure service that provides a hybrid, multi-cloud management platform for APIs.

0 comments No comments

2 answers

Sort by: Oldest
  1. AI answer

    2026-11-15T16:48:21.32+00:00

    APIM does not provide a documented quota-style threshold notification for short-duration rate limits; expose the policy’s remaining and total call values, capture them as telemetry, and alert on the resulting depletion percentage.

    Expose the live rate-limit state

    rate-limit-by-key can return both the remaining calls and configured total after every policy execution. For subscription-level monitoring:

    <policies>
      <inbound>
        <base />
        <rate-limit-by-key
            calls="1000"
            renewal-period="300"
            counter-key="@(context.Subscription.Id)"
            remaining-calls-header-name="x-apim-ratelimit-remaining"
            total-calls-header-name="x-apim-ratelimit-limit" />
      </inbound>
      <backend><base /></backend>
      <outbound><base /></outbound>
      <on-error><base /></on-error>
    </policies>
    

    Apply this through APIM → APIs → API name → Design → All operations → Inbound processing → Code editor, adjusting the counter key to match the actual throttling boundary. The maximum renewal-period for rate-limit-by-key is 300 seconds. The policy also supports storing the remaining value in a policy variable instead of returning it to callers.^1^

    If exposing these headers publicly is undesirable, use remaining-calls-variable-name and send a normalized value to your telemetry pipeline instead. The available documentation does not provide a complete policy example for exporting that variable, so the implementation depends on the selected logger.

    Calculate an operational depletion signal as:

    depletionPercent = 100 * (totalCalls - remainingCalls) / totalCalls
    

    For v2 tiers, this represents token-bucket depletion—not literal usage in a fixed five-minute window. Classic tiers use a sliding window, while v2 tiers use a token bucket.^2^

    Choose the telemetry path

    Dashboard and ordinary operational visibility

    1. Go to APIM → Monitoring → Diagnostic settings → + Add diagnostic setting.
    2. Select Logs related to ApiManagement Gateway.
    3. Select Send to Log Analytics and use the resource-specific destination table.
    4. Under APIs → APIs → All APIs → Settings → Diagnostic Logs → Azure Monitor, configure the API diagnostic logger to capture the custom response headers.
    5. Verify that x-apim-ratelimit-remaining and x-apim-ratelimit-limit appear in the resulting gateway records before building the alert.

    Gateway logs can contain request and response headers, but diagnostic logging uses configurable collection settings. Merely creating the resource diagnostic setting is therefore not sufficient unless the custom headers are actually present in the emitted records.^3^

    The Azure Monitor-based Monitoring → Analytics dashboard is Microsoft’s recommended replacement for classic APIM analytics, but analytics can be delayed and is better suited to trends and capacity planning than a last-minute five-minute-window warning.^3^

    Lower-latency alerting

    For a five-minute limit, APIM observability options have materially different latency:

    • Application Insights: seconds
    • Event Hubs custom logging: seconds
    • Azure Monitor Logs: minutes

    These are documented telemetry characteristics, not guaranteed alert-delivery times.^4^

    If seconds matter, normalize each observation into fields such as:

    • SubscriptionId
    • GatewayId or region
    • Remaining
    • Limit
    • DepletionPercent
    • timestamp

    Send those observations to Application Insights or Event Hubs. Event Hubs is also the practical route to Splunk or another SIEM; Azure Monitor diagnostic settings can stream platform logs to Event Hubs, and Splunk has an Azure Event Hubs integration.^5^

    The exact KQL depends on how the captured headers are represented. After normalizing them into numeric columns, the alert query is conceptually:

    RateLimitObservations
    | where TimeGenerated > ago(5m)
    | summarize arg_max(TimeGenerated, *) by SubscriptionId, GatewayId
    | extend DepletionPercent =
        100.0 * (Limit - Remaining) / Limit
    | where DepletionPercent >= 80
    

    Create a log search alert from the query, measure returned table rows, and split by stable dimensions such as subscription and gateway. Avoid volatile or high-cardinality dimensions because each unique combination becomes a separate alert instance.^6^

    Avoid alert storms

    For five-minute windows:

    • Use a dashboard for 80% visibility.
    • Page only at 90%, repeated near-exhaustion, or actual 429s.
    • Use a stateful alert so it fires once and resolves after recovery.
    • Require two consecutive evaluations where latency permits.
    • Group by subscription and gateway, then use alert processing rules for suppression.
    • Keep Log Analytics evaluation frequency no shorter than operationally necessary; more frequent log searches increase cost.^7^

    Do not use quota-counter management APIs for this calculation: the documented operations retrieve quota-by-key counters, not rate-limit-by-key state.^8^

    Finally, treat thresholds as approximate. Rate limiting is distributed, and multi-region or workspace gateways maintain separate counters rather than an instance-wide aggregate. Alert per gateway/region, or aggregate only for reporting.^1^


    References

    1. Limit call rate by key
    2. Advanced request throttling with Azure API Management
    3. Monitor API Management
    4. Observability in Azure API Management
    5. Stream Azure monitoring data to an event hub and external partner
    6. Create or edit a log search alert rule
    7. Best practices for Azure Monitor alerts
    8. IQuotaByPeriodKeysOperations.GetWithHttpMessagesAsync Method-Definition
    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

  2. NIDHIN JOSEPH 20 Reputation points
    2026-11-16T07:02:26.7033333+00:00

    Hi,

    1. If remaining-calls-header-name and total-calls-header-name are configured, can these values be exported through APIM Diagnostics/Event Hub and consumed by external monitoring systems such as Splunk without exposing them to API consumers?
    2. Can remaining-calls and total-calls values be exported to Splunk via APIM diagnostics without requiring response header collection, and is this Microsoft's recommended approach for proactive rate-limit monitoring?
    3. Has Microsoft published any reference architecture or best-practice implementation for proactive monitoring of rate-limit-by-key utilization before HTTP 429 responses occur?

    Was this answer helpful?

    0 comments No comments

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.