{
  "openapi": "3.1.1",
  "info": {
    "title": "Clusterbot moderation API",
    "description": "Classify text and receive a structured moderation outcome. Authenticate every request with the `X-Api-Key` header. Guides: [developer documentation](/Docs).",
    "version": "v1"
  },
  "servers": [
    {
      "url": "https://clusterbot.dev"
    }
  ],
  "paths": {
    "/v1/health": {
      "get": {
        "tags": [
          "Service"
        ],
        "summary": "Check service health",
        "description": "Reports that the service process is running. Doesn't check providers or your workspace. No API key required; rate limited.",
        "operationId": "Health",
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/moderations": {
      "post": {
        "tags": [
          "Moderation"
        ],
        "summary": "Moderate content",
        "description": "Classifies one text message and returns a structured outcome under your workspace thresholds. Costs 1 credit per started 2,000 characters on paid plans, or 1,000 on Free; service-side failures are refunded. Rejected content still returns 200. Errors: 400 `invalid_content` or `invalid_language`, 413 body over 64 KiB, 429 `quota_exceeded` or rate limit, 503 `provider_unavailable`, `review_unavailable`, or capacity. A 503 is never a safe result.",
        "operationId": "Moderate",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ModerationRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "429": {
            "description": "Too Many Requests",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ModerationResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "413": {
            "description": "Payload Too Large",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "503": {
            "description": "Service Unavailable",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKey": [ ]
          }
        ]
      }
    },
    "/v1/moderations/{reviewId}": {
      "get": {
        "tags": [
          "Moderation"
        ],
        "summary": "Get a review decision",
        "description": "Returns the manual review decision for a `FlaggedForReview` result. Free, but shares your workspace rate limit; poll about every 10–15 seconds or use review callbacks. 404 `review_not_found` means unknown, another workspace's, or expired — never treat it as approval.",
        "operationId": "GetReview",
        "parameters": [
          {
            "name": "reviewId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "429": {
            "description": "Too Many Requests",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ModerationReviewStatus"
                }
              }
            }
          },
          "404": {
            "description": "Not Found",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKey": [ ]
          }
        ]
      }
    },
    "/v1/usage": {
      "get": {
        "tags": [
          "Usage"
        ],
        "summary": "Get usage",
        "description": "Returns your workspace's credit balances. Free. Available capacity is `creditsRemaining + topUpBalance`.",
        "operationId": "GetUsage",
        "responses": {
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "429": {
            "description": "Too Many Requests",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ModerationUsage"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKey": [ ]
          }
        ]
      }
    }
  },
  "components": {
    "schemas": {
      "ModerationOutcome": {
        "enum": [
          "Pass",
          "FlaggedForReview",
          "Rejected"
        ],
        "type": "string",
        "description": "The decision under your workspace thresholds. `FlaggedForReview` is only returned when manual review is enabled."
      },
      "ModerationRequest": {
        "examples": [
          {
            "content": "Meet me after school, you will regret it.",
            "language": "en"
          }
        ],
        "required": [
          "content"
        ],
        "type": "object",
        "properties": {
          "content": {
            "maxLength": 16000,
            "minLength": 1,
            "type": "string",
            "description": "Text to classify. 1–16,000 characters (UTF-16 code units); not whitespace only; no NUL characters."
          },
          "language": {
            "pattern": "^[A-Za-z]{2,3}(-[A-Za-z]{2})?$",
            "type": [
              "null",
              "string"
            ],
            "description": "Optional language hint: a two- or three-letter code with an optional two-letter region, such as `ro` or `pt-BR`. A non-English value ensures multilingual evaluation. Omit or send null for automatic interpretation."
          }
        }
      },
      "ModerationResponse": {
        "examples": [
          {
            "flagged": true,
            "categories": [
              "harassment/threatening",
              "violence"
            ],
            "latencyMs": 91.4,
            "outcome": "Rejected",
            "evaluatedBy": "Model"
          }
        ],
        "required": [
          "outcome",
          "categories",
          "flagged",
          "evaluatedBy",
          "latencyMs"
        ],
        "type": "object",
        "properties": {
          "flagged": {
            "type": "boolean",
            "description": "True for both `FlaggedForReview` and `Rejected`. Kept for compatibility; prefer `outcome`."
          },
          "categories": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Every category that didn't pass under your thresholds. Empty when the outcome is `Pass`."
          },
          "latencyMs": {
            "type": "number",
            "description": "Screening and inference time in milliseconds, including failover attempts.",
            "format": "double"
          },
          "reviewId": {
            "type": [
              "null",
              "string"
            ],
            "description": "Present only when `outcome` is `FlaggedForReview`. Use it with `GET /v1/moderations/{reviewId}`.",
            "format": "uuid"
          },
          "outcome": {
            "$ref": "#/components/schemas/ModerationOutcome"
          },
          "evaluatedBy": {
            "$ref": "#/components/schemas/ModerationSource"
          }
        }
      },
      "ModerationReviewStatus": {
        "examples": [
          {
            "reviewId": "ab43b6e9-d212-4350-8ca7-c01bd21ad6b3",
            "status": "Approved",
            "outcome": "Pass",
            "reviewedAt": "2026-10-18T10:30:00+00:00"
          }
        ],
        "required": [
          "reviewId",
          "status",
          "outcome",
          "reviewedAt"
        ],
        "type": "object",
        "properties": {
          "reviewId": {
            "type": "string",
            "description": "The review ID returned with a `FlaggedForReview` result.",
            "format": "uuid"
          },
          "status": {
            "enum": [
              "Pending",
              "Approved",
              "Rejected"
            ],
            "type": "string",
            "description": "Review state. Stop polling once it is `Approved` or `Rejected`."
          },
          "outcome": {
            "enum": [
              "FlaggedForReview",
              "Pass",
              "Rejected"
            ],
            "type": "string",
            "description": "The outcome to apply: `FlaggedForReview` while pending, then `Pass` or `Rejected`."
          },
          "reviewedAt": {
            "type": [
              "null",
              "string"
            ],
            "description": "When the decision was made, or null while pending.",
            "format": "date-time"
          }
        }
      },
      "ModerationSource": {
        "enum": [
          "Model",
          "Prefilter",
          "Cache"
        ],
        "type": "string",
        "description": "How the result was produced. Ignore values you don't recognize."
      },
      "ModerationUsage": {
        "examples": [
          {
            "used": 1240,
            "limit": 10000,
            "resetsAt": "2026-12-01T00:00:00+00:00",
            "topUpBalance": 500,
            "unit": "credits",
            "creditsUsed": 1240,
            "creditLimit": 10000,
            "creditsRemaining": 8760
          }
        ],
        "required": [
          "creditsUsed",
          "creditLimit",
          "creditsRemaining",
          "topUpBalance",
          "resetsAt",
          "unit",
          "used",
          "limit"
        ],
        "type": "object",
        "properties": {
          "used": {
            "type": "integer",
            "description": "Alias of `creditsUsed`, kept for compatibility.",
            "format": "int32"
          },
          "limit": {
            "type": "integer",
            "description": "Alias of `creditLimit`, kept for compatibility.",
            "format": "int32"
          },
          "resetsAt": {
            "type": "string",
            "description": "When the monthly allowance next resets.",
            "format": "date-time"
          },
          "topUpBalance": {
            "type": "integer",
            "description": "Carry-over credits, used after the monthly allowance. They never expire.",
            "format": "int64"
          },
          "unit": {
            "const": "credits",
            "type": "string",
            "description": "Always `credits`."
          },
          "creditsUsed": {
            "type": "integer",
            "description": "Credits reserved in the current period, including requests later refunded to the top-up balance.",
            "format": "int32"
          },
          "creditLimit": {
            "type": "integer",
            "description": "Monthly credit allowance.",
            "format": "int32"
          },
          "creditsRemaining": {
            "type": "integer",
            "description": "Unused monthly allowance. Never negative.",
            "format": "int32"
          }
        }
      },
      "ProblemDetails": {
        "type": "object",
        "properties": {
          "type": {
            "type": [
              "null",
              "string"
            ]
          },
          "title": {
            "type": [
              "null",
              "string"
            ]
          },
          "status": {
            "type": [
              "null",
              "integer"
            ],
            "format": "int32"
          },
          "detail": {
            "type": [
              "null",
              "string"
            ]
          },
          "instance": {
            "type": [
              "null",
              "string"
            ]
          },
          "code": {
            "enum": [
              "invalid_content",
              "invalid_language",
              "customer_unavailable",
              "review_not_found",
              "quota_exceeded",
              "provider_unavailable",
              "review_unavailable"
            ],
            "type": "string",
            "description": "Stable machine-readable error code, present on business errors."
          }
        },
        "description": "Problem Details (RFC 9457). Business errors add a stable `code`."
      }
    },
    "securitySchemes": {
      "ApiKey": {
        "type": "apiKey",
        "description": "A secret key from Portal → API keys, such as `cb_` followed by 64 hexadecimal characters. Send it from your server only.",
        "name": "X-Api-Key",
        "in": "header"
      }
    }
  },
  "tags": [
    {
      "name": "Moderation",
      "description": "Classify text and retrieve manual review decisions."
    },
    {
      "name": "Usage",
      "description": "Credit balances for your workspace."
    },
    {
      "name": "Service",
      "description": "Service availability."
    }
  ]
}