Overview
Inline moderation lets authenticated API-key callers ask NanoGPT to run a paid input safety check before a text, image, or video generation request is dispatched to the target model provider. It is opt-in per request and configured with HTTP headers. If the submitted input is flagged, NanoGPT charges only the moderation check, skips generation, and returns a content policy error. If the input passes, NanoGPT charges the moderation check, then continues with the normal generation request and normal generation billing. Inline moderation is an input preflight only. It does not moderate generated outputs.Supported Routes
Inline moderation is supported on authenticated API-key requests to:POST /api/v1/chat/completionsPOST /api/v1/responsesPOST /api/v1/completionsPOST /api/v1/messagesPOST /api/v1/images/generationsPOST /api/v1/images/edits- NanoGPT image generation compatibility routes that flow through the canonical image handler
- NanoGPT video generation requests that flow through the canonical video handler
Enabling Inline Moderation
Use themoderation header.
To enable moderation with the default moderation model:
true1yeson
false0nooff
Selecting a Moderation Model
Supported moderation model IDs are listed by:moderation header:
moderation: true and select the model with moderation-model:
moderation-model only selects the model when the moderation header is also present. A request with only moderation-model does not enable inline moderation.
If both headers specify model IDs and they differ, the request fails:
model_not_found behavior.
What Gets Moderated
Inline moderation checks user-facing request input before generation. For text APIs, NanoGPT moderates:- chat messages
- Responses API instructions
- Responses API input, including merged
conversation.messagesandprevious_response_idhistory when applicable - Responses API text content parts such as
input_text,output_text, and tool output text - completions prompts, including prompt arrays
- image content parts when they are provided as HTTP(S) image URLs or
data:image/...URLs
prompt- multi-prompt text fields
- submitted images
- reference images
- start/end/first/last frame images when those fields are used
data:image/... URLs. If a request includes an image input that cannot be inspected, such as a bare base64 string or a provider-specific file/asset reference, inline moderation fails closed with unsupported_moderation_input.
NanoGPT does not moderate:
- generated outputs
- raw video inputs
- provider configuration fields
negative_prompt- arbitrary non-user-facing model configuration
empty_moderation_input.
Billing Behavior
Inline moderation is a separate paid preflight. If the moderation check passes:- NanoGPT charges the moderation request.
- NanoGPT continues with normal generation.
- Normal generation billing still applies.
- NanoGPT charges the moderation request.
- NanoGPT does not dispatch the generation request to the target provider.
- NanoGPT does not charge generation.
- The response is
400 content_policy_violation.
- NanoGPT fails closed with
503. - NanoGPT does not charge moderation.
- NanoGPT does not dispatch generation.
- NanoGPT does not charge generation.
Response Headers
When inline moderation runs and the request is not blocked, successful moderated generation responses include moderation metadata headers:Blocked Response Shape
When moderation flags the input, NanoGPT returns400 with a standard error object and moderation metadata. The original input content is not echoed.
Common Errors
| Code | Meaning |
|---|---|
conflicting_moderation_model | Both moderation and moderation-model specify different moderation model IDs. |
model_not_found | The selected moderation model ID is not supported. |
inline_moderation_requires_api_key | Inline moderation was requested without a supported authenticated API-key billing context. |
empty_moderation_input | Moderation was requested but no text or image input could be extracted. |
unsupported_moderation_input | The request contains input that inline moderation cannot inspect safely, such as an unsupported image file reference or non-URL image payload. |
unsupported_input_modality | The selected moderation model cannot moderate one of the submitted modalities, for example image input with a text-only moderation model. |
unsupported_batch_input | The selected moderation model does not support batched moderation input. |
context_length_exceeded | The moderation input exceeds the selected moderation model’s input limit. |
content_policy_violation | Moderation flagged the input. |
Examples
Chat Completions
Responses API with a Specific Moderation Model
Image Generation
Image or Video Request with Reference Images
Reference images are moderated when they are provided as inspectable URLs:Notes for Integrators
Inline moderation is best for callers who want NanoGPT to enforce a paid input safety preflight before generation. It is not a substitute for output moderation, downstream user reporting, or product-specific policy controls. Because moderation is charged separately, clients should treat inline moderation as an additional paid feature. If a request is blocked, the caller still pays for moderation, but not for generation. To avoid accidental no-op configuration, always sendmoderation: true or moderation: <model-id> when you want inline moderation enabled.