An AI Policy specifies a type (like AI Sanitizer or AI Rate Limiting Advanced) and a config block that configures that behavior. AI Gateway applies the policy at the scope you choose: globally across all traffic, or scoped to a specific entity.
The following example creates a global AI PII Sanitizer Policy that runs for every AI Gateway Route. It anonymizes high-risk PII categories (email, phone, SSN, and credit cards) along with custom patterns for sensitive tokens like AWS API keys and GitHub tokens.
This Policy connects to an AI PII Anonymizer service at host/port (sanitizer-service.internal:8080 in this example) to perform the actual sanitization. Substitute the address of your own running instance. See AI PII Anonymizer service for image access and setup instructions.
Without a reachable service at that address, requests through this Policy will fail.
curl -X POST https://{region}.api.konghq.com/v1/ai-gateways/{AIGatewayId}/policies \
--header "accept: application/json" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $KONNECT_TOKEN" \
--data '
{
"display_name": "PII Sanitizer - Global",
"name": "pii-sanitizer-global",
"type": "ai-sanitizer",
"enabled": true,
"global": true,
"config": {
"anonymize": [
"email",
"phone",
"ssn",
"creditcard",
"custom"
],
"custom_patterns": [
{
"name": "aws_api_key",
"regex": "AKIA[0-9A-Z]{16}",
"score": 0.95
},
{
"name": "github_token",
"regex": "ghp_[A-Za-z0-9]{36}",
"score": 0.9
}
],
"host": "sanitizer-service.internal",
"port": 8080,
"redact_type": "placeholder",
"stop_on_error": true,
"recover_redacted": false
}
}
'
Make sure to replace the following placeholders with your own values:
-
region: Geographic region where your Kong Konnect is hosted and operates.
-
KONNECT_TOKEN: Your Personal Access Token (PAT) associated with your Konnect account.
-
AIGatewayId: The id of the AI Gateway.
See the Konnect AI Gateway API reference to learn about region-specific URLs and personal access tokens.
ai_gateway_policies:
- ref: pii-sanitizer-global
ai_gateway: !lookup {id: !env AI_GATEWAY_ID}
display_name: PII Sanitizer - Global
name: pii-sanitizer-global
type: ai-sanitizer
enabled: true
global: true
config:
anonymize:
- email
- phone
- ssn
- creditcard
- custom
custom_patterns:
- name: aws_api_key
regex: AKIA[0-9A-Z]{16}
score: 0.95
- name: github_token
regex: ghp_[A-Za-z0-9]{36}
score: 0.9
host: sanitizer-service.internal
port: 8080
redact_type: placeholder
stop_on_error: true
recover_redacted: false
Make sure to replace the following placeholders with your own values:
-
AI_GATEWAY_ID: The id of your AI Gateway.
UI instructions are not yet available for this AI Gateway entity type.