AI Rate Limiting Advanced Policy

Request prompt function with AWS ElastiCache instance auth

Protect your LLM services with rate limiting and AWS ElastiCache instance auth. The AI Rate Limiting Advanced Policy analyzes query costs and token responses to provide an enterprise-grade rate limiting strategy.

The following example uses request prompt rate limiting, which lets you rate limit requests based on a custom token.

Prerequisites

  • An existing AI Model.

  • A running Redis instance on an AWS ElastiCache instance for Valkey 7.2 or later or ElastiCache for Redis OSS version 7.0 or later..

  • Port 6379, or your custom Redis port, is open and reachable from AI Gateway.

  • The ElastiCache user needs to set “Authentication mode” to “IAM”..

  • The following policy assigned to the IAM user/IAM role that is used to connect to the ElastiCache:

    {
      "Version": "2012-10-17",
      "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "elasticache:Connect"
            ],
            "Resource": [
                "arn:aws:elasticache:ARN_OF_THE_ELASTICACHE",
                "arn:aws:elasticache:ARN_OF_THE_ELASTICACHE_USER"
            ]
        }
    ]
    }

Environment variables

  • INSTANCE_ADDRESS: The ElastiCache instance address.

  • INSTANCE_USERNAME: The ElastiCache username with IAM Auth mode configured.

  • AWS_CACHE_NAME: Name of your AWS ElastiCache instance.

  • AWS_REGION: Your AWS ElastiCache instance region.

  • AWS_ACCESS_KEY_ID: (Optional) Your AWS access key ID.

  • AWS_ACCESS_SECRET_KEY: (Optional) Your AWS secret access key.

Set up the policy

Attach the policy

Help us make these docs great!

Kong Developer docs are open source. If you find these useful and want to make them better, contribute today!