Limit Count Configuration
Parameters
See plugin common configurations for configuration options available to all plugins.
This plugin supports referencing 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.
-
count—integer | string· optionalValid values: greater than 0
The maximum number of requests allowed within a given time interval.
A string value can reference a built-in variable by prefixing the variable with a dollar sign (
$). Introduced in API7 Enterprise 3.9.14 and 3.10.1, and APISIX 3.16.0. Earlier versions accept only integer values.Required with
time_windowwhenrulesis not configured. Do not configurecountortime_windowtogether withrules.A string value must resolve to a positive integer no greater than
9007199254740991. An invalid value returns500 Internal Server Errorunlessallow_degradationistrue. Introduced in API7 Enterprise 3.9.16 and 3.10.2, and APISIX 3.18.0. -
time_window—integer | string· optionalValid values: greater than 0
The time interval corresponding to the rate limiting
countin seconds.A string value can reference a built-in variable by prefixing the variable with a dollar sign (
$). Introduced in API7 Enterprise 3.9.14 and 3.10.1, and APISIX 3.16.0. Earlier versions accept only integer values.Required with
countwhenrulesis not configured. Do not configurecountortime_windowtogether withrules.A string value must resolve to a positive integer no greater than
9007199254740991. An invalid value returns500 Internal Server Errorunlessallow_degradationistrue. Introduced in API7 Enterprise 3.9.16 and 3.10.2, and APISIX 3.18.0. -
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 the rate limiting counter. Required for API7 Enterprise and optional for APISIX.
When set to
local, the counter is stored in memory locally. When set toredis, the counter is stored on a Redis instance. When set toredis-cluster, the counter is stored in a Redis cluster. When set toredis-sentinel, the counter is stored on Redis nodes managed by Redis Sentinel.The
redis-sentinelvalue adds high availability through Sentinel-managed failover. Introduced in API7 Enterprise 3.9.14 and 3.10.1, and APISIX 3.18.0. -
window_type—string· optional · default:fixedValid values:
fixedorslidingThe rate limiting window algorithm. When set to
fixed, a fixed window algorithm is used, where each time window enforces the quota independently. When set tosliding, a sliding window algorithm is used, which smooths out bursts at window boundaries by weighting the previous window when calculating the current count.Introduced in API7 Enterprise 3.9.14 and 3.10.1, and APISIX 3.18.0.
-
sync_interval—number· optional · default:-1Valid values:
-1or greater than or equal to0.1; must be smaller than a numeric top-leveltime_windowThe interval in seconds at which the local counter is synchronized to the shared store (Redis). Only takes effect when
policyisredis,redis-cluster, orredis-sentinel. A value of-1disables delayed synchronization, so each request synchronizes directly. When enabled, the value should not be smaller than0.1and should be smaller thantime_window. Enabling delayed synchronization reduces the number of round trips to the shared store at the cost of slightly looser enforcement.At runtime, if the applicable
time_windowis less than or equal tosync_interval, the gateway falls back to direct synchronization for that request. This can occur with variable-resolved values or values insiderules, which are evaluated at request time.Introduced in API7 Enterprise 3.9.14 and 3.10.1, and APISIX 3.18.0.
-
allow_degradation—boolean· optional · default:falseIf true, continue handling requests without rate limiting when the counter backend fails or a variable-resolved
countortime_windowis invalid. If false, these failures return500 Internal Server Error. -
show_limit_quota_header—boolean· optional · default:trueIf true, include quota headers on the response.
With the default names,
X-RateLimit-Limitis the total quota,X-RateLimit-Remainingis how many requests remain in the window, andX-RateLimit-Resetis the number of seconds until the counter resets.You can rename those headers with plugin metadata. When
rulesis configured, each rule inserts itsheader_prefix(or the rule index if omitted) beforeRateLimit-so Limit, Remaining, and Reset stay distinct per rule. Seerules.header_prefix. -
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 whenpolicyisredisorredis-sentinel. -
redis_password—string· optionalThe password of the Redis node when
policyisredis,redis-cluster, orredis-sentinel. The password is encrypted at rest in API7 Enterprise. In APISIX, enable data encryption to encrypt it before etcd storage. Encryption was introduced in API7 Enterprise 3.9.16 and 3.10.2, and APISIX 3.18.0. -
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-sentinelKeepalive timeout in milliseconds for Redis connections. When
policyisredisorredis-cluster, the default is10000and the minimum is1000. Whenpolicyisredis-sentinel, the default is60000and the minimum is1.Introduced in API7 Enterprise 3.9.16 and 3.10.3, and APISIX 3.15.0. Sentinel defaults were introduced in API7 Enterprise 3.9.14 and 3.10.1, and APISIX 3.18.0.
-
redis_keepalive_pool—integer· optional · default:100Valid values: greater than or equal to 1
Keepalive pool size for Redis when
policyisredisorredis-cluster.Introduced in API7 Enterprise 3.9.16 and 3.10.3, and APISIX 3.15.0.
-
redis_cluster_nodes—array[string]· optionalThe list of Redis cluster nodes with at least one address. 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. -
redis_sentinels—array[object]· optionalThe list of Redis Sentinel nodes, with at least one node. Required when
policyisredis-sentinel. Each node is an object withhost(string) andport(integer between 1 and 65535).Introduced in API7 Enterprise 3.9.14 and 3.10.1, and APISIX 3.18.0.
-
redis_master_name—string· optionalThe name of the Redis master monitored by Sentinel. Required when
policyisredis-sentinel.Introduced in API7 Enterprise 3.9.14 and 3.10.1, and APISIX 3.18.0.
-
redis_role—string· optional · default:masterValid values:
masterorslaveThe role of the Redis node to connect to when
policyisredis-sentinel. Usemasterfor read and write operations, orslavefor read-only replicas.Introduced in API7 Enterprise 3.9.14 and 3.10.1, and APISIX 3.18.0.
-
redis_connect_timeout—integer· optional · default:1000Valid values: greater than or equal to 1
The connection timeout in milliseconds when
policyisredis-sentinel.Introduced in API7 Enterprise 3.9.14 and 3.10.1, and APISIX 3.18.0.
-
redis_read_timeout—integer· optional · default:1000Valid values: greater than or equal to 1
The read timeout in milliseconds when
policyisredis-sentinel.Introduced in API7 Enterprise 3.9.14 and 3.10.1, and APISIX 3.18.0.
-
sentinel_username—string· optionalThe username used to authenticate with the Redis Sentinel nodes when
policyisredis-sentinel.Introduced in API7 Enterprise 3.9.14 and 3.10.1, and APISIX 3.18.0.
-
sentinel_password—string· optionalThe password used to authenticate with the Redis Sentinel nodes when
policyisredis-sentinel.Introduced in API7 Enterprise 3.9.14 and 3.10.1, and APISIX 3.18.0.
The password is encrypted at rest in API7 Enterprise. In APISIX, enable data encryption to encrypt it before etcd storage. Encryption was introduced in API7 Enterprise 3.9.16 and 3.10.2, and APISIX 3.18.0.
-
rules—array[object]· optionalAn array of rate-limiting rules that are applied sequentially. Do not configure
rulestogether with the top-levelcount,time_window, orgroupfields. The top-levelkeyandkey_typeare not used in rules mode. Rule keys must be unique. A rule whosekeyvariable is absent from a request is skipped.Introduced in API7 Enterprise 3.9.14 and 3.10.1, and APISIX 3.16.0.
-
count—integer | string· requiredValid values: greater than 0
The maximum number of requests allowed within the given
time_window.This parameter also supports the string data type and allows the use of built-in variables prefixed with a dollar sign (
$).A string value must resolve to a positive integer no greater than
9007199254740991. If the rule applies and the value is invalid, the request returns500 Internal Server Errorunlessallow_degradationistrue. Introduced in API7 Enterprise 3.9.16 and 3.10.2, and APISIX 3.18.0. -
time_window—integer | string· requiredValid values: greater than 0
The time interval in seconds for the rate limiting
count.This parameter also supports the string data type and allows the use of built-in variables prefixed with a dollar sign (
$).A string value must resolve to a positive integer no greater than
9007199254740991. If the rule applies and the value is invalid, the request returns500 Internal Server Errorunlessallow_degradationistrue. Introduced in API7 Enterprise 3.9.16 and 3.10.2, and APISIX 3.18.0. -
key—string· requiredA variable expression that resolves to the key used to count requests for this rule. Prefix every APISIX built-in variable or NGINX variable with a dollar sign (
$), for example$remote_addror$remote_addr $http_x_tenant.The top-level
key_typedoes not apply to rules. A rule with no resolvable variable is skipped for that request. -
header_prefix—string· optionalA prefix inserted before
RateLimit-in this rule's quota headers so each rule stays distinguishable. With the default names,fooproducesX-foo-RateLimit-Limit,X-foo-RateLimit-Remaining, andX-foo-RateLimit-Reset. Those headers still mean total quota, remaining quota, and seconds until reset. If omitted, the rule's array index is used, so the first rule becomesX-1-RateLimit-Limit. Only sent whenshow_limit_quota_headeristrue.
-
Plugin Metadata
-
limit_header—string· optional · default:X-RateLimit-LimitDefault response header name for the total rate limit quota.
-
remaining_header—string· optional · default:X-RateLimit-RemainingDefault response header name for the remaining rate limit quota.
-
reset_header—string· optional · default:X-RateLimit-ResetDefault response header name for the number of seconds until the rate limit counter resets.