quota_renewal_rate
to 60 seconds, and update the API.
Note: Obtain your Dashboard API key by clicking on the User profile at the top right corner, then click on Edit Profile
, and select the key available under Tyk Dashboard API Access Credentials
. Now in the below command replace <your-api-key>
with the API key you obtained from the Dashboard UI.
<replace-with-key-id>
with the API Key ID you saved earlier. This command attempts to send 15 requests sequentially.sleep 0.1
adds a tiny delay, but ensure all 15 requests execute well within the 60-second quota window).
200
. After the 10th request, the subsequent requests (11 through 15) should be blocked by the quota limit, returning an HTTP status code 403
(Forbidden).200
. This demonstrates that because the 60-second quota period ended, the next request made after that period triggered the quota reset, replenishing the allowance.
-1
for unlimited requests1000
) to limit total requests3600
for the hourly quota (1 hour = 3600 seconds)86400
for the daily quota (24 hours = 86400 seconds)2592000
for the monthly quota (30 days = 2592000 seconds)tyk.conf
). These settings affect how quotas are enforced across the entire gateway.
enforce_org_quotas
: When set to true
, enables organization-level quota enforcementmonitor.enable_trigger_monitors
: Enables quota monitoring and webhook triggersmonitor.global_trigger_limit
: Percentage of quota usage that triggers alerts (e.g., 80.0 means 80%)monitor.monitor_user_keys
: Enables monitoring for individual API keysmonitor.monitor_org_keys
: Enables monitoring for organization quotasGET /api/portal/policies/{POLICY_ID}
quota_max
and quota_renewal_rate
fields within the policy JSON objectPUT /api/portal/policies/{POLICY_ID}
with the modified object, or create a new one using POST /api/portal/policies/
quota_max
to -1
grants unlimited requests for the quota period.quota_renewal_rate
(in seconds) has passed and upon the next request using the key. They do not reset automatically on a fixed schedule (e.g., precisely at midnight or the 1st of the month) unless external automation updates the session object.X-RateLimit-Limit
, X-RateLimit-Remaining
, and X-RateLimit-Reset
headers to responses, allowing clients to track their usage. (Note: Header names might be configurable).scope
is optional and represents an API-specific allowance scopekey_hash
is the hashed API key (if hash keys are enabled)SessionState
, which contains several quota-related fields:
QuotaMax
: Maximum number of requests allowed during the quota period.QuotaRemaining
: Number of requests remaining for the current period. Note: This is a derived value, not the primary counter.QuotaRenews
: Unix timestamp when the quota will reset.QuotaRenewalRate
: Time in seconds for the quota period (e.g., 3600 for hourly quotas).RateLimitAndQuotaCheck
middleware
RateLimitAndQuotaCheck
middleware, which is a step in the request processing pipeline. Here’s a breakdown of this process:
RateLimitAndQuotaCheck
middleware.
SessionState
.SessionState
to get the specific quota parameters applicable to this key and potentially the specific API being accessed (if per-API quotas are configured):
QuotaMax
: The maximum number of requests allowed.QuotaRenewalRate
: The duration (in seconds) of the quota period for setting the TTL in Redis.quota-{scope}-{api-key-hash}
).QuotaRenewalRate
as the new TTL).QuotaMax
retrieved from the session state.new_counter_value <= QuotaMax
: The request is within the allowed quota.new_counter_value > QuotaMax
: This request has exceeded the quota limit.HTTP 403 Forbidden
with a “Quota exceeded” message.updateSessionQuota
) to update the in-memory SessionState
associated with the API key. This update synchronizes the QuotaRemaining
field in the session with the latest calculated state based on the Redis counter and its expiry. It ensures that subsequent operations within the same request lifecycle (if any) or diagnostic information have access to the most recent quota status.
QuotaRemaining
) for an API key is replenished back to its maximum (QuotaMax
) through several distinct mechanisms:
QuotaRenewalRate
(in seconds) has elapsed since the quota period began (i.e., since the last reset or key creation/update). In Redis, this corresponds to the Time-To-Live (TTL) expiring on the quota tracking key.QuotaRenewalRate
duration has passed (and the Redis TTL has expired).QuotaRenewalRate
. This effectively makes the full QuotaMax
available for the new period starting from that moment.QuotaMax
and setting a new TTL. This provides an immediate, on-demand refresh of the quota allowance.QuotaRemaining
value to QuotaMax
in the key’s session data and ensuring the corresponding Redis key is created with the correct initial value (or implicitly reset) and its TTL set according to the QuotaRenewalRate
. This ensures the key starts with a fresh quota allowance according to its defined limits.DontSetQuotasOnCreate
field (referred to as SkipQuotaReset
in the OAS specification), which prevents automatic quota resets during key creation or updates.QuotaRenewalRate
(in seconds)
What are Request Quotas in Tyk?
How do Request Quotas differ from Rate Limits?
How are Request Quotas configured in Tyk?
What are the key parameters for Request Quotas?
quota_max
: Maximum number of requests allowed during the quota periodquota_remaining
: Number of requests remaining for the current periodquota_renewal_rate
: Time in seconds during which the quota is valid (e.g., 3600 for hourly quotas)quota_renews
: Timestamp indicating when the quota will resetCan I disable Request Quotas for specific APIs?
disable_quota
flag to true
in the API definition. This config will bypass quota checking for all requests to that API, regardless of any quotas set at the key or policy level.Refer this documentation.What happens when a Request Quota is exceeded?
How are Request Quotas tracked and stored?
Can I set different quotas for different endpoints within the same API?
How do organization-level quotas work?
enforce_org_quotas
), Tyk tracks the combined usage of all keys in the organization and rejects requests when the organization quota is exceeded, regardless of individual key quotas.Can I monitor quota usage and receive notifications before quotas are exceeded?
monitor
section of your Tyk configurationWhy isn't my quota resetting automatically at midnight?
How can I manually reset a quota for a specific key?
Does Tyk count failed requests against my quota?
Why are my quota counts inconsistent in a multi-gateway setup?
Why do I see "Quota disabled" error logs when I've intentionally disabled quotas?
quota_max
to -1 (to disable quotas) would generate an error log message: Quota disabled: quota max <= 0
. This was a known issue that has been fixed in more recent versions.If you’re still seeing these logs, consider:disable_quota
flag instead of setting quota_max
to -1Can I set quotas to only count successful requests?
What happens if I change a quota mid-period?
Can I implement different quota plans for different users?
How do I troubleshoot quota issues?
X-Rate-Limit-Remaining
headers in API responses