Block request and response content using Mistral AI moderation
Configure the AI Custom Guardrail policy to check requests and responses, and block content matching using Mistral AI.
Prerequisites
-
You have a Mistral AI account.
-
An existing AI Model.
Environment variables
-
MISTRAL_API_KEY: The API key to access Mistral AI. -
MISTRAL_MODEL: The Mistral AI model to use for moderation.
ai_gateway_policies:
- ref: mistral-moderation
ai_gateway: !lookup {id: !env AI_GATEWAY_ID}
name: mistral-moderation
display_name: Block request and response content using Mistral AI moderation
type: ai-custom-guardrail
enabled: true
config:
guarding_mode: BOTH
text_source: concatenate_all_content
params:
api_key: !env MISTRAL_API_KEY
model: !env MISTRAL_MODEL
request:
url: https://api.mistral.ai/v1/moderations
headers:
Authorization: Bearer $(conf.params.api_key)
body:
model: "$(conf.params.model)"
input: "$(content)"
response:
block: "$(check_response.block)"
block_message: "$(check_response.block_message)"
functions:
check_response: "return function(resp)\n local blocked_categories = {}\n
\ \n for _, result in ipairs(resp.results) do\n for category,
is_flagged in pairs(result.categories) do\n if is_flagged then\n
\ table.insert(blocked_categories, category)\n end\n
\ end\n end\n \n local block = #blocked_categories > 0\n local
reason\n\n if block then\n reason = \"Content moderation failed in
the following categories: \" .. table.concat(blocked_categories, \", \")\n
\ else\n reason = \"Content moderation passed\"\n end\n \n return
{\n block = block,\n block_message = reason\n }\nend\n"
global: falseMake sure to replace the following placeholders with your own values:
-
AI_GATEWAY_ID: Theidof your AI Gateway. -
!env MISTRAL_API_KEY: The API key to access Mistral AI. -
!env MISTRAL_MODEL: The Mistral AI model to use for moderation.
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 '
{
"name": "mistral-moderation",
"display_name": "Block request and response content using Mistral AI moderation",
"type": "ai-custom-guardrail",
"enabled": true,
"config": {
"guarding_mode": "BOTH",
"text_source": "concatenate_all_content",
"params": {
"api_key": "'$MISTRAL_API_KEY'",
"model": "'$MISTRAL_MODEL'"
},
"request": {
"url": "https://api.mistral.ai/v1/moderations",
"headers": {
"Authorization": "Bearer $(conf.params.api_key)"
},
"body": {
"model": "$(conf.params.model)",
"input": "$(content)"
}
},
"response": {
"block": "$(check_response.block)",
"block_message": "$(check_response.block_message)"
},
"functions": {
"check_response": "return function(resp)\n local blocked_categories = {}\n \n for _, result in ipairs(resp.results) do\n for category, is_flagged in pairs(result.categories) do\n if is_flagged then\n table.insert(blocked_categories, category)\n end\n end\n end\n \n local block = #blocked_categories > 0\n local reason\n\n if block then\n reason = \"Content moderation failed in the following categories: \" .. table.concat(blocked_categories, \", \")\n else\n reason = \"Content moderation passed\"\n end\n \n return {\n block = block,\n block_message = reason\n }\nend\n"
}
},
"global": 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: Theidof the AI Gateway.
See the Konnect AI Gateway API reference to learn about region-specific URLs and personal access tokens.
Prerequisite: Configure your Personal Access Token
terraform {
required_providers {
konnect = {
source = "kong/konnect"
}
}
}
provider "konnect" {
personal_access_token = "$KONNECT_TOKEN"
server_url = "https://us.api.konghq.com/"
}Add the following to your Terraform configuration:
resource "konnect_ai_gateway_policy" "my_policy" {
name = "mistral-moderation"
display_name = "Block request and response content using Mistral AI moderation"
type = "ai-custom-guardrail"
enabled = true
global = false
config = jsonencode({
guarding_mode = "BOTH"
text_source = "concatenate_all_content"
params = {
api_key = var.mistral_api_key
model = var.mistral_model
}
request = {
url = "https://api.mistral.ai/v1/moderations"
headers = {
Authorization = "Bearer $(conf.params.api_key)"
}
body = {
model = "$(conf.params.model)"
input = "$(content)"
}
}
response = {
block = "$(check_response.block)"
block_message = "$(check_response.block_message)"
}
functions = {
check_response = <<EOF
return function(resp)
local blocked_categories = {}
for _, result in ipairs(resp.results) do
for category, is_flagged in pairs(result.categories) do
if is_flagged then
table.insert(blocked_categories, category)
end
end
end
local block = #blocked_categories > 0
local reason
if block then
reason = "Content moderation failed in the following categories: " .. table.concat(blocked_categories, ", ")
else
reason = "Content moderation passed"
end
return {
block = block,
block_message = reason
}
end
EOF
}
})
gateway_id = konnect_ai_gateway.my_ai_gateway.id
}This example requires the following variables to be added to your manifest. You can specify values at runtime by setting TF_VAR_name=value.
variable "mistral_api_key" {
type = string
}
variable "mistral_model" {
type = string
}ai_gateway_policies:
- ref: mistral-moderation
ai_gateway: !lookup {id: !env AI_GATEWAY_ID}
name: mistral-moderation
display_name: Block request and response content using Mistral AI moderation
type: ai-custom-guardrail
enabled: true
config:
guarding_mode: BOTH
text_source: concatenate_all_content
params:
api_key: !env MISTRAL_API_KEY
model: !env MISTRAL_MODEL
request:
url: https://api.mistral.ai/v1/moderations
headers:
Authorization: Bearer $(conf.params.api_key)
body:
model: "$(conf.params.model)"
input: "$(content)"
response:
block: "$(check_response.block)"
block_message: "$(check_response.block_message)"
functions:
check_response: "return function(resp)\n local blocked_categories = {}\n
\ \n for _, result in ipairs(resp.results) do\n for category,
is_flagged in pairs(result.categories) do\n if is_flagged then\n
\ table.insert(blocked_categories, category)\n end\n
\ end\n end\n \n local block = #blocked_categories > 0\n local
reason\n\n if block then\n reason = \"Content moderation failed in
the following categories: \" .. table.concat(blocked_categories, \", \")\n
\ else\n reason = \"Content moderation passed\"\n end\n \n return
{\n block = block,\n block_message = reason\n }\nend\n"
global: falseMake sure to replace the following placeholders with your own values:
-
AI_GATEWAY_ID: Theidof your AI Gateway. -
!env MISTRAL_API_KEY: The API key to access Mistral AI. -
!env MISTRAL_MODEL: The Mistral AI model to use for moderation.
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 '
{
"name": "mistral-moderation",
"display_name": "Block request and response content using Mistral AI moderation",
"type": "ai-custom-guardrail",
"enabled": true,
"config": {
"guarding_mode": "BOTH",
"text_source": "concatenate_all_content",
"params": {
"api_key": "'$MISTRAL_API_KEY'",
"model": "'$MISTRAL_MODEL'"
},
"request": {
"url": "https://api.mistral.ai/v1/moderations",
"headers": {
"Authorization": "Bearer $(conf.params.api_key)"
},
"body": {
"model": "$(conf.params.model)",
"input": "$(content)"
}
},
"response": {
"block": "$(check_response.block)",
"block_message": "$(check_response.block_message)"
},
"functions": {
"check_response": "return function(resp)\n local blocked_categories = {}\n \n for _, result in ipairs(resp.results) do\n for category, is_flagged in pairs(result.categories) do\n if is_flagged then\n table.insert(blocked_categories, category)\n end\n end\n end\n \n local block = #blocked_categories > 0\n local reason\n\n if block then\n reason = \"Content moderation failed in the following categories: \" .. table.concat(blocked_categories, \", \")\n else\n reason = \"Content moderation passed\"\n end\n \n return {\n block = block,\n block_message = reason\n }\nend\n"
}
},
"global": 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: Theidof the AI Gateway.
See the Konnect AI Gateway API reference to learn about region-specific URLs and personal access tokens.
Prerequisite: Configure your Personal Access Token
terraform {
required_providers {
konnect = {
source = "kong/konnect"
}
}
}
provider "konnect" {
personal_access_token = "$KONNECT_TOKEN"
server_url = "https://us.api.konghq.com/"
}Add the following to your Terraform configuration:
resource "konnect_ai_gateway_policy" "my_policy" {
name = "mistral-moderation"
display_name = "Block request and response content using Mistral AI moderation"
type = "ai-custom-guardrail"
enabled = true
global = false
config = jsonencode({
guarding_mode = "BOTH"
text_source = "concatenate_all_content"
params = {
api_key = var.mistral_api_key
model = var.mistral_model
}
request = {
url = "https://api.mistral.ai/v1/moderations"
headers = {
Authorization = "Bearer $(conf.params.api_key)"
}
body = {
model = "$(conf.params.model)"
input = "$(content)"
}
}
response = {
block = "$(check_response.block)"
block_message = "$(check_response.block_message)"
}
functions = {
check_response = <<EOF
return function(resp)
local blocked_categories = {}
for _, result in ipairs(resp.results) do
for category, is_flagged in pairs(result.categories) do
if is_flagged then
table.insert(blocked_categories, category)
end
end
end
local block = #blocked_categories > 0
local reason
if block then
reason = "Content moderation failed in the following categories: " .. table.concat(blocked_categories, ", ")
else
reason = "Content moderation passed"
end
return {
block = block,
block_message = reason
}
end
EOF
}
})
gateway_id = konnect_ai_gateway.my_ai_gateway.id
}This example requires the following variables to be added to your manifest. You can specify values at runtime by setting TF_VAR_name=value.
variable "mistral_api_key" {
type = string
}
variable "mistral_model" {
type = string
}ai_gateway_policies:
- ref: mistral-moderation
ai_gateway: !lookup {id: !env AI_GATEWAY_ID}
name: mistral-moderation
display_name: Block request and response content using Mistral AI moderation
type: ai-custom-guardrail
enabled: true
config:
guarding_mode: BOTH
text_source: concatenate_all_content
params:
api_key: !env MISTRAL_API_KEY
model: !env MISTRAL_MODEL
request:
url: https://api.mistral.ai/v1/moderations
headers:
Authorization: Bearer $(conf.params.api_key)
body:
model: "$(conf.params.model)"
input: "$(content)"
response:
block: "$(check_response.block)"
block_message: "$(check_response.block_message)"
functions:
check_response: "return function(resp)\n local blocked_categories = {}\n
\ \n for _, result in ipairs(resp.results) do\n for category,
is_flagged in pairs(result.categories) do\n if is_flagged then\n
\ table.insert(blocked_categories, category)\n end\n
\ end\n end\n \n local block = #blocked_categories > 0\n local
reason\n\n if block then\n reason = \"Content moderation failed in
the following categories: \" .. table.concat(blocked_categories, \", \")\n
\ else\n reason = \"Content moderation passed\"\n end\n \n return
{\n block = block,\n block_message = reason\n }\nend\n"
global: falseMake sure to replace the following placeholders with your own values:
-
AI_GATEWAY_ID: Theidof your AI Gateway. -
!env MISTRAL_API_KEY: The API key to access Mistral AI. -
!env MISTRAL_MODEL: The Mistral AI model to use for moderation.
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 '
{
"name": "mistral-moderation",
"display_name": "Block request and response content using Mistral AI moderation",
"type": "ai-custom-guardrail",
"enabled": true,
"config": {
"guarding_mode": "BOTH",
"text_source": "concatenate_all_content",
"params": {
"api_key": "'$MISTRAL_API_KEY'",
"model": "'$MISTRAL_MODEL'"
},
"request": {
"url": "https://api.mistral.ai/v1/moderations",
"headers": {
"Authorization": "Bearer $(conf.params.api_key)"
},
"body": {
"model": "$(conf.params.model)",
"input": "$(content)"
}
},
"response": {
"block": "$(check_response.block)",
"block_message": "$(check_response.block_message)"
},
"functions": {
"check_response": "return function(resp)\n local blocked_categories = {}\n \n for _, result in ipairs(resp.results) do\n for category, is_flagged in pairs(result.categories) do\n if is_flagged then\n table.insert(blocked_categories, category)\n end\n end\n end\n \n local block = #blocked_categories > 0\n local reason\n\n if block then\n reason = \"Content moderation failed in the following categories: \" .. table.concat(blocked_categories, \", \")\n else\n reason = \"Content moderation passed\"\n end\n \n return {\n block = block,\n block_message = reason\n }\nend\n"
}
},
"global": 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: Theidof the AI Gateway.
See the Konnect AI Gateway API reference to learn about region-specific URLs and personal access tokens.
Prerequisite: Configure your Personal Access Token
terraform {
required_providers {
konnect = {
source = "kong/konnect"
}
}
}
provider "konnect" {
personal_access_token = "$KONNECT_TOKEN"
server_url = "https://us.api.konghq.com/"
}Add the following to your Terraform configuration:
resource "konnect_ai_gateway_policy" "my_policy" {
name = "mistral-moderation"
display_name = "Block request and response content using Mistral AI moderation"
type = "ai-custom-guardrail"
enabled = true
global = false
config = jsonencode({
guarding_mode = "BOTH"
text_source = "concatenate_all_content"
params = {
api_key = var.mistral_api_key
model = var.mistral_model
}
request = {
url = "https://api.mistral.ai/v1/moderations"
headers = {
Authorization = "Bearer $(conf.params.api_key)"
}
body = {
model = "$(conf.params.model)"
input = "$(content)"
}
}
response = {
block = "$(check_response.block)"
block_message = "$(check_response.block_message)"
}
functions = {
check_response = <<EOF
return function(resp)
local blocked_categories = {}
for _, result in ipairs(resp.results) do
for category, is_flagged in pairs(result.categories) do
if is_flagged then
table.insert(blocked_categories, category)
end
end
end
local block = #blocked_categories > 0
local reason
if block then
reason = "Content moderation failed in the following categories: " .. table.concat(blocked_categories, ", ")
else
reason = "Content moderation passed"
end
return {
block = block,
block_message = reason
}
end
EOF
}
})
gateway_id = konnect_ai_gateway.my_ai_gateway.id
}This example requires the following variables to be added to your manifest. You can specify values at runtime by setting TF_VAR_name=value.
variable "mistral_api_key" {
type = string
}
variable "mistral_model" {
type = string
}ai_gateway_policies:
- ref: mistral-moderation
ai_gateway: !lookup {id: !env AI_GATEWAY_ID}
name: mistral-moderation
display_name: Block request and response content using Mistral AI moderation
type: ai-custom-guardrail
enabled: true
config:
guarding_mode: BOTH
text_source: concatenate_all_content
params:
api_key: !env MISTRAL_API_KEY
model: !env MISTRAL_MODEL
request:
url: https://api.mistral.ai/v1/moderations
headers:
Authorization: Bearer $(conf.params.api_key)
body:
model: "$(conf.params.model)"
input: "$(content)"
response:
block: "$(check_response.block)"
block_message: "$(check_response.block_message)"
functions:
check_response: "return function(resp)\n local blocked_categories = {}\n
\ \n for _, result in ipairs(resp.results) do\n for category,
is_flagged in pairs(result.categories) do\n if is_flagged then\n
\ table.insert(blocked_categories, category)\n end\n
\ end\n end\n \n local block = #blocked_categories > 0\n local
reason\n\n if block then\n reason = \"Content moderation failed in
the following categories: \" .. table.concat(blocked_categories, \", \")\n
\ else\n reason = \"Content moderation passed\"\n end\n \n return
{\n block = block,\n block_message = reason\n }\nend\n"
global: trueMake sure to replace the following placeholders with your own values:
-
AI_GATEWAY_ID: Theidof your AI Gateway. -
!env MISTRAL_API_KEY: The API key to access Mistral AI. -
!env MISTRAL_MODEL: The Mistral AI model to use for moderation.
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 '
{
"name": "mistral-moderation",
"display_name": "Block request and response content using Mistral AI moderation",
"type": "ai-custom-guardrail",
"enabled": true,
"config": {
"guarding_mode": "BOTH",
"text_source": "concatenate_all_content",
"params": {
"api_key": "'$MISTRAL_API_KEY'",
"model": "'$MISTRAL_MODEL'"
},
"request": {
"url": "https://api.mistral.ai/v1/moderations",
"headers": {
"Authorization": "Bearer $(conf.params.api_key)"
},
"body": {
"model": "$(conf.params.model)",
"input": "$(content)"
}
},
"response": {
"block": "$(check_response.block)",
"block_message": "$(check_response.block_message)"
},
"functions": {
"check_response": "return function(resp)\n local blocked_categories = {}\n \n for _, result in ipairs(resp.results) do\n for category, is_flagged in pairs(result.categories) do\n if is_flagged then\n table.insert(blocked_categories, category)\n end\n end\n end\n \n local block = #blocked_categories > 0\n local reason\n\n if block then\n reason = \"Content moderation failed in the following categories: \" .. table.concat(blocked_categories, \", \")\n else\n reason = \"Content moderation passed\"\n end\n \n return {\n block = block,\n block_message = reason\n }\nend\n"
}
},
"global": true
}
'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: Theidof the AI Gateway.
See the Konnect AI Gateway API reference to learn about region-specific URLs and personal access tokens.
Prerequisite: Configure your Personal Access Token
terraform {
required_providers {
konnect = {
source = "kong/konnect"
}
}
}
provider "konnect" {
personal_access_token = "$KONNECT_TOKEN"
server_url = "https://us.api.konghq.com/"
}Add the following to your Terraform configuration:
resource "konnect_ai_gateway_policy" "my_policy" {
name = "mistral-moderation"
display_name = "Block request and response content using Mistral AI moderation"
type = "ai-custom-guardrail"
enabled = true
global = true
config = jsonencode({
guarding_mode = "BOTH"
text_source = "concatenate_all_content"
params = {
api_key = var.mistral_api_key
model = var.mistral_model
}
request = {
url = "https://api.mistral.ai/v1/moderations"
headers = {
Authorization = "Bearer $(conf.params.api_key)"
}
body = {
model = "$(conf.params.model)"
input = "$(content)"
}
}
response = {
block = "$(check_response.block)"
block_message = "$(check_response.block_message)"
}
functions = {
check_response = <<EOF
return function(resp)
local blocked_categories = {}
for _, result in ipairs(resp.results) do
for category, is_flagged in pairs(result.categories) do
if is_flagged then
table.insert(blocked_categories, category)
end
end
end
local block = #blocked_categories > 0
local reason
if block then
reason = "Content moderation failed in the following categories: " .. table.concat(blocked_categories, ", ")
else
reason = "Content moderation passed"
end
return {
block = block,
block_message = reason
}
end
EOF
}
})
gateway_id = konnect_ai_gateway.my_ai_gateway.id
}This example requires the following variables to be added to your manifest. You can specify values at runtime by setting TF_VAR_name=value.
variable "mistral_api_key" {
type = string
}
variable "mistral_model" {
type = string
}After creating the policy, add mistral-moderation to the policies array of your AI Model. The tool examples update an existing AI Model with the policy attached: replace the entity configuration in the example with your own, as the update replaces the entire AI Model.
ai_gateway_models:
- ref: my-gpt-4o
ai_gateway: !lookup {id: !env AI_GATEWAY_ID}
display_name: my-gpt-4o
name: my-gpt-4o
type: model
capabilities:
- generate
formats:
- type: openai
targets:
- name: gpt-4o
provider: my-openai-account
config:
type: openai
config:
route:
paths:
- "/v1"
model:
body_param: model
values:
- my-gpt-4o
logging:
payloads: false
policies:
- !ref mistral-moderation#nameAfter creating the policy, add mistral-moderation to the policies array of your AI Model. The tool examples update an existing AI Model with the policy attached: replace the entity configuration in the example with your own, as the update replaces the entire AI Model.
curl -X PUT https://{region}.api.konghq.com/v1/ai-gateways/{AIGatewayId}/models/my-gpt-4o \
--header "accept: application/json" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $KONNECT_TOKEN" \
--data '
{
"display_name": "my-gpt-4o",
"name": "my-gpt-4o",
"type": "model",
"capabilities": [
"generate"
],
"formats": [
{
"type": "openai"
}
],
"policies": [
"mistral-moderation"
],
"targets": [
{
"name": "gpt-4o",
"provider": "my-openai-account",
"config": {
"type": "openai"
}
}
],
"config": {
"route": {
"paths": [
"/v1"
],
"model": {
"body_param": "model",
"values": [
"my-gpt-4o"
]
}
},
"logging": {
"payloads": false
}
}
}
'After creating the policy, add mistral-moderation to the policies array of your AI Model. The tool examples update an existing AI Model with the policy attached: replace the entity configuration in the example with your own, as the update replaces the entire AI Model.
resource "konnect_ai_gateway_model" "my_model" {
display_name = "my-gpt-4o"
name = "my-gpt-4o"
type = "model"
capabilities = ["generate"]
formats = [
{
type = "openai"
} ]
targets = [
{
name = "gpt-4o"
provider = "my-openai-account"
config = {
type = "openai"
}
} ]
config = jsonencode({
route = {
paths = ["/v1"]
model = {
body_param = "model"
values = ["my-gpt-4o"]
}
}
logging = {
payloads = false
}
})
policies = [konnect_ai_gateway_policy.my_policy.name]
gateway_id = konnect_ai_gateway.my_ai_gateway.id
}This example requires the following variables to be added to your manifest. You can specify values at runtime by setting TF_VAR_name=value.
variable "mistral_api_key" {
type = string
}
variable "mistral_model" {
type = string
}After creating the policy, add mistral-moderation to the policies array of your AI Consumer. The tool examples update an existing AI Consumer with the policy attached: replace the entity configuration in the example with your own, as the update replaces the entire AI Consumer.
ai_gateway_consumers:
- ref: mobile-app-production
ai_gateway: !lookup {id: !env AI_GATEWAY_ID}
display_name: Mobile App - Production
name: mobile-app-production
type: api-key
policies:
- !ref mistral-moderation#nameAfter creating the policy, add mistral-moderation to the policies array of your AI Consumer. The tool examples update an existing AI Consumer with the policy attached: replace the entity configuration in the example with your own, as the update replaces the entire AI Consumer.
curl -X PUT https://{region}.api.konghq.com/v1/ai-gateways/{AIGatewayId}/consumers/mobile-app-production \
--header "accept: application/json" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $KONNECT_TOKEN" \
--data '
{
"display_name": "Mobile App - Production",
"name": "mobile-app-production",
"type": "api-key",
"policies": [
"mistral-moderation"
]
}
'After creating the policy, add mistral-moderation to the policies array of your AI Consumer. The tool examples update an existing AI Consumer with the policy attached: replace the entity configuration in the example with your own, as the update replaces the entire AI Consumer.
resource "konnect_ai_gateway_consumer" "my_consumer" {
display_name = "Mobile App - Production"
name = "mobile-app-production"
type = "api-key"
policies = [konnect_ai_gateway_policy.my_policy.name]
gateway_id = konnect_ai_gateway.my_ai_gateway.id
}This example requires the following variables to be added to your manifest. You can specify values at runtime by setting TF_VAR_name=value.
variable "mistral_api_key" {
type = string
}
variable "mistral_model" {
type = string
}After creating the policy, add mistral-moderation to the policies array of your AI Consumer Group. The tool examples update an existing AI Consumer Group with the policy attached: replace the entity configuration in the example with your own, as the update replaces the entire AI Consumer Group.
ai_gateway_consumer_groups:
- ref: internal-teams
ai_gateway: !lookup {id: !env AI_GATEWAY_ID}
display_name: Internal Teams
name: internal-teams
policies:
- !ref mistral-moderation#nameAfter creating the policy, add mistral-moderation to the policies array of your AI Consumer Group. The tool examples update an existing AI Consumer Group with the policy attached: replace the entity configuration in the example with your own, as the update replaces the entire AI Consumer Group.
curl -X PUT https://{region}.api.konghq.com/v1/ai-gateways/{AIGatewayId}/consumer-groups/internal-teams \
--header "accept: application/json" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $KONNECT_TOKEN" \
--data '
{
"display_name": "Internal Teams",
"name": "internal-teams",
"policies": [
"mistral-moderation"
]
}
'After creating the policy, add mistral-moderation to the policies array of your AI Consumer Group. The tool examples update an existing AI Consumer Group with the policy attached: replace the entity configuration in the example with your own, as the update replaces the entire AI Consumer Group.
resource "konnect_ai_gateway_consumer_group" "my_consumer_group" {
display_name = "Internal Teams"
name = "internal-teams"
policies = [konnect_ai_gateway_policy.my_policy.name]
gateway_id = konnect_ai_gateway.my_ai_gateway.id
}This example requires the following variables to be added to your manifest. You can specify values at runtime by setting TF_VAR_name=value.
variable "mistral_api_key" {
type = string
}
variable "mistral_model" {
type = string
}