Moderations
Classify text against content-safety categories with the cruxy-guard model.
POST /api/v1/moderations checks text against the content-safety
categories and returns whether each one matched, plus an overall
flagged. It is OpenAI-compatible. Here is a single-string check:
curl https://api.cruxy.ai/api/v1/moderations \
-H "Authorization: Bearer $CRUXY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "cruxy-guard",
"input": "I want to learn how to bake bread."
}'const res = await fetch('https://api.cruxy.ai/api/v1/moderations', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.CRUXY_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: 'cruxy-guard',
input: 'I want to learn how to bake bread.',
}),
})
const { results } = await res.json()
if (results[0].flagged) {
// handle flagged content
}import { Cruxy } from '@cruxy/api'
const cruxy = new Cruxy({ bearerAuth: process.env.CRUXY_API_KEY })
// The SDK's `input` is an array: send one string as a one-element array.
const { result } = await cruxy.moderations.createModeration({
body: { model: 'cruxy-guard', input: ['I want to learn how to bake bread.'] },
})
if (result.results[0]?.flagged) {
// handle flagged content
}The model
model must be "cruxy-guard". It is the only moderation model on the
gateway.
Single string or array
input accepts a single string or an array of strings. With an array,
results holds one entry per input, in order.
Response shape
{
"id": "modr-a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"model": "cruxy-guard",
"results": [
{
"flagged": false,
"categories": { "example_category": false },
"category_scores": { "example_category": 0.0 }
}
]
}| Field | Meaning |
|---|---|
flagged | true when the guard flagged the input. Check this first. A flagged result can have every category false; cruxy.hazard_codes on the result then names the guard's own codes. |
categories | Map of category name to a boolean: whether that category matched. |
category_scores | Map of category name to a score. See the caveat below. |
cruxy.hazard_codes holds the guard's raw codes (MLCommons S-codes),
uppercased, in the order the guard emitted them. Nine of the fourteen codes map
onto an OpenAI category. The other five map onto none: S6 (specialized
advice), S7 (privacy), S8 (intellectual property), S13 (elections), and
S14 (code interpreter abuse). That is why a flagged result can have every
category false. On a flagged result the list is never null and may be empty,
when the guard flagged the input without naming a code; an unflagged result
has no cruxy key.
categories and category_scores share the same keys, one per
moderation category. The keys shown above are illustrative; treat the
category set as whatever the response returns rather than a fixed list.
category_scores is binary
The scores are not calibrated probabilities. The guard model emits
labels, not likelihoods, so each value in category_scores is either
1.0 or 0.0, the same information as the boolean in categories,
expressed as a number. Do not threshold these scores or read them as
confidence. To decide whether to act, use flagged (or the per-category
booleans in categories). To run this check in front of a chat call, see
the Moderation gate recipe.
Errors
Moderations returns 400 for a malformed request, 401 for a bad key,
429 for rate_limited or a spend cap (key_spend_cap_exceeded,
workspace_spend_cap_exceeded, credits_exhausted), never budget_exhausted,
and the model failures, which nothing bills: 502 upstream_error (the provider
rejected the request; it fails the same way again, so do not retry it), 503
upstream_overloaded, model_unavailable, service_unavailable,
server_shutting_down, or limits_unavailable, and 504 upstream_timeout.
Retry the 503s and the 504 with backoff; see
Embeddings, rerank, and moderations.
Errors lists every code.
Next steps
- Moderation gate: screen input before it reaches chat.
- Chat: completions across the tiers.
- Errors: the error shape.