AI Rate Limiting Advanced 정책 구성 참조
AI Rate Limiting Advanced 정책 구성 참조 (AI Rate Limiting Advanced Policy Configuration Reference)
이 문서는 AI Rate Limiting Advanced 정책에서 설정할 수 있는 구성 옵션을 한눈에 확인할 수 있는 참조 자료예요. 요청 제한 초과 시 반환할 오류 코드와 메시지, local·redis·cluster 중 어떤 제한 전략을 사용할지 같은 핵심 파라미터를 스키마 형태로 설명해요. 토큰 비용 계산 기준이나 Redis 연결 설정처럼 세부 동작을 조정하는 방법도 함께 다뤄요
출처: 문서
본문
{
"properties": {
"config": {
"type": "object",
"properties": {
"disable_penalty": {
"type": "boolean",
"description": "If set to `true`, this doesn't count denied requests (status = `429`). If set to `false`, all requests, including denied ones, are counted. This parameter only affects the `sliding` window_type and the request prompt provider.",
"default": false
},
"error_code": {
"type": "number",
"description": "Set a custom error code to return when the rate limit is exceeded.",
"default": 429
},
"error_message": {
"type": "string",
"description": "Set a custom error message to return when the rate limit is exceeded.",
"default": "AI token rate limit exceeded for provider(s): "
},
"strategy": {
"type": "string",
"enum": [
"cluster",
"local",
"redis"
],
"description": "The rate-limiting strategy to use for retrieving and incrementing the limits. Available values are: `local`, `redis` and `cluster`.",
"default": "local"
},
"path": {
"type": "string",
"description": "A string representing a URL path, such as /path/to/resource. Must start with a forward slash (/) and must not contain empty segments (i.e., two consecutive forward slashes)."
},
"request_prompt_count_function": {
"type": "string",
"description": "If defined, it use custom function to count requests for the request prompt provider"
},
"tokens_count_strategy": {
"type": "string",
"enum": [
"completion_tokens",
"cost",
"prompt_tokens",
"total_tokens"
],
"description": "What tokens to use for cost calculation. Available values are: `total_tokens` `prompt_tokens`, `completion_tokens` or `cost`.",
"default": "total_tokens"
},
"redis": {
"type": "object",
"properties": {
"username": {
"type": "string",
"description": "Username to use for Redis connections. If undefined, ACL authentication won't be performed. This requires Redis v6.0.0+. To be compatible with Redis v5.x.y, you can set it to `default`.",
"x-referenceable": true
},
"sentinel_username": {
"type": "string",
"description": "Sentinel username to authenticate with a Redis Sentinel instance. If undefined, ACL authentication won't be performed. This requires Redis v6.2.0+.",
"x-referenceable": true
},
"cloud_authentication": {
"type": "object",
"properties": {
"aws_cache_name": {
"type": "string",
"description": "The name of the AWS Elasticache cluster when `auth_provider` is set to `aws`.",
"x-referenceable": true
},
"aws_region": {
"type": "string",
"description": "The region of the AWS ElastiCache cluster when `auth_provider` is set to `aws`.",
"x-referenceable": true
},
"azure_client_id": {
"type": "string",
"description": "Azure Client ID to be used for authentication when `auth_provider` is set to `azure`.",
"x-referenceable": true,
"x-encrypted": true
},
"azure_tenant_id": {
"type": "string",
"description": "Azure Tenant ID to be used for authentication when `auth_provider` is set to `azure`.",
"x-encrypted": true,
"x-referenceable": true
},
"auth_provider": {
"type": "string",
"enum": [
"aws",
"azure",
"gcp"
],
"description": "Auth providers to be used to authenticate to a Cloud Provider's Redis instance.",
"x-referenceable": true
},
"aws_is_serverless": {
"type": "boolean",
"description": "This flag specifies whether the cluster is serverless when auth_provider is set to `aws`.",
"default": true
},
"aws_access_key_id": {
"type": "string",
"description": "AWS Access Key ID to be used for authentication when `auth_provider` is set to `aws`.",
"x-encrypted": true,
"x-referenceable": true
},
"aws_secret_access_key": {
"type": "string",
"description": "AWS Secret Access Key to be used for authentication when `auth_provider` is set to `aws`.",
"x-referenceable": true,
"x-encrypted": true
},
"aws_assume_role_arn": {
"type": "string",
"description": "The ARN of the IAM role to assume for generating ElastiCache IAM authentication tokens.",
"x-referenceable": true,
"x-encrypted": true
},
"aws_role_session_name": {
"type": "string",
"description": "The session name for the temporary credentials when assuming the IAM role.",
"x-referenceable": true,
"x-encrypted": true
},
"gcp_service_account_json": {
"type": "string",
"description": "GCP Service Account JSON to be used for authentication when `auth_provider` is set to `gcp`.",
"x-encrypted": true,
"x-referenceable": true
},
"azure_client_secret": {
"type": "string",
"description": "Azure Client Secret to be used for authentication when `auth_provider` is set to `azure`.",
"x-encrypted": true,
"x-referenceable": true
}
},
"description": "Cloud auth related configs for connecting to a Cloud Provider's Redis instance."
},
"sentinel_master": {
"type": "string",
"description": "Sentinel master to use for Redis connections. Defining this value implies using Redis Sentinel."
},
"sentinel_role": {
"type": "string",
"enum": [
"any",
"master",
"slave"
],
"description": "Sentinel role to use for Redis connections when the `redis` strategy is defined. Defining this value implies using Redis Sentinel."
},
"cluster_nodes": {
"type": "array",
"items": {
"type": "object",
"properties": {
"port": {
"type": "integer",
"maximum": 65535,
"minimum": 0,
"description": "An integer representing a port number between 0 and 65535, inclusive.",
"default": 6379
},
"ip": {
"type": "string",
"description": "A string representing a host name, such as example.com.",
"default": "127.0.0.1"
}
}
},
"minLength": 1,
"description": "Cluster addresses to use for Redis connections when the `redis` strategy is defined. Defining this field implies using a Redis Cluster. The minimum length of the array is 1 element."
},
"keepalive_backlog": {
"type": "integer",
"maximum": 2147483646,
"minimum": 0,
"description": "Limits the total number of opened connections for a pool. If the connection pool is full, connection queues above the limit go into the backlog queue. If the backlog queue is full, subsequent connect operations fail and return `nil`. Queued operations (subject to set timeouts) resume once the number of connections in the pool is less than `keepalive_pool_size`. If latency is high or throughput is low, try increasing this value. Empirically, this value is larger than `keepalive_pool_size`."
},
"ssl": {
"type": "boolean",
"description": "If set to true, uses SSL to connect to Redis.",
"default": false
},
"ssl_verify": {
"type": "boolean",
"description": "If set to true, verifies the validity of the server SSL certificate. If setting this parameter, also configure `lua_ssl_trusted_certificate` in `kong.conf` to specify the CA (or server) certificate used by your Redis server. You may also need to configure `lua_ssl_verify_depth` accordingly.",
"default": true
},
"password": {
"type": "string",
"description": "Password to use for Redis connections. If undefined, no AUTH commands are sent to Redis.",
"x-referenceable": true,
"x-encrypted": true
},
"sentinel_password": {
"type": "string",
"description": "Sentinel password to authenticate with a Redis Sentinel instance. If undefined, no AUTH commands are sent to Redis Sentinels.",
"x-referenceable": true,
"x-encrypted": true
},
"sentinel_nodes": {
"type": "array",
"items": {
"type": "object",
"properties": {
"host": {
"type": "string",
"description": "A string representing a host name, such as example.com.",
"default": "127.0.0.1"
},
"port": {
"type": "integer",
"maximum": 65535,
"minimum": 0,
"description": "An integer representing a port number between 0 and 65535, inclusive.",
"default": 6379
}
}
},
"minLength": 1,
"description": "Sentinel node addresses to use for Redis connections when the `redis` strategy is defined. Defining this field implies using a Redis Sentinel. The minimum length of the array is 1 element."
},
"connection_is_proxied": {
"type": "boolean",
"description": "If the connection to Redis is proxied (e.g. Envoy), set it `true`. Set the `host` and `port` to point to the proxy address.",
"default": false
},
"host": {
"type": "string",
"description": "A string representing a host name, such as example.com.",
"default": "127.0.0.1",
"x-referenceable": true
},
"port": {
"type": "integer",
"maximum": 65535,
"minimum": 0,
"description": "An integer representing a port number between 0 and 65535, inclusive.",
"default": 6379,
"x-referenceable": true
},
"send_timeout": {
"type": "integer",
"maximum": 2147483646,
"minimum": 0,
"description": "An integer representing a timeout in milliseconds. Must be between 0 and 2^31-2.",
"default": 2000
},
"database": {
"type": "integer",
"description": "Database to use for the Redis connection when using the `redis` strategy",
"default": 0
},
"keepalive_pool_size": {
"type": "integer",
"maximum": 2147483646,
"minimum": 1,
"description": "The size limit for every cosocket connection pool associated with every remote server, per worker process. If neither `keepalive_pool_size` nor `keepalive_backlog` is specified, no pool is created. If `keepalive_pool_size` isn't specified but `keepalive_backlog` is specified, then the pool uses the default value. Try to increase (e.g. 512) this value if latency is high or throughput is low.",
"default": 256
},
"server_name": {
"type": "string",
"description": "A string representing an SNI (server name indication) value for TLS.",
"x-referenceable": true
},
"cluster_max_redirections": {
"type": "integer",
"description": "Maximum retry attempts for redirection.",
"default": 5
},
"connect_timeout": {
"type": "integer",
"maximum": 2147483646,
"minimum": 0,
"description": "An integer representing a timeout in milliseconds. Must be between 0 and 2^31-2.",
"default": 2000
},
"read_timeout": {
"type": "integer",
"maximum": 2147483646,
"minimum": 0,
"description": "An integer representing a timeout in milliseconds. Must be between 0 and 2^31-2.",
"default": 2000
}
}
},
"custom_cost_count_function": {
"type": "string",
"description": "If defined, it uses custom function to generate cost for the inference request"
},
"identifier": {
"type": "string",
"enum": [
"consumer",
"consumer-group",
"credential",
"header",
"ip",
"path",
"service"
],
"description": "The type of identifier used to generate the rate limit key. Defines the scope used to increment the rate limiting counters. Can be `ip`, `credential`, `consumer`, `service`, `header`, `path` or `consumer-group`. Note if `identifier` is `consumer-group`, the policy must be applied on a consumer group entity. Because a consumer may belong to multiple consumer groups, the policy needs to know explicitly which consumer group to limit the rate.",
"default": "consumer"
},
"policies": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string",
"description": "UUID reference to a reusable ai_rate_limiting_policies DAO entity. Mutually exclusive with inline limits."
},
"match": {
"type": "array",
"items": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": [
"consumer",
"consumer_group",
"credential",
"header",
"ip",
"model",
"path",
"provider",
"service"
],
"description": "The attribute to match against."
},
"values": {
"type": "array",
"items": {
"type": "string"
},
"description": "Values to match. If omitted, matches any value of this type."
},
"key": {
"type": "string",
"description": "Sub-key for consumer (id|username|custom_id), consumer_group (id|name), service (id|name, defaults to id), or header (header name)."
},
"partition_by": {
"type": "boolean",
"description": "If true, the matched value contributes to the composite rate limit counter key.",
"default": false
}
},
"required": [
"type"
]
},
"description": "Array of match conditions (AND logic). If omitted, this policy acts as a fallback for unmatched requests."
},
"limits": {
"type": "array",
"items": {
"type": "object",
"properties": {
"limit": {
"type": "number",
"description": "The rate limit threshold for this window."
},
"window_size": {
"type": "integer",
"description": "The window size in seconds for fixed or sliding windows."
},
"period": {
"type": "string",
"enum": [
"month",
"week"
],
"description": "The calendar period for calendar windows."
},
"week_start_day": {
"type": "string",
"enum": [
"friday",
"monday",
"saturday",
"sunday",
"thursday",
"tuesday",
"wednesday"
],
"description": "Day the week starts for calendar weekly windows."
},
"month_day": {
"type": "integer",
"maximum": 31,
"minimum": 1,
"description": "Day of month the calendar monthly window starts (1-31)."
},
"tokens_count_strategy": {
"type": "string",
"enum": [
"completion_tokens",
"cost",
"prompt_tokens",
"total_tokens"
],
"description": "What to count for this limit. Supported strategies: total_tokens, prompt_tokens, completion_tokens, cost.",
"default": "total_tokens"
}
},
"required": [
"limit"
]
},
"minLength": 1,
"description": "Rate limits to enforce when this policy matches."
},
"window_type": {
"type": "string",
"enum": [
"calendar",
"fixed",
"sliding"
],
"description": "The time window type for this policy.",
"default": "sliding"
},
"timezone": {
"type": "string",
"description": "IANA timezone used for calendar window boundaries."
}
}
},
"minLength": 1,
"description": "Policy-based rate limiting. Each policy defines match conditions and limits."
},
"hide_client_headers": {
"type": "boolean",
"description": "Optionally hide informative response headers that would otherwise provide information about the current status of limits and counters.",
"default": false
},
"retry_after_jitter_max": {
"type": "number",
"description": "The upper bound of a jitter (random delay) in seconds to be added to the `Retry-After` header of denied requests (status = `429`) in order to prevent all the clients from coming back at the same time. The lower bound of the jitter is `0`; in this case, the `Retry-After` header is equal to the `RateLimit-Reset` header.",
"default": 0
},
"error_hide_providers": {
"type": "boolean",
"description": "Optionally hide informative response that would otherwise provide information about the provider in the error message.",
"default": false
},
"decrease_by_fractions_in_redis": {
"type": "boolean",
"description": "By default, Kong decreates the AI rate limiting counters by whole number in Redis. This setting allows to decrease the counters by float number.",
"default": false
},
"window_type": {
"type": "string",
"enum": [
"fixed",
"sliding"
],
"description": "Sets the time window type to either `sliding` (default) or `fixed`. Sliding windows apply the rate limiting logic while taking into account previous hit rates (from the window that immediately precedes the current) using a dynamic weight. Fixed windows consist of buckets that are statically assigned to a definitive time range, each request is mapped to only one fixed window based on its timestamp and will affect only that window's counters.",
"default": "sliding"
},
"sync_rate": {
"type": "number",
"description": "How often to sync counter data to the central data store. A value of 0 results in synchronous behavior; a value of -1 ignores sync behavior entirely and only stores counters in node memory. A value greater than 0 will sync the counters in the specified number of seconds. The minimum allowed interval is 0.02 seconds (20ms)."
},
"namespace": {
"type": "string",
"description": "The rate limiting library namespace to use for this policy instance. Counter data and sync configuration is isolated in each namespace. NOTE: For the policy instances sharing the same namespace, all the configurations that are required for synchronizing counters, e.g. `strategy`, `redis`, `sync_rate`, `dictionary_name`, need to be the same."
},
"dictionary_name": {
"type": "string",
"description": "The shared dictionary where counters are stored. When the policy is configured to synchronize counter data externally (that is `config.strategy` is `cluster` or `redis` and `config.sync_rate` isn't `-1`), this dictionary serves as a buffer to populate counters in the data store on each synchronization cycle. The dictionary must be defined in the nginx configuration using `lua_shared_dict` directive (e.g., `lua_shared_dict kong_rate_limiting_counters 12m`).",
"default": "kong_rate_limiting_counters"
},
"header_name": {
"type": "string",
"description": "A string representing an HTTP header name."
}
},
"required": [
"policies"
]
}
}
}
번역할 문서 조각이 아직 첨부되지 않았어요. Kong 문서 내용(마크다운)을 보내주시면 규칙에 따라 번역해 드릴게요.
관련 리소스
더 알아보기 (Learn more)
- 일반 트래픽을 대상으로 하는 Rate Limiting Advanced 정책의 구성 방법을 확인해요 — Rate Limiting Advanced Policy
- 모델별 토큰 비용을 관리해 비용 기반 제한을 더 정확하게 설정하는 방법을 알아봐요 — Model cost management
- 자주 요청되는 응답을 캐싱해 토큰 사용량과 비용을 줄이는 방법을 살펴봐요 — AI Semantic Cache Policy