Search code examples
azureazure-api-managementpolicies

Limiting usage quota by API in Azure API Management


The Azure API Management Policies have a nice array of possibilities. The examples how to configure the Usage Quota by subscription or by key are everywhere.

But what if I want to set a different quota for different APIs in the same Subscription?

For example, include a "taste" of an API in a particular plan (Product, in APIM parlance) so that the users give it a try but won't be able to use it in production. While other APIs for the same plan will have a higher quota.

I see there's a Control Flow but I'm wondering how to obtain the API being called.


Solution

  • You can use "quota" policy as it allows you to specify different limits per product/API/operation. Look for sample here: https://learn.microsoft.com/en-us/azure/api-management/api-management-access-restriction-policies#SetUsageQuota. Inherently those limits are enforced per API per subscription.

    Or you can use quota-by-key policy and construct your own key that would identify counter. API is available through context.Api. Here are more details about context variable: https://learn.microsoft.com/en-us/azure/api-management/api-management-policy-expressions#ContextVariables