Moderations
Enable OpenAI's moderation feature in your LLM applications to automatically detect and filter harmful content in user messages.
Legacy / Unsupported. The Cova-Moderations-Enabled request header was
supported by the legacy Cloudflare Worker proxy. It is not read by the
current AI Gateway (gateway/src/) and sending it has no effect. This page
is retained for historical reference only. See the
Header Directory
for the list of unsupported headers.
By integrating with OpenAI's moderation endpoint, CoreValue helps you check whether the user message is potentially harmful.
Why Moderations
- Identifying harmful requests and take action, for example, by filtering it.
- Ensuring any inappropriate or harmful content in user messages is flagged and prevented from being processed.
- Maintaining the safety of the interactions with your application.
Getting Started
Moderations currently work with OpenAI models only (gpt-4o, gpt-4o-mini, etc.) as it uses OpenAI's moderation endpoint.
To enable moderation, set Cova-Moderations-Enabled to true.
curl https://gateway.corevalue.dev/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $COVA_API_KEY" \
-H "Cova-Moderations-Enabled: true" \ # Add this header and set to true
-d '{
"model": "gpt-4o-mini",
"messages": [
{
"role": "user",
"content": "How do I enable moderations?"
}
]
}'from openai import OpenAI
import os
client = OpenAI(
base_url="https://gateway.corevalue.dev/v1",
api_key=os.getenv("COVA_API_KEY"),
)
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "How do I enable moderations?"}],
extra_headers={
"Cova-Moderations-Enabled": "true", # Add this header and set to true
}
)import { OpenAI } from "openai";
const client = new OpenAI({
baseURL: "https://gateway.corevalue.dev/v1",
apiKey: process.env.COVA_API_KEY,
});
const response = await client.chat.completions.create(
{
model: "gpt-4o-mini",
messages: [{ role: "user", content: "How do I enable moderations?" }]
},
{
headers: {
"Cova-Moderations-Enabled": "true", // Add this header and set to true
}
}
);The moderation call to the OpenAI endpoint will utilize your OpenAI API key configured in CoreValue.
Error Repsonse
If the message is flagged, the response will have a 400 status code. It's crucial to handle this response appropriately.
If the message is not flagged, the proxy forwards it to the chat completion endpoint, and the process continues as normal.
Here's an example of the error response when flagged:
{
"success": false,
"error": {
"code": "PROMPT_FLAGGED_FOR_MODERATION",
"message": "The given prompt was flagged by the OpenAI Moderation endpoint.",
"details": "See your CoreValue request page for more info: https://www.corevalue.dev/requests?[REQUEST_ID]"
}
}Coming Soon
We're continually expanding our moderation features. Upcoming updates include:
- Customizable moderation criteria