> ## Documentation Index
> Fetch the complete documentation index at: https://docs.inworld.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Create chat moderation

> Classify chat messages for harmful content

Classifies messages in a conversation for harmful content. Unlike `/v1/moderations`, this endpoint accepts chat messages and supports a `scope` parameter to control which messages are evaluated.
Not compatible with the OpenAI SDK. Use [`/v1/moderations`](/api-reference/routerAPI/create-moderation) for SDK compatibility.


## OpenAPI

````yaml post /v1/chat/moderations
openapi: 3.0.0
info:
  title: Router API
  version: v1
  description: >-
    Intelligent routing and optimization for LLM requests. Automatically selects
    the best model based on your criteria, handles fallbacks, and optimizes for
    cost, latency, or intelligence. Also includes a Router CRUD API for creating
    reusable routing configurations.
servers:
  - url: https://api.inworld.ai
    description: Production server
security:
  - inworld_basic: []
tags:
  - name: Chat Completions
    description: >-
      Main API endpoint for intelligent LLM routing and optimization. Generate
      chat completions with automatic model selection or specific models with
      fallbacks.
  - name: Moderations
    description: >-
      Classify text content for harmful material. Includes OpenAI-compatible
      moderation and conversation-aware chat moderation with AILuminate safety
      signals.
  - name: Router Management
    description: >-
      Service endpoints for creating and managing reusable router
      configurations. Use these to set up routing strategies that can be
      referenced in Chat Completions requests.
