This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.

Adding New Throttling Policies

WSO2 API Manager admins can add new throttling policies and define extra properties to the throttling policies. To get started, click the level of throttling that you want to add a new policy to:

To make changes in the throttling configurations, set the EnableAdvanceThrottling parameter in api-manager.xml. This parameter is set to true by default. If you set it to false, you only see the available tiers.

Adding a new advanced throttling policy

You can add advanced throttling policies to both APIs and resources.

  1. Sign in to the Admin Portal using the URL https://localhost:9443/admin  and your admin credentials (admin/admin by default).
  2. Click Advanced Throttling under the Throttle Policies section to see the set of existing throttling tiers. 
  3. To add a new tier, click Add Tier.
  4. Fill in the required details and click Save

    Request Count and Request Bandwidth are the two options for default limit. You can use the option according to your requirement. For example, If your using API for File sharing, Data transmission you can use request bandwidth option and limit the data bandwidth for given time unit.

  5. To add throttling limits with different parameters to the conditions below, click Add Conditional Group.

    Note that if you want to add a header, query param, or JSON Web Token (JWT) claim condition, you need to set the <EnableHeaderConditions>, <EnableJWTClaimConditions> or <EnableQueryParamConditions> element to true (depending on which condition you need) in the repository/conf/api-manager.xml file.

    You can add Description about condition group by click Sample description about condition group under Condition Group.

    ConditionDescription
    IP ConditionAllows you to set a throttling limit for a specific IP address or a range of IP addresses.
    Header ConditionAllows you to set a throttling limit to specific headers and parameters.
    Query Param ConditionAllows you to set a throttling limit to specific query parameters.
    JWT Claim ConditionAllows you to set a throttling limit to specific claims.

    Conditional group Execution policy used only for that condition. For example, If you add IP condition and set request count as shown in above diagram then only 5 requests allow per 1 minute using that IP condition. Any request comes with false condition(Outside that condition) taken to the default limit.

  6. Turn on the required condition and enter a condition and value. 
  7. Header condition and JWT claim condition values allow regex patterns to be defined.
    You can configure it to make either an exact match or a pattern match for the value using the regex values. For example,

    Claim name : Name of the JWT Claim
    Eg : "iss" - The issuer of the JWT, "http://wso2.org/claims/apicontext" - Context of the API, "http://wso2.org/claims/version" - API version

    Claim value : Value to be checked in the corresponding claim. (allows regex patterns as well)

    Invert condition : Whether to take the throttle decision based on the equality of the values.
    Eg : If the claim name is "iss" value is "wso2" and "invert condition" is off - Requests having "wso2" as "iss" claim will be throttled.
    If the claim name is "iss" value is "wso2" and "invert condition" is on - Requests not having "wso2" as "iss" claim will be throttled.

  8. Once done, click Add.

You have added a new advanced throttling policy. You can now apply it to an API or a resource.

You possibly can configure multiple conditional groups when defining a tier for advanced throttling policies. For example, Its possible to apply IP based throttling and query pram condition both in one advanced policy tier.


Adding a new application-level throttling tier

Application-level throttling policies are applicable per access token generated for an application. 

  1. Sign in to the Admin Portal using the URL https://localhost:9443/admin and your admin credentials (admin/admin by default).
  2. Click Application Tiers under the Throttle Policies section to see the set of existing throttling tiers. 
  3. To add a new tier, click Add New Policy.
  4. Fill in the required details and click Save


You have added a new application-level throttling policy.


