{
  "openapi": "3.0.0",
  "info": {
    "title": "Paxmod API",
    "version": "1.1.0",
    "description": "AI-powered text and image moderation API for gaming communities and online platforms. COPPA-oriented content filtering. Authenticate with your project API key (Bearer). Projects are configured in the Paxmod console with a moderation mode: 'standard' (per-category AI scores against your thresholds) or 'advanced' (your custom written policy evaluated by an LLM, returned as a single 'Policy Violation' category).",
    "contact": {
      "name": "Paxmod Support",
      "email": "contact@paxmod.com"
    },
    "license": {
      "name": "Proprietary"
    }
  },
  "servers": [
    {
      "url": "https://www.paxmod.com/api/v1",
      "description": "Production server"
    }
  ],
  "security": [
    {
      "BearerAuth": []
    }
  ],
  "paths": {
    "/text": {
      "post": {
        "summary": "Moderate text content",
        "description": "Analyze a text message for harmful content. The message is normalized server-side before analysis (Unicode NFKC, look-alike and accented characters mapped to plain letters, zero-width characters removed, whitespace collapsed); ASCII substitutions such as digits for letters are not rewritten. Standard-mode projects return per-category scores (e.g. Harassment, Profanities, Spam) compared against your project's thresholds; advanced-mode projects evaluate your custom policy and return a single 'Policy Violation' category. Passing user_id enables ban-awareness (messages from users you've banned in the console are auto-flagged); context_id groups related messages in the review queue.",
        "operationId": "moderateText",
        "tags": ["Text Moderation"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TextModerationRequest"
              },
              "example": {
                "message": "Hello, this is a test message!",
                "user_id": "player_123",
                "context_id": "match_787"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Moderation completed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TextModerationResponse"
                },
                "example": {
                  "status": "success",
                  "id": "7f4df2a4-3a1f-4f7a-9d36-8a1c2f6a0b1e",
                  "service": "pax",
                  "request": {
                    "original_message": "ur trash, uninstall the game",
                    "processed_message": "ur trash, uninstall the game",
                    "timestamp": "2026-06-12T03:21:45.012Z"
                  },
                  "result": "flagged",
                  "reason": "Content flagged for Harassment",
                  "content_moderation": {
                    "flagged": true,
                    "categories": {
                      "Harassment": {
                        "flagged": true,
                        "threshold": 0.5,
                        "score": 0.94
                      },
                      "Profanities": {
                        "flagged": false,
                        "threshold": 0.5,
                        "score": 0.1
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request. Error codes: INVALID_JSON (body is not valid JSON), EMPTY_MESSAGE (message empty after normalization, e.g. only zero-width characters), MESSAGE_TOO_LONG (over 5000 characters after normalization). A missing, non-string, or whitespace-only `message` returns 400 with `error` as a plain string and no code.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed. Error codes: UNAUTHORIZED (missing API key), INVALID_API_KEY (invalid or revoked key).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "402": {
            "description": "Plan or key limit. Retrying will not help until the account changes. Error codes: PLAN_REQUIRED (no plan: start the 14-day trial or choose a plan in the console), PREVIEW_LIMIT_REACHED (no-plan account used today's console test messages), TRIAL_LIMIT_REACHED (trial message allowance used), AGENT_KEY_EXPIRED (agent key expired: claim it and start the trial), AGENT_KEY_LIMIT_REACHED (agent key used its 100 free messages).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "RATE_LIMITED: the project sent over 600 requests in a one-minute window (text and image together). Wait the number of seconds in the Retry-After header, then retry. USAGE_LIMIT_EXCEEDED: legacy free plan monthly limit reached (100 messages per month by default); retrying will not help, upgrade the plan instead.",
            "headers": {
              "Retry-After": {
                "description": "Seconds to wait before retrying. Sent with RATE_LIMITED.",
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error. Error code: INTERNAL_SERVER_ERROR.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "503": {
            "description": "Upstream language-model error (advanced-mode projects), returned only when both the primary and fallback models fail. Error code: LLM_SERVICE_ERROR. The status is usually 503 but may carry the upstream provider's status. Safe to retry with backoff.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/image": {
      "post": {
        "summary": "Moderate image content",
        "description": "Analyze an image (by URL) for sexual, violent and self-harm content, plus the project's custom checks: plain-English descriptions of anything else to detect (for example personal information such as phone numbers, addresses or faces), set in the console. Requires a project configured with the 'image' moderation type. Returns a score per category and per custom check, each compared against its threshold. Categories: Sexual, Violence, Violence/Graphic, Self-Harm, Self-Harm/Intent, Self-Harm/Instructions. Custom checks appear in content_moderation.categories under the name given to each. An image scored against custom checks counts as two credits.",
        "operationId": "moderateImage",
        "tags": ["Image Moderation"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ImageModerationRequest"
              },
              "example": {
                "image_url": "https://example.com/image.jpg",
                "user_id": "player_123"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Moderation completed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ImageModerationResponse"
                },
                "example": {
                  "status": "success",
                  "id": "0b2a7c1e-9d4f-4a3b-8e21-6c5d4f3a2b10",
                  "service": "pax",
                  "request": {
                    "image_url": "https://example.com/image.jpg",
                    "timestamp": "2026-06-12T03:21:45.012Z"
                  },
                  "result": "not_flagged",
                  "reason": "No moderation category thresholds exceeded",
                  "content_moderation": {
                    "flagged": false,
                    "categories": {
                      "Sexual": {
                        "flagged": false,
                        "threshold": 0.5,
                        "score": 0.0012
                      },
                      "Violence": {
                        "flagged": false,
                        "threshold": 0.5,
                        "score": 0.0103
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request. Error codes: INVALID_JSON (body is not valid JSON), MISSING_IMAGE_URL, INVALID_IMAGE_URL (not a valid URL), IMAGE_URL_UNAVAILABLE (image could not be downloaded), INVALID_MODERATION_TYPE (project is configured for text moderation).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed. Error codes: UNAUTHORIZED, INVALID_API_KEY.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "402": {
            "description": "Plan limit. Error codes: PLAN_REQUIRED, PREVIEW_LIMIT_REACHED, TRIAL_LIMIT_REACHED (see the text endpoint).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "403": {
            "description": "Plan does not include image moderation. Error code: PLAN_UPGRADE_REQUIRED (image moderation is on the Studio plan and during trials).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "RATE_LIMITED: the project sent over 600 requests in a one-minute window (text and image together); wait the Retry-After seconds, then retry. USAGE_LIMIT_EXCEEDED: legacy free plan monthly limit reached.",
            "headers": {
              "Retry-After": {
                "description": "Seconds to wait before retrying. Sent with RATE_LIMITED.",
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "422": {
            "description": "CHECKS_BLOCKED: the image was refused before the project's custom checks could run, and no category flagged it. Treat it as flagged or send it for review.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error. Error code: INTERNAL_SERVER_ERROR.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "503": {
            "description": "CHECKS_UNAVAILABLE: the project's custom checks could not be run, and no category flagged the image. Retry shortly.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/test-policy": {
      "post": {
        "summary": "Test a policy against example messages",
        "description": "Runs example messages through an Advanced mode policy, draft or saved, and returns what each would get. The project's word rules run first, as they do live (or send draft rules). Nothing is stored and no credits are used, except on a free agent key, where each message checked counts toward its 100. Use it to tune a policy before saving it in the console.",
        "operationId": "testPolicy",
        "tags": [
          "Text Moderation"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PolicyTestRequest"
              },
              "example": {
                "policy": "Flag asking players for their school, address or phone number. Trash talk and swearing are fine.",
                "examples": [
                  {
                    "message": "what school do u go to",
                    "expect": "flag"
                  },
                  {
                    "message": "ur trash at this game lol",
                    "expect": "pass"
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Test completed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PolicyTestResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request. Error codes: INVALID_JSON, NO_EXAMPLES, TOO_MANY_EXAMPLES (over 50), INVALID_EXAMPLE, INVALID_WORD_RULES, INVALID_POLICY, POLICY_TOO_LONG (over 1,000 characters), NO_POLICY (no saved policy and none sent), INVALID_THRESHOLD, WRONG_PROJECT_TYPE (image project).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key (UNAUTHORIZED, INVALID_API_KEY).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "402": {
            "description": "AGENT_KEY_EXPIRED: an unclaimed agent key past its 72 hours.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "RATE_LIMITED: shares the project's request rate limit.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Project API key authentication: 'Authorization: Bearer <api_key>'. Get your API key from the Paxmod console. (Legacy fallback: an 'api_key' field in the request body is also accepted, but the header is preferred.)"
      }
    },
    "schemas": {
      "TextModerationRequest": {
        "type": "object",
        "required": ["message"],
        "properties": {
          "message": {
            "type": "string",
            "maxLength": 5000,
            "description": "The text content to moderate (max 5000 characters)."
          },
          "user_id": {
            "type": "string",
            "description": "Optional ID of the end user who authored the content. Enables ban-awareness: content from users banned in the Paxmod console is automatically flagged."
          },
          "context_id": {
            "type": "string",
            "description": "Optional ID grouping related messages (e.g. a match, room, or thread) for context in the review queue."
          },
          "advanced_threshold": {
            "type": "number",
            "format": "float",
            "minimum": 0,
            "maximum": 1,
            "description": "Advanced-mode projects only: per-request override of the 'Policy Violation' flagging threshold (default 0.5 or the project's configured threshold)."
          },
          "api_key": {
            "type": "string",
            "deprecated": true,
            "description": "Legacy authentication fallback. Prefer the 'Authorization: Bearer' header."
          }
        }
      },
      "ImageModerationRequest": {
        "type": "object",
        "required": ["image_url"],
        "properties": {
          "image_url": {
            "type": "string",
            "format": "uri",
            "description": "Publicly reachable URL of the image to moderate."
          },
          "user_id": {
            "type": "string",
            "description": "Optional ID of the end user who posted the image. Enables ban-awareness."
          },
          "context_id": {
            "type": "string",
            "description": "Optional ID grouping related content for the review queue."
          },
          "api_key": {
            "type": "string",
            "deprecated": true,
            "description": "Legacy authentication fallback. Prefer the 'Authorization: Bearer' header."
          }
        }
      },
      "CategoryResult": {
        "type": "object",
        "description": "Per-category moderation outcome.",
        "required": ["flagged", "threshold", "score"],
        "properties": {
          "flagged": {
            "type": "boolean",
            "description": "Whether this category's score exceeded its threshold."
          },
          "threshold": {
            "type": "number",
            "format": "float",
            "minimum": 0,
            "maximum": 1,
            "description": "The project's configured threshold for this category (default 0.5)."
          },
          "score": {
            "type": "number",
            "format": "float",
            "minimum": 0,
            "maximum": 1,
            "description": "Model confidence that the content belongs to this category."
          }
        }
      },
      "ContentModeration": {
        "type": "object",
        "required": ["flagged", "categories"],
        "properties": {
          "flagged": {
            "type": "boolean",
            "description": "True if any enabled category exceeded its threshold (or the user is banned)."
          },
          "categories": {
            "type": "object",
            "description": "Map of category name to result. Text categories (standard mode, per project configuration): Sexual, Hate and Discrimination, Violence, Dangerous and Criminal Content, Self-Harm, Medical Advice, Financial Advice, Legal Advice, Personally Identifiable Information, Harassment, Threatening, Profanities, Spam. Advanced mode returns a single 'Policy Violation' category. Image categories: Sexual, Violence, Violence/Graphic, Self-Harm, Self-Harm/Intent, Self-Harm/Instructions, plus one entry per custom check on the project, under the name given to it. May be empty for short-circuit results (whitelisted content or banned users).",
            "additionalProperties": {
              "$ref": "#/components/schemas/CategoryResult"
            }
          }
        }
      },
      "TextModerationResponse": {
        "type": "object",
        "required": ["status", "id", "service", "request", "result", "reason", "content_moderation"],
        "properties": {
          "status": {
            "type": "string",
            "enum": ["success"]
          },
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "Unique ID for this moderation decision."
          },
          "service": {
            "type": "string",
            "enum": ["pax"]
          },
          "request": {
            "type": "object",
            "properties": {
              "original_message": {
                "type": "string",
                "description": "The message exactly as submitted."
              },
              "processed_message": {
                "type": "string",
                "description": "The normalized message that was analyzed (after any word rule changes)."
              },
              "timestamp": {
                "type": "string",
                "format": "date-time"
              }
            }
          },
          "result": {
            "type": "string",
            "enum": ["flagged", "not_flagged"],
            "description": "Overall moderation outcome."
          },
          "reason": {
            "type": "string",
            "description": "Human-readable explanation. Standard mode: e.g. 'Content flagged for Harassment, Profanities'. Advanced mode: a fixed line, 'Flagged under your moderation policy' or 'No policy violation found' (the written explanation for a flagged message is shown with it in the console). Banned users: 'User banned in Paxmod'."
          },
          "degraded": {
            "type": "boolean",
            "description": "Standard mode only. True when a moderation provider was unavailable and at least one enabled category could not be scored; those categories are listed in unavailable_categories and are not flagged."
          },
          "unavailable_categories": {
            "type": "array",
            "items": { "type": "string" },
            "description": "Standard mode only. Enabled categories that could not be scored for this request (empty when degraded is false)."
          },
          "allow_list": {
            "type": "array",
            "description": "Present only when one of the project's word rules (allow list) removed, replaced or blocked a term. A block returns result flagged with no category scores and no model call.",
            "items": {
              "type": "object",
              "required": ["term", "mode", "count"],
              "properties": {
                "term": { "type": "string" },
                "mode": { "type": "string", "enum": ["bypass", "remove", "substitute", "block"] },
                "replacement": { "type": "string" },
                "count": { "type": "integer" }
              }
            }
          },
          "context": {
            "type": "object",
            "description": "Standard mode only. Present only when the project has Player Context with live conversation scoring on and this message was scored together with the lines said before it in the same context_id. Absent otherwise.",
            "required": ["used", "messages"],
            "properties": {
              "used": { "type": "boolean", "enum": [true] },
              "messages": { "type": "integer", "description": "How many earlier lines of the conversation were read." }
            }
          },
          "content_moderation": {
            "$ref": "#/components/schemas/ContentModeration"
          }
        }
      },
      "ImageModerationResponse": {
        "type": "object",
        "required": ["status", "id", "service", "request", "result", "reason", "content_moderation"],
        "properties": {
          "status": {
            "type": "string",
            "enum": ["success"]
          },
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "service": {
            "type": "string",
            "enum": ["pax"]
          },
          "request": {
            "type": "object",
            "properties": {
              "image_url": {
                "type": "string",
                "format": "uri"
              },
              "timestamp": {
                "type": "string",
                "format": "date-time"
              }
            }
          },
          "result": {
            "type": "string",
            "enum": ["flagged", "not_flagged"]
          },
          "reason": {
            "type": "string"
          },
          "content_moderation": {
            "$ref": "#/components/schemas/ContentModeration"
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "required": ["status", "error"],
        "properties": {
          "status": {
            "type": "string",
            "enum": ["error"]
          },
          "error": {
            "description": "Error details. A plain string only for the text endpoint's missing-message 400; an object everywhere else.",
            "oneOf": [
              { "type": "string" },
              { "$ref": "#/components/schemas/ErrorDetail" }
            ]
          }
        }
      },
      "ErrorDetail": {
        "type": "object",
        "required": ["code", "message"],
        "properties": {
          "code": {
            "type": "string",
            "description": "Machine-readable error code.",
            "enum": [
              "INVALID_JSON",
              "UNAUTHORIZED",
              "INVALID_API_KEY",
              "PLAN_REQUIRED",
              "PLAN_UPGRADE_REQUIRED",
              "PREVIEW_LIMIT_REACHED",
              "TRIAL_LIMIT_REACHED",
              "AGENT_KEY_EXPIRED",
              "AGENT_KEY_LIMIT_REACHED",
              "RATE_LIMITED",
              "USAGE_LIMIT_EXCEEDED",
              "EMPTY_MESSAGE",
              "MESSAGE_TOO_LONG",
              "MISSING_IMAGE_URL",
              "INVALID_IMAGE_URL",
              "IMAGE_URL_UNAVAILABLE",
              "INVALID_MODERATION_TYPE",
              "LLM_SERVICE_ERROR",
              "INTERNAL_SERVER_ERROR"
            ]
          },
          "message": {
            "type": "string"
          },
          "details": {
            "type": "string"
          },
          "timestamp": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "PolicyTestRequest": {
        "type": "object",
        "required": [
          "examples"
        ],
        "properties": {
          "examples": {
            "type": "array",
            "maxItems": 50,
            "items": {
              "type": "object",
              "required": [
                "message"
              ],
              "properties": {
                "message": {
                  "type": "string",
                  "description": "A chat message, up to 5000 characters."
                },
                "expect": {
                  "type": "string",
                  "enum": [
                    "flag",
                    "pass"
                  ],
                  "description": "What the policy should do with it. With it, the summary counts how many came back as expected."
                }
              }
            }
          },
          "policy": {
            "type": "string",
            "maxLength": 1000,
            "description": "Draft policy. Leave out to test the saved policy."
          },
          "threshold": {
            "type": "number",
            "minimum": 0,
            "maximum": 1,
            "description": "Flag above this score. Defaults to the project's Policy Violation threshold."
          },
          "word_rules": {
            "type": "array",
            "maxItems": 500,
            "description": "Draft word rules. Leave out to use the saved ones.",
            "items": {
              "type": "object",
              "required": [
                "term",
                "mode"
              ],
              "properties": {
                "term": {
                  "type": "string"
                },
                "mode": {
                  "type": "string",
                  "enum": [
                    "bypass",
                    "remove",
                    "substitute",
                    "block"
                  ]
                },
                "replacement": {
                  "type": "string",
                  "description": "Only for substitute."
                }
              }
            }
          },
          "word_rules_only": {
            "type": "boolean",
            "description": "Run the word rules only, with no policy check."
          }
        }
      },
      "PolicyTestResponse": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "example": "success"
          },
          "policy": {
            "type": "string",
            "enum": [
              "draft",
              "saved"
            ],
            "nullable": true
          },
          "word_rules": {
            "type": "string",
            "enum": [
              "draft",
              "saved"
            ]
          },
          "threshold": {
            "type": "number",
            "nullable": true
          },
          "summary": {
            "type": "object",
            "properties": {
              "total": {
                "type": "integer"
              },
              "flagged": {
                "type": "integer"
              },
              "not_flagged": {
                "type": "integer"
              },
              "errors": {
                "type": "integer"
              },
              "with_expectation": {
                "type": "integer"
              },
              "as_expected": {
                "type": "integer"
              },
              "unexpected": {
                "type": "integer"
              }
            }
          },
          "results": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "message": {
                  "type": "string"
                },
                "expect": {
                  "type": "string",
                  "enum": [
                    "flag",
                    "pass"
                  ]
                },
                "result": {
                  "type": "string",
                  "enum": [
                    "flagged",
                    "not_flagged",
                    "error"
                  ]
                },
                "score": {
                  "type": "number",
                  "nullable": true,
                  "description": "Null when a word rule decided without a policy check."
                },
                "reason": {
                  "type": "string"
                },
                "word_rules": {
                  "type": "object",
                  "properties": {
                    "action": {
                      "type": "string",
                      "enum": [
                        "block",
                        "bypass",
                        "scan"
                      ]
                    },
                    "text": {
                      "type": "string",
                      "description": "The text the policy checked, after word rules."
                    },
                    "applied": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    }
                  }
                },
                "as_expected": {
                  "type": "boolean"
                }
              }
            }
          }
        }
      }
    }
  },
  "tags": [
    {
      "name": "Text Moderation",
      "description": "Real-time text moderation"
    },
    {
      "name": "Image Moderation",
      "description": "Image moderation by URL"
    }
  ]
}
