---
title: "POST /moderations"
method: POST
path: "/moderations"
tags: ["Moderations"]
---

# POST /moderations

`POST /moderations`

Classifies if given messages are potentially harmful across several categories.

## Request body

- ModerationRequest
  - `model` string — Optional identifier of the model to use. Defaults to "Llama-Guard".
  - `messages` Message[], required — List of messages in the conversation.
    - union
      - UserMessage — A message from the user in a chat conversation.
        - `role` 'user', required — Must be "user" to identify this as a user message.
        - `content` union, required — The content of the user message, which can include text and other media.
          - string — The text contents of the message.
          - UserMessageContentItem[] — A list of content items, which can include text and other media. Supported content types differ based on model.
            - union
              - …
      - SystemMessage — A system message providing instructions or context to the model.
        - `role` 'system', required — Must be "system" to identify this as a system message
        - `content` union, required — The content of the system message.
          - string — The text contents of the message.
          - MessageTextContentItem[] — A list of content items, which can include text and other media. Supported content types differ based on model.
            - `type` 'text', required — Discriminator type of the content item. Always "text"
            - `text` string, required — Text content
      - ToolResponseMessage — A message representing the result of a tool invocation.
        - `role` 'tool', required — Must be "tool" to identify this as a tool response
        - `tool_call_id` string, required — Unique identifier for the tool call this response is for
        - `content` union, required — The content of the user message, which can include text and other media.
          - string — The text contents of the message.
          - MessageTextContentItem[] — A list of content items, which can include text and other media. Supported content types differ based on model.
            - `type` 'text', required — Discriminator type of the content item. Always "text"
            - `text` string, required — Text content
      - AssistantMessage — A message containing the model's (assistant) response in a chat conversation.
        - `role` 'assistant', required — Must be "assistant" to identify this as the model's response
        - `content` union — The content of the model's response.
          - string
          - AssistantMessageContentItem — A text content item
            - `type` 'text', required — Discriminator type of the content item. Always "text"
            - `text` string, required — Text content
        - `stop_reason` 'stop' | 'tool_calls' | 'length' — The reason why we stopped. Options are: - "stop": The model reached a natural stopping point. - "tool_calls": The model finished generating and invoked a tool call. - "length": The model reached the maxinum number of tokens specified in the request.
        - `tool_calls` MessageToolCall[] — The tool calls generated by the model, such as function calls.
          - `id` string, required — The ID of the tool call.
          - `function` object, required — The function that the model called.
            - `name` string, required — The name of the function to call.
            - `arguments` string, required — The arguments to call the function with, as generated by the model in JSON format. Note that the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema. Validate the arguments in your code before calling your function.

## Response `200`

Returns a Moderation object with moderation results.

- ModerationResponse
  - `model` string, required
  - `results` ModerationObject[], required
    - `flagged` boolean, required
    - `flagged_categories` string[], required

## Other responses

- `400` — The request was invalid or malformed
- `429` — The client has sent too many requests in a given amount of time
- `500` — The server encountered an unexpected error
- `default` — An unexpected error occurred

---

[API](https://skmtc.dev/meta-llama/apis/llama-api-specification.md) · [All operations](https://skmtc.dev/meta-llama/apis/llama-api-specification/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/meta-llama/llama-api-specification/revisions/edf0a308dd29/schema)