Adding a new subscription-level throttling tier

  1. Sign in to the Admin Portal using the URL  https://localhost:9443/admin  and your admin credentials.
  2. Click Subscription Policies under the Throttling Policies section. The existing set of throttling tiers are displayed. 
  3. To add a new tier, click Add New Policy.

    When you are going to add a new Subscription level throttling tier, you can see the existing list of subscription tiers in Subscription Tier List. In this list, you will find a tier named Unauthenticated which have a request quota of 500. This is a subscription tier which automatically applied when the authentication type of your resources is 'None'. That is, when you can invoke APIs without tokens. And this tier is not visiblie in the Throttling tier list of the application.

  4. Fill in the details required by this form and click Save once you are done. 

    Given below are the descriptions of the fields you find in the form:

    FieldDescription
    Request Count/Request BandwidthThe maximum number of requests/maximum bandwidth allowed to the API within the time period given in the next field.
    Unit TimeTime within which the number of requests given in the previous field is allowed to the API. This can be defined in minutes, hours, days, weeks, months or years.
    Burst Control (Rate Limiting)You can define the request count/bandwidth per unit time on an addition layer by using rate limiting. This is usually a smaller number of requests/bandwidth for a shorter time span than what is enforced in the above fields. For instance, if there's a subscription level policy enforced over a long period, you may not want users to consume the entire quota within a short time span. Enforcing a rate limit protects the backend from sudden request bursts and controls the usage at a subscription and API level.
    Stop On Quota ReachThis indicates the action to be taken when a user goes beyond the allocated quota. If the check box is selected, the user's requests are dropped and an error response (HTTP Status code 429) is given. If the check box is cleared, the requests are allowed to pass through.
    Billing PlanThis field only makes sense if you have API Monetization enabled. The available billing plans are Free, Commercial, and Freemium. An API is tagged/labelled as Free, Paid, or Freemium depending on its subscription tiers (e.g., Unlimited, Gold, etc.), which are the tiers selected when creating an API.
    • Free - If all subscription tiers are defined as Free, the API uses the Free billing plan and the API is labeled as Free in the Store.

    • Paid - If all subscription tiers are defined as Paid, the API uses the Commercial billing plan and the API is labeled as Paid in the Store.

    • Freemium - If the API has a combination of Free and Paid subscription tiers, the API uses the Freemium billing plan and the API is labeled as Freemium in the Store.

    This labeling happens on the API Store only if monetization has been enabled. For information on how to enable monetization and how to tag subscription tiers, see Configuring API Monetization Category Labels
    Custom Attributes

    You can choose to display addtional information about tiers using custom attributes, during custom implementations. The main objective of these fields are to provide more information regarding the tier to Application Developers at the time of API subscription. An example usage of custom attributes is API Monetization.

    PermissionsYou can allow or deny permission for specific roles. Once permission is denied to a role, the new subscription tier that you add here will not be available to that role in the API Store.

    You have added a new subscription-level throttling policy.

    Adding a custom throttling policy

    Custom throttling allows system administrators to define dynamic rules for specific use cases, which are applied globally across all tenants. When a custom throttling policy is created, it is possible to define any policy you like. The Traffic Manager acts as the global throttling engine and is based on the same technology as WSO2 Complex Event Processor (CEP), which uses the Siddhi query language. Users are therefore able to create their own custom throttling policies by writing custom Siddhi queries. The specific combination of attributes being checked in the policy need to be defined as the key (also called the key template). The key template usually includes a predefined format and a set of predefined parameters. It can contain a combination of allowed keys separated by a colon (:), where each key must start with the prefix $. The following keys can be used to create custom throttling policies:

    resourceKey, userId, apiContext, apiVersion, appTenant, apiTenant, appId 

    For example, the following sample custom policy allows the admin user to send 5 requests per minute to the Pizza Shack API. 

    Key Template
    $userId:$apiContext:$apiVersion
    Siddhi query
    FROM RequestStream
    SELECT userId, ( userId == 'admin@carbon.super'  and apiContext == '/pizzashack/1.0.0' and apiVersion == '1.0.0') AS isEligible ,
    str:concat('admin@carbon.super',':','/pizzashack/1.0.0:1.0.0') as throttleKey
      
    INSERT INTO EligibilityStream;
    FROM EligibilityStream[isEligible==true]#throttler:timeBatch(1 min) 
    SELECT throttleKey, (count(userId) >= 5) as isThrottled, expiryTimeStamp group by throttleKey 
    INSERT ALL EVENTS into ResultStream;

    As shown in the above Siddhi query, the throttle key must match the key template format. If there is a mismatch between the key template format and the throttle key, requests will not be throttled.