paths:
  /v1/chat/moderations:
    post:
      tags:
        - Moderations
      summary: Create chat moderation
      description: >-
        Classifies messages in a conversation for harmful content. Accepts chat
        messages and supports a `scope` parameter to control which messages are
        evaluated.


        Not compatible with the OpenAI SDK. Use `/v1/moderations` for SDK
        compatibility.
      operationId: createChatModeration
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatModerationRequest'
            examples:
              Default (last message):
                summary: Moderate the last message only (default)
                value:
                  messages:
                    - role: user
                      content: Hello world!
                    - role: assistant
                      content: Hi there!
                    - role: user
                      content: Tell me something
              All messages:
                summary: Moderate all messages
                value:
                  messages:
                    - role: user
                      content: Hello world!
                    - role: assistant
                      content: Hi there!
                    - role: user
                      content: Tell me something
                  scope: all
              Last N messages:
                summary: Moderate the last 2 messages
                value:
                  messages:
                    - role: user
                      content: Hello world!
                    - role: assistant
                      content: Hi there!
                    - role: user
                      content: Tell me something
                  scope: 2
      responses:
        '200':
          description: A successful response.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatModerationResponse'
              examples:
                Default:
                  summary: Chat moderation result
                  value:
                    id: modr-8a1241048da1455f92f1e6242a3a3576
                    model: inworld/moderation-latest
                    result:
                      flagged: false
                      categories:
                        sexual: false
                        sexual/minors: false
                        harassment: false
                        harassment/threatening: false
                        hate: false
                        hate/threatening: false
                        illicit: false
                        illicit/violent: false
                        self-harm: false
                        self-harm/intent: false
                        self-harm/instructions: false
                        violence: false
                        violence/graphic: false
                      category_scores:
                        sexual: 0
                        sexual/minors: 0
                        harassment: 0
                        harassment/threatening: 0
                        hate: 0
                        hate/threatening: 0
                        illicit: 0
                        illicit/violent: 0
                        self-harm: 0
                        self-harm/intent: 0
                        self-harm/instructions: 0
                        violence: 0
                        violence/graphic: 0
                      category_applied_input_types:
                        sexual:
                          - text
                        sexual/minors:
                          - text
                        harassment:
                          - text
                        harassment/threatening:
                          - text
                        hate:
                          - text
                        hate/threatening:
                          - text
                        illicit:
                          - text
                        illicit/violent:
                          - text
                        self-harm:
                          - text
                        self-harm/intent:
                          - text
                        self-harm/instructions:
                          - text
                        violence:
                          - text
                        violence/graphic:
                          - text
                      ailuminate:
                        safety: safe
                        categories:
                          violent_crimes: false
                          sex_related_crimes: false
                          child_sexual_exploitation: false
                          suicide_self_harm: false
                          indiscriminate_weapons: false
                          intellectual_property: false
                          defamation: false
                          non_violent_crimes: false
                          hate: false
                          specialized_advice: false
                          privacy: false
                          sexual_content: false
                        extensions:
                          politically_sensitive: false
                          unethical_acts: false
                          jailbreak: false
                        refusal: false
        '400':
          description: Bad request - Missing or invalid messages
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Unauthorized - Invalid or missing API key
          content:
            text/plain:
              schema:
                type: string
                example: Unauthorized
      security:
        - inworld_bearer: []
      x-codeSamples:
        - lang: bash
          label: Last message (default)
          source: |-
            curl -X POST 'https://api.inworld.ai/v1/chat/moderations' \
              -H 'Authorization: Bearer $INWORLD_API_KEY' \
              -H 'Content-Type: application/json' \
              -d '{
                "messages": [
                  {"role": "user", "content": "Hello world!"},
                  {"role": "assistant", "content": "Hi there!"},
                  {"role": "user", "content": "Tell me something"}
                ]
              }'
        - lang: bash
          label: All messages
          source: |-
            curl -X POST 'https://api.inworld.ai/v1/chat/moderations' \
              -H 'Authorization: Bearer $INWORLD_API_KEY' \
              -H 'Content-Type: application/json' \
              -d '{
                "messages": [
                  {"role": "user", "content": "Hello world!"},
                  {"role": "assistant", "content": "Hi there!"},
                  {"role": "user", "content": "Tell me something"}
                ],
                "scope": "all"
              }'
        - lang: bash
          label: Last N messages
          source: |-
            curl -X POST 'https://api.inworld.ai/v1/chat/moderations' \
              -H 'Authorization: Bearer $INWORLD_API_KEY' \
              -H 'Content-Type: application/json' \
              -d '{
                "messages": [
                  {"role": "user", "content": "Hello world!"},
                  {"role": "assistant", "content": "Hi there!"},
                  {"role": "user", "content": "Tell me something"}
                ],
                "scope": 2
              }'
        - lang: python
          label: Python
          source: |-
            import requests

            response = requests.post(
                "https://api.inworld.ai/v1/chat/moderations",
                headers={
                    "Authorization": "Bearer YOUR_INWORLD_API_KEY",
                    "Content-Type": "application/json"
                },
                json={
                    "messages": [
                        {"role": "user", "content": "Hello world!"},
                        {"role": "assistant", "content": "Hi there!"},
                        {"role": "user", "content": "Tell me something"}
                    ],
                    "scope": "last"
                }
            )

            result = response.json()["result"]
            print(result["flagged"])
        - lang: javascript
          label: JavaScript
          source: >-
            const response = await
            fetch('https://api.inworld.ai/v1/chat/moderations', {
              method: 'POST',
              headers: {
                'Authorization': 'Bearer YOUR_INWORLD_API_KEY',
                'Content-Type': 'application/json',
              },
              body: JSON.stringify({
                messages: [
                  { role: 'user', content: 'Hello world!' },
                  { role: 'assistant', content: 'Hi there!' },
                  { role: 'user', content: 'Tell me something' },
                ],
                scope: 'last',
              }),
            });


            const { result } = await response.json();

            console.log(result.flagged);
