1.Rate Limiting Overview
Also known as throttling, Tyk API will actively only allow a key to make
x requests per
y time period. This is very useful if you want to ensure your API does not get flooded with requests.
How do rate limits work?
The Rate limits in Tyk work using a “leaky bucket” mechanism: Tyk will record each request in a timestamped list in Redis, it will at the same time count the number of requests that fall between the current time, and the maximum time in the past that encompasses the rate limit (and remove these from the list). If this count exceeds the number of requests over the period, the request is blocked.
This approach means that rate limits are applied across all gateway instances equally and that the actual limit is a “moving window” so that there is no fixed point in time to flood the limiter or execute more requests than is permitted by any one client.
Can I disable the rate limiter?
Not currently, the rate limiter is always enforced except on “Open (Keyless)” API configurations.
Can I rate limit by IP address?
2.Set a rate limit with the GUI
In order to apply a rate limit with the GUI:
Visit the key creation screen by browsing to “System Management” -> “Keys” -> “Add Key”
Ensure the new key has access to the APIs you wish it work with by selecting the API from the “Access Rights” -> “Add Access Rule” and clicking the “add” button.
Under the “Rate Limit” section of the page, select the rate (number of requests”) and the “per” period. If the period is not available in the drop down, you can set it to a custom value using the Dashboard REST API.
- Save the token, it will be created instantly.
3.Set a rate limit on the session object (API)
All actions on the session object must be done via the Dashboard or Gateway REST API.
rateare set to the same value, this should be number of requests to be allowed in a time period, so if you wanted 100 requests every second, set this value to 100.
peris set to the time limit. Again, as in the above example, if you wanted 100 requests per second, set this value to 1. If you wanted 100 per 5 seconds, set this value to 5 etc.