Limit Count Advanced Configuration
Parameters
See plugin common configurations for configuration options available to all plugins.
This plugin supports referencing sensitive parameter values from environment variables using the env:// prefix, or from a secret manager, such as HashiCorp Vault’s KV secrets engine, using the secret:// prefix. For more information, see environment variables in plugin and secrets.
In API7 Enterprise (from 3.8.17), you should configure one of the following parameter sets, but not both:
count,time_windowrules
-
count—integer | string· requiredValid values: greater than 0
The maximum number of requests allowed within a given time interval.
In API7 Enterprise (from 3.8.17), this parameter also supports the string data type and allows the use of built-in variables prefixed with a dollar sign (
$). -
time_window—integer | string· requiredValid values: greater than 0
The time interval corresponding to the rate limiting
countin seconds.In API7 Enterprise (from 3.8.17), this parameter also supports the string data type and allows the use of built-in variables prefixed with a dollar sign (
$). -
window_type—string· optional · default:fixedValid values:
fixedorslidingRate limiting algorithm, fixed window or sliding window.
-
key_type—string· optional · default:varValid values:
var,var_combination, orconstantThe type of key.
If the
key_typeisvar, thekeyis interpreted as a variable.If the
key_typeisvar_combination, thekeyis interpreted as a combination of variables.If the
key_typeisconstant, thekeyis interpreted as a constant. -
key—string· optional · default:remote_addrThe key to count requests by.
If the
key_typeisvar, thekeyis interpreted as a variable. The variable does not need to be prefixed by a dollar sign ($). See built-in variables for available variables.If the
key_typeisvar_combination, thekeyis interpreted as a combination of variables. All variables should be prefixed by dollar signs ($). For example, to configure thekeyto use a combination of two request headerscustom-aandcustom-b, thekeyshould be configured as$http_custom_a $http_custom_b.If the
key_typeisconstant, thekeyis interpreted as a constant value. -
rejected_code—integer· optional · default:503Valid values: between 200 and 599 inclusive
The HTTP status code returned when a request is rejected for exceeding the threshold.
-
rejected_msg—string· optionalValid values: any non-empty string
The response body returned when a request is rejected for exceeding the threshold.
-
policy—string· optional · default:localValid values:
local,redis,redis-cluster, orredis-sentinelThe policy for rate limiting counter.
Set to
localto store the counter in memory locally.Set to
redisto store the counter on a Redis instance.Set to
redis-clusterto store the counter in a Redis cluster.Set to
redis-sentinelto store the counter on the Redis primary node managed by Redis Sentinel, which ensures high availability by automatically promoting a replica to primary in case of failure. Redis Sentinel provides high availability for Redis when not using Redis Cluster. -
redis_sentinels—array[object]· optionalAn array of Redis Sentinel nodes (host and port). Required when
policyisredis-sentinel. -
redis_master_name—string· optionalThe name of the Redis master group that Sentinels are monitoring. Required when
policyisredis-sentinel. -
redis_role—string· optional · default:masterValid values:
masterorslaveThe Redis node role to connect to. Configurable when
policyisredis-sentinel. Set tomasterto connect to the current Redis master, and set toslaveto connect to a Redis replica. -
redis_connect_timeout—integer· optional · default:1000Valid values: greater than or equal to 1
Timeout in milliseconds for establishing a connection to a Redis node. Configurable when
policyisredis-sentinel. -
redis_read_timeout—integer· optional · default:1000Valid values: greater than or equal to 1
Timeout in milliseconds for reading data from a Redis node. Configurable when
policyisredis-sentinel. -
sentinel_username—string· optionalUsername used to authenticate with the Redis Sentinel instance. Configurable when
policyisredis-sentinel. -
sentinel_password—string· optionalPassword used to authenticate with the Redis Sentinel instance. Configurable when
policyisredis-sentinel. -
allow_degradation—boolean· optional · default:falseIf true, allow the gateway to continue handling requests without the plugin when the plugin or its dependencies become unavailable.
-
rules—array[object]· optionalAn array of rate-limiting rules that are applied sequentially.
Available in API7 Enterprise from 3.8.17.
-
count—integer | string· requiredValid values: greater than 0
The maximum number of requests allowed within a given time interval.
This parameter also supports the string data type and allows the use of built-in variables prefixed with a dollar sign (
$). -
time_window—integer | string· requiredValid values: greater than 0
The time interval corresponding to the rate limiting
countin seconds.This parameter also supports the string data type and allows the use of built-in variables prefixed with a dollar sign (
$). -
key—string· requiredThe key to count requests by. If the configured key does not exist, the rule will not be executed.
The
keyis interpreted as a combination of variables, for example,$http_custom_a $http_custom_b. -
header_prefix—string· optionalPrefix for all rate limiting response headers. Available in API7 Enterprise from version 3.8.19.
When configured, the prefix is inserted after
X-in the header name. For example, withheader_prefixset totest, the headers becomeX-Test-RateLimit-Limit,X-Test-RateLimit-Remaining, andX-Test-RateLimit-Reset.When not configured, the index of the rule in the rules array is used as the prefix. For example, headers for the first rule will be
X-1-RateLimit-Limit,X-1-RateLimit-Remaining, andX-1-RateLimit-Reset.
-
-
show_limit_quota_header—boolean· optional · default:trueIf true, includes the rate limiting response headers. Specifically, if
rulesis not set, the headers are:X-RateLimit-Limitshows the total quota.X-RateLimit-Remainingshows the remaining quota.X-RateLimit-Resetshows the number of seconds until the counter resets.
When
rulesis set, a prefix (followed by a hyphen) is inserted afterX-. Seerules.header_prefixfor details. -
group—string· optionalValid values: non-empty
The
groupID for the plugin, such that routes of the samegroupcan share the same rate limiting counter. -
redis_host—string· optionalThe address of the Redis node. Required when
policyisredis. -
redis_port—integer· optional · default:6379Valid values: greater than or equal to 1
The port of the Redis node when
policyisredis. -
redis_username—string· optionalThe username for Redis if Redis ACL is used. If you use the legacy authentication method
requirepass, configure only theredis_password. Used whenpolicyisredis. -
redis_password—string· optionalThe password of the Redis node when
policyisredis, orredis-cluster. -
redis_database—integer· optional · default:0Valid values: greater than or equal to 0
The database number in Redis when
policyisredisorredis-sentinel. -
redis_ssl—boolean· optional · default:falseIf true, use SSL to connect to Redis when
policyisredis. -
redis_ssl_verify—boolean· optional · default:falseIf true, verify the server SSL certificate when
policyisredis. -
redis_timeout—integer· optional · default:1000Valid values: greater than or equal to 1
The Redis timeout value in milliseconds when
policyisredisorredis-cluster. -
redis_keepalive_timeout—integer· optionalValid values: greater than or equal to 1000 for
redisandredis-cluster; greater than or equal to 1 forredis-sentinelTime in milliseconds that an idle Redis connection is kept alive in the connection pool before being closed. When
policyisredisorredis-cluster, the default is10000. Whenpolicyisredis-sentinel, the default is60000.For
redisandredis-cluster, this parameter was introduced in API7 Enterprise 3.9.16 and 3.10.3. -
redis_keepalive_pool—integer· optional · default:100Valid values: greater than or equal to 1
Maximum number of idle Redis connections in the keepalive pool. Used when
policyisredisorredis-cluster.Introduced in API7 Enterprise 3.9.16 and 3.10.3.
-
redis_cluster_nodes—array[string]· optionalThe list of Redis cluster nodes with at least two addresses. Required when
policyisredis-cluster. -
redis_cluster_name—string· optionalThe name of the Redis cluster. Required when
policyisredis-cluster. -
redis_cluster_ssl—boolean· optional · default:falseIf true, use SSL to connect to Redis cluster when
policyisredis-cluster. -
redis_cluster_ssl_verify—boolean· optional · default:falseIf true, verify the server SSL certificate when
policyisredis-cluster. -
sync_interval—number· optional · default:-1Valid values: greater than or equal to 0.1, or the default -1
The frequency of synchronizing counter data to Redis. Available only in Enterprise.
The
sync_intervalvalue should be smaller thantime_window. A value of1results in synchronizing counter data every second. A value of-1yields no change in synchronizing behaviour, i.e. counter data will be synchronized for each request.