components:
  schemas:
    ChatModerationRequest:
      type: object
      required:
        - messages
      properties:
        messages:
          type: array
          description: Array of chat messages to classify.
          items:
            $ref: '#/components/schemas/Message'
        scope:
          oneOf:
            - type: string
              enum:
                - all
                - last
            - type: integer
              minimum: 1
          description: >-
            Which messages to classify. `"last"` (default) processes only the
            last message. `"all"` processes every message. A positive integer
            `N` processes the last `N` messages. Be mindful that including many
            messages increases response latency.
          default: last
        model:
          type: string
          description: The moderation model to use.
          default: inworld/moderation-latest
    ChatModerationResponse:
      type: object
      properties:
        id:
          type: string
          description: Unique identifier for the moderation request.
        model:
          type: string
          description: The model used for classification.
        result:
          $ref: '#/components/schemas/ModerationResult'
          description: A single aggregated moderation result for the conversation.
    ErrorResponse:
      type: object
      description: >-
        Error response format varies: error can be a string or an object with
        message.
      properties:
        error:
          oneOf:
            - type: string
              description: Error message string.
              example: model field is required
            - type: object
              properties:
                message:
                  type: string
                  example: 'Invalid service provider: SERVICE_PROVIDER_INVALID'
    Message:
      type: object
      required:
        - role
      properties:
        role:
          type: string
          enum:
            - system
            - user
            - assistant
            - tool
          description: The role of the message author.
        content:
          description: >-
            The content of the message. Can be a string for text-only messages,
            an array of content parts for multimodal messages, or null for
            assistant messages with tool_calls.
          nullable: true
          oneOf:
            - $ref: '#/components/schemas/TextMessageContent'
            - $ref: '#/components/schemas/MultimodalMessageContent'
        tool_calls:
          type: array
          items:
            $ref: '#/components/schemas/ToolCall'
          description: Tool calls generated by the model (assistant messages only).
        tool_call_id:
          type: string
          description: Tool call ID this message is responding to (tool role only).
    ModerationResult:
      type: object
      properties:
        flagged:
          type: boolean
          description: Whether the content was flagged as harmful.
        categories:
          type: object
          description: Boolean flags for each safety category.
          properties:
            sexual:
              type: boolean
            sexual/minors:
              type: boolean
            harassment:
              type: boolean
            harassment/threatening:
              type: boolean
            hate:
              type: boolean
            hate/threatening:
              type: boolean
            illicit:
              type: boolean
            illicit/violent:
              type: boolean
            self-harm:
              type: boolean
            self-harm/intent:
              type: boolean
            self-harm/instructions:
              type: boolean
            violence:
              type: boolean
            violence/graphic:
              type: boolean
        category_scores:
          type: object
          description: Numeric confidence scores (0–1) for each safety category.
          properties:
            sexual:
              type: number
            sexual/minors:
              type: number
            harassment:
              type: number
            harassment/threatening:
              type: number
            hate:
              type: number
            hate/threatening:
              type: number
            illicit:
              type: number
            illicit/violent:
              type: number
            self-harm:
              type: number
            self-harm/intent:
              type: number
            self-harm/instructions:
              type: number
            violence:
              type: number
            violence/graphic:
              type: number
        category_applied_input_types:
          type: object
          description: Input types evaluated for each category.
          additionalProperties:
            type: array
            items:
              type: string
        ailuminate:
          $ref: '#/components/schemas/AILuminateResult'
    TextMessageContent:
      type: string
      description: Text-only message content.
    MultimodalMessageContent:
      type: array
      description: An array of content parts for a multimodal message.
      minItems: 1
      items:
        $ref: '#/components/schemas/ContentPart'
    ToolCall:
      type: object
      description: A tool call made by the model.
      properties:
        id:
          type: string
          description: ID of the tool call.
        type:
          type: string
          enum:
            - function
          description: The type of the tool call. Always 'function'.
        function:
          type: object
          description: The function that the model called.
          properties:
            name:
              type: string
              description: The name of the function to call.
            arguments:
              type: string
              description: The arguments to call the function with, as a JSON string.
          required:
            - name
            - arguments
      required:
        - id
        - type
        - function
    AILuminateResult:
      type: object
      description: >-
        Additional safety classifications based on the AILuminate benchmark by
        MLCommons. Extends the standard OpenAI moderation categories with more
        granular signals.
      properties:
        safety:
          type: string
          description: Overall safety assessment.
          enum:
            - safe
            - unsafe
            - controversial
        categories:
          type: object
          description: Boolean flags for AILuminate-specific safety categories.
          properties:
            violent_crimes:
              type: boolean
            sex_related_crimes:
              type: boolean
            child_sexual_exploitation:
              type: boolean
            suicide_self_harm:
              type: boolean
            indiscriminate_weapons:
              type: boolean
            intellectual_property:
              type: boolean
            defamation:
              type: boolean
            non_violent_crimes:
              type: boolean
            hate:
              type: boolean
            specialized_advice:
              type: boolean
            privacy:
              type: boolean
            sexual_content:
              type: boolean
        extensions:
          type: object
          description: Additional classification signals.
          properties:
            politically_sensitive:
              type: boolean
            unethical_acts:
              type: boolean
            jailbreak:
              type: boolean
        refusal:
          type: boolean
          description: Whether the content represents a refusal.
    ContentPart:
      description: A single content part in a multimodal message. Discriminated by `type`.
      oneOf:
        - $ref: '#/components/schemas/TextContentPart'
        - $ref: '#/components/schemas/ImageContentPart'
        - $ref: '#/components/schemas/InputAudioContentPart'
      discriminator:
        propertyName: type
        mapping:
          text:
            $ref: '#/components/schemas/TextContentPart'
          image_url:
            $ref: '#/components/schemas/ImageContentPart'
          input_audio:
            $ref: '#/components/schemas/InputAudioContentPart'
    TextContentPart:
      type: object
      description: A text content part.
      required:
        - type
        - text
      properties:
        type:
          type: string
          enum:
            - text
        text:
          type: string
          description: The text content.
    ImageContentPart:
      type: object
      description: An image content part.
      required:
        - type
        - image_url
      properties:
        type:
          type: string
          enum:
            - image_url
        image_url:
          $ref: '#/components/schemas/ImageUrl'
    InputAudioContentPart:
      type: object
      description: An audio content part.
      required:
        - type
        - input_audio
      properties:
        type:
          type: string
          enum:
            - input_audio
        input_audio:
          $ref: '#/components/schemas/InputAudio'
    ImageUrl:
      type: object
      description: Image URL or base64 data URI with optional detail level.
      properties:
        url:
          type: string
          description: >-
            The image URL or base64 data URI (e.g. `data:image/png;base64,...`).
            HTTP URLs are supported for all providers except Google AI Studio
            and Vertex AI.
        detail:
          type: string
          description: Image detail level. Controls how the model processes the image.
          enum:
            - auto
            - low
            - high
          default: auto
      required:
        - url
    InputAudio:
      type: object
      description: Base64-encoded audio input.
      properties:
        data:
          type: string
          description: Base64-encoded audio data.
        format:
          type: string
          description: The audio format.
          enum:
            - wav
            - mp3
      required:
        - data
        - format
  securitySchemes:
    inworld_basic:
      type: apiKey
      in: header
      name: Authorization
      description: >-
        Your [authentication](../../../api-reference/introduction) credentials.
        For Basic authentication, please populate `Basic $INWORLD_API_KEY`.


        Please make sure your API Key has [write permissions for the Router
        API](/api-reference/introduction#getting-an-api-key) in order to create,
        update, and delete routers. You can create a key in one command with the
        [Inworld CLI](../../../tts/resources/inworld-cli): `inworld workspace
        add-key`.
    inworld_bearer:
      type: http
      scheme: bearer
      description: >-
        Your [authentication](../../../api-reference/introduction) credentials.
        Pass your API key as a Bearer token: `Bearer $INWORLD_API_KEY`. You can
        create a key in one command with the [Inworld
        CLI](../../../tts/resources/inworld-cli): `inworld workspace add-key`.

````