An Azure service that provides a hybrid, multi-cloud management platform for APIs.
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
- Go to APIM → Monitoring → Diagnostic settings → + Add diagnostic setting.
- Select Logs related to ApiManagement Gateway.
- Select Send to Log Analytics and use the resource-specific destination table.
- Under APIs → APIs → All APIs → Settings → Diagnostic Logs → Azure Monitor, configure the API diagnostic logger to capture the custom response headers.
- Verify that
x-apim-ratelimit-remainingandx-apim-ratelimit-limitappear 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 -
GatewayIdor 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
- Limit call rate by key
- Advanced request throttling with Azure API Management
- Monitor API Management
- Observability in Azure API Management
- Stream Azure monitoring data to an event hub and external partner
- Create or edit a log search alert rule
- Best practices for Azure Monitor alerts
- IQuotaByPeriodKeysOperations.GetWithHttpMessagesAsync Method-Definition