{
  "openapi": "3.0.0",
  "info": { "version": "1.0.0", "title": "ContentMod Api" },
  "servers": [{ "url": "https://api.contentmod.io" }],
  "components": {
    "securitySchemes": { "Bearer": { "type": "http", "scheme": "bearer" } },
    "schemas": {},
    "parameters": {}
  },
  "paths": {
    "/text": {
      "post": {
        "security": [{ "Bearer": [] }],
        "requestBody": {
          "description": "The text to moderate",
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "text": {
                    "type": "string",
                    "minLength": 1,
                    "example": "This is a very cool api"
                  },
                  "options": {
                    "type": "object",
                    "properties": {
                      "meta": { "type": "object", "properties": {} },
                      "callbackUrl": { "type": "string", "format": "uri" },
                      "defer": { "type": "boolean" },
                      "actorId": { "type": "string" },
                      "bannedWords": {
                        "type": "array",
                        "items": { "type": "string" }
                      }
                    }
                  }
                },
                "required": ["text"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Response of the moderated text",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "The id of the text moderation",
                      "example": "27fbdc0b-b295-46ce-93f5-81b2fc08a381"
                    },
                    "isSafe": {
                      "type": "boolean",
                      "description": "Whether the text is considered safe",
                      "example": true
                    },
                    "confidence": {
                      "type": "number",
                      "description": "Confidence of the safety of the text from 1-100",
                      "example": 90
                    },
                    "sentiment": {
                      "type": "string",
                      "enum": ["positive", "negative", "neutral"],
                      "description": "Sentiment of the text, either negative, neutral or positive",
                      "example": "positive"
                    },
                    "sentimentScore": {
                      "type": "number",
                      "description": "Sentiment score from 1-100 (negative, neutral, positive)",
                      "example": 90
                    },
                    "riskScores": {
                      "type": "object",
                      "properties": {
                        "overall": {
                          "type": "number",
                          "description": "Overall risk score from 1-100",
                          "example": 90
                        },
                        "spam": {
                          "type": "number",
                          "description": "Score from 1-100 wether the text is spam",
                          "example": 90
                        },
                        "toxicity": {
                          "type": "number",
                          "description": "Score from 1-100 wether the text is malicious/toxic",
                          "example": 90
                        }
                      },
                      "required": ["overall", "spam", "toxicity"]
                    },
                    "topics": {
                      "type": "array",
                      "items": { "type": "string" },
                      "description": "General topics the text depicts, lowercase and no punctuation",
                      "example": ["politics", "sports"]
                    },
                    "nsfwCategories": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "category": {
                            "type": "string",
                            "description": "The category",
                            "example": "sexual"
                          },
                          "severity": {
                            "type": "number",
                            "description": "Severity level of the category from 1-100",
                            "example": 90
                          }
                        },
                        "required": ["category", "severity"]
                      },
                      "example": [{ "category": "sexual", "severity": 90 }]
                    },
                    "summary": {
                      "type": "object",
                      "properties": {
                        "profanity": {
                          "type": "boolean",
                          "description": "Whether the content contains profanity.",
                          "example": true
                        },
                        "totalFlags": {
                          "type": "number",
                          "description": "Total flags",
                          "example": 1
                        },
                        "contentRating": {
                          "type": "string",
                          "description": "Content rating of the text (e.g. G, PG, PG-13, R, NC-17)",
                          "example": "G"
                        },
                        "language": {
                          "type": "string",
                          "description": "The language code of the text, eg. en, fr, de",
                          "example": "en"
                        }
                      },
                      "required": [
                        "profanity",
                        "totalFlags",
                        "contentRating",
                        "language"
                      ]
                    },
                    "suggestedActions": {
                      "type": "object",
                      "properties": {
                        "reject": {
                          "type": "boolean",
                          "description": "Whether to reject the text",
                          "example": true
                        },
                        "review": {
                          "type": "boolean",
                          "description": "Whether to flag the text",
                          "example": true
                        }
                      },
                      "required": ["reject", "review"]
                    },
                    "filteredContent": {
                      "type": "string",
                      "description": "The text with profanity replaced by *.",
                      "example": "This is a filtered text"
                    },
                    "content": {
                      "type": "string",
                      "description": "The original text",
                      "example": "This is the original text"
                    },
                    "request": {
                      "type": "object",
                      "properties": {
                        "requestId": {
                          "type": "string",
                          "description": "The id of the request",
                          "example": "27fbdc0b-b295-46ce-93f5-81b2fc08a381"
                        },
                        "timestamp": {
                          "type": "string",
                          "description": "The timestamp of the request",
                          "example": "2023-04-05T12:00:00.000Z"
                        }
                      },
                      "required": ["requestId", "timestamp"]
                    },
                    "meta": {
                      "nullable": true,
                      "description": "The metadata of the request",
                      "example": "This is the metadata"
                    },
                    "hash": {
                      "type": "string",
                      "description": "SHA-256 hash of the text",
                      "example": "93a08bd10cd367bf83f12ba6590fcaef2f8deec8a47ce4ce88a15c7dda325ffa"
                    }
                  },
                  "required": [
                    "id",
                    "isSafe",
                    "confidence",
                    "sentiment",
                    "sentimentScore",
                    "riskScores",
                    "topics",
                    "nsfwCategories",
                    "summary",
                    "suggestedActions",
                    "filteredContent",
                    "content",
                    "request",
                    "hash"
                  ]
                }
              }
            }
          },
          "201": {
            "description": "Returns 201 moderation created with the id",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": { "id": { "type": "string" } },
                  "required": ["id"]
                }
              }
            }
          }
        }
      }
    },
    "/text/{id}": {
      "get": {
        "security": [{ "Bearer": [] }],
        "parameters": [
          {
            "schema": {
              "type": "string",
              "minLength": 3,
              "example": "27fbdc0b-b295-46ce-93f5-81b2fc08a381"
            },
            "required": true,
            "name": "id",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Fetch a text moderation by its ID",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "The id of the text moderation",
                      "example": "27fbdc0b-b295-46ce-93f5-81b2fc08a381"
                    },
                    "isSafe": {
                      "type": "boolean",
                      "description": "Whether the text is considered safe",
                      "example": true
                    },
                    "confidence": {
                      "type": "number",
                      "description": "Confidence of the safety of the text from 1-100",
                      "example": 90
                    },
                    "sentiment": {
                      "type": "string",
                      "enum": ["positive", "negative", "neutral"],
                      "description": "Sentiment of the text, either negative, neutral or positive",
                      "example": "positive"
                    },
                    "sentimentScore": {
                      "type": "number",
                      "description": "Sentiment score from 1-100 (negative, neutral, positive)",
                      "example": 90
                    },
                    "riskScores": {
                      "type": "object",
                      "properties": {
                        "overall": {
                          "type": "number",
                          "description": "Overall risk score from 1-100",
                          "example": 90
                        },
                        "spam": {
                          "type": "number",
                          "description": "Score from 1-100 wether the text is spam",
                          "example": 90
                        },
                        "toxicity": {
                          "type": "number",
                          "description": "Score from 1-100 wether the text is malicious/toxic",
                          "example": 90
                        }
                      },
                      "required": ["overall", "spam", "toxicity"]
                    },
                    "topics": {
                      "type": "array",
                      "items": { "type": "string" },
                      "description": "General topics the text depicts, lowercase and no punctuation",
                      "example": ["politics", "sports"]
                    },
                    "nsfwCategories": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "category": {
                            "type": "string",
                            "description": "The category",
                            "example": "sexual"
                          },
                          "severity": {
                            "type": "number",
                            "description": "Severity level of the category from 1-100",
                            "example": 90
                          }
                        },
                        "required": ["category", "severity"]
                      },
                      "example": [{ "category": "sexual", "severity": 90 }]
                    },
                    "summary": {
                      "type": "object",
                      "properties": {
                        "profanity": {
                          "type": "boolean",
                          "description": "Whether the content contains profanity.",
                          "example": true
                        },
                        "totalFlags": {
                          "type": "number",
                          "description": "Total flags",
                          "example": 1
                        },
                        "contentRating": {
                          "type": "string",
                          "description": "Content rating of the text (e.g. G, PG, PG-13, R, NC-17)",
                          "example": "G"
                        },
                        "language": {
                          "type": "string",
                          "description": "The language code of the text, eg. en, fr, de",
                          "example": "en"
                        }
                      },
                      "required": [
                        "profanity",
                        "totalFlags",
                        "contentRating",
                        "language"
                      ]
                    },
                    "suggestedActions": {
                      "type": "object",
                      "properties": {
                        "reject": {
                          "type": "boolean",
                          "description": "Whether to reject the text",
                          "example": true
                        },
                        "review": {
                          "type": "boolean",
                          "description": "Whether to flag the text",
                          "example": true
                        }
                      },
                      "required": ["reject", "review"]
                    },
                    "filteredContent": {
                      "type": "string",
                      "description": "The text with profanity replaced by *.",
                      "example": "This is a filtered text"
                    },
                    "content": {
                      "type": "string",
                      "description": "The original text",
                      "example": "This is the original text"
                    },
                    "request": {
                      "type": "object",
                      "properties": {
                        "requestId": {
                          "type": "string",
                          "description": "The id of the request",
                          "example": "27fbdc0b-b295-46ce-93f5-81b2fc08a381"
                        },
                        "timestamp": {
                          "type": "string",
                          "description": "The timestamp of the request",
                          "example": "2023-04-05T12:00:00.000Z"
                        }
                      },
                      "required": ["requestId", "timestamp"]
                    },
                    "meta": {
                      "nullable": true,
                      "description": "The metadata of the request",
                      "example": "This is the metadata"
                    },
                    "hash": {
                      "type": "string",
                      "description": "SHA-256 hash of the text",
                      "example": "93a08bd10cd367bf83f12ba6590fcaef2f8deec8a47ce4ce88a15c7dda325ffa"
                    }
                  },
                  "required": [
                    "id",
                    "isSafe",
                    "confidence",
                    "sentiment",
                    "sentimentScore",
                    "riskScores",
                    "topics",
                    "nsfwCategories",
                    "summary",
                    "suggestedActions",
                    "filteredContent",
                    "content",
                    "request",
                    "hash"
                  ]
                }
              }
            }
          }
        }
      },
      "delete": {
        "security": [{ "Bearer": [] }],
        "parameters": [
          {
            "schema": {
              "type": "string",
              "minLength": 3,
              "example": "27fbdc0b-b295-46ce-93f5-81b2fc08a381"
            },
            "required": true,
            "name": "id",
            "in": "path"
          }
        ],
        "responses": { "204": { "description": "No content" } }
      }
    },
    "/image": {
      "post": {
        "security": [{ "Bearer": [] }],
        "requestBody": {
          "description": "image",
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "image": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Url of an image or base 64 encoded image string",
                    "example": "This is a very cool api"
                  },
                  "options": {
                    "type": "object",
                    "properties": {
                      "meta": { "type": "object", "properties": {} },
                      "callbackUrl": { "type": "string", "format": "uri" },
                      "defer": { "type": "boolean" },
                      "actorId": { "type": "string" }
                    }
                  }
                },
                "required": ["image"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Response of the moderated image",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "summary": {
                      "type": "object",
                      "properties": {
                        "totalFlags": {
                          "type": "number",
                          "description": "Total flags",
                          "example": 1
                        },
                        "contentRating": {
                          "type": "string",
                          "description": "Content rating of the image (e.g. G, PG, PG-13, R, NC-17)",
                          "example": "G"
                        },
                        "language": {
                          "type": "string",
                          "description": "The language code of the text, eg. en, fr, de",
                          "example": "en"
                        }
                      },
                      "required": ["totalFlags", "contentRating", "language"]
                    },
                    "isSafe": {
                      "type": "boolean",
                      "description": "Whether the image is considered safe",
                      "example": true
                    },
                    "confidence": {
                      "type": "number",
                      "description": "Confidence of the safety of the image from 1-100",
                      "example": 90
                    },
                    "description": {
                      "type": "string",
                      "description": "A short description of what the image depicts",
                      "example": "This is a description"
                    },
                    "riskScores": {
                      "type": "object",
                      "properties": {
                        "overall": {
                          "type": "number",
                          "description": "Overall risk score from 1-100",
                          "example": 90
                        },
                        "spam": {
                          "type": "number",
                          "description": "Score from 1-100 wether the image is spam",
                          "example": 90
                        },
                        "toxicity": {
                          "type": "number",
                          "description": "Score from 1-100 wether the image is malicious/toxic",
                          "example": 90
                        }
                      },
                      "required": ["overall", "spam", "toxicity"]
                    },
                    "topics": {
                      "type": "array",
                      "items": { "type": "string" },
                      "description": "General topics the image depicts, lowercase and no punctuation",
                      "example": ["politics", "sports"]
                    },
                    "nsfwCategories": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "category": {
                            "type": "string",
                            "description": "The category",
                            "example": "sexual"
                          },
                          "severity": {
                            "type": "number",
                            "description": "Severity level of the category from 1-100",
                            "example": 90
                          }
                        },
                        "required": ["category", "severity"]
                      },
                      "example": [{ "category": "sexual", "severity": 90 }]
                    },
                    "suggestedActions": {
                      "type": "object",
                      "properties": {
                        "reject": {
                          "type": "boolean",
                          "description": "Whether to reject the image",
                          "example": true
                        },
                        "review": {
                          "type": "boolean",
                          "description": "Whether to flag the image",
                          "example": true
                        }
                      },
                      "required": ["reject", "review"]
                    },
                    "meta": {
                      "nullable": true,
                      "description": "The metadata of the request",
                      "example": "This is the metadata"
                    },
                    "hash": {
                      "type": "string",
                      "description": "SHA-256 hash of the image",
                      "example": "93a08bd10cd367bf83f12ba6590fcaef2f8deec8a47ce4ce88a15c7dda325ffa"
                    }
                  },
                  "required": [
                    "summary",
                    "isSafe",
                    "confidence",
                    "description",
                    "riskScores",
                    "topics",
                    "nsfwCategories",
                    "suggestedActions",
                    "hash"
                  ]
                }
              }
            }
          },
          "201": {
            "description": "Returns 201 moderation created with the id",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": { "id": { "type": "string" } },
                  "required": ["id"]
                }
              }
            }
          }
        }
      }
    },
    "/image/{id}": {
      "get": {
        "security": [{ "Bearer": [] }],
        "parameters": [
          {
            "schema": {
              "type": "string",
              "minLength": 3,
              "example": "27fbdc0b-b295-46ce-93f5-81b2fc08a381"
            },
            "required": true,
            "name": "id",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Fetch a image moderation by its ID",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "summary": {
                      "type": "object",
                      "properties": {
                        "totalFlags": {
                          "type": "number",
                          "description": "Total flags",
                          "example": 1
                        },
                        "contentRating": {
                          "type": "string",
                          "description": "Content rating of the image (e.g. G, PG, PG-13, R, NC-17)",
                          "example": "G"
                        },
                        "language": {
                          "type": "string",
                          "description": "The language code of the text, eg. en, fr, de",
                          "example": "en"
                        }
                      },
                      "required": ["totalFlags", "contentRating", "language"]
                    },
                    "isSafe": {
                      "type": "boolean",
                      "description": "Whether the image is considered safe",
                      "example": true
                    },
                    "confidence": {
                      "type": "number",
                      "description": "Confidence of the safety of the image from 1-100",
                      "example": 90
                    },
                    "description": {
                      "type": "string",
                      "description": "A short description of what the image depicts",
                      "example": "This is a description"
                    },
                    "riskScores": {
                      "type": "object",
                      "properties": {
                        "overall": {
                          "type": "number",
                          "description": "Overall risk score from 1-100",
                          "example": 90
                        },
                        "spam": {
                          "type": "number",
                          "description": "Score from 1-100 wether the image is spam",
                          "example": 90
                        },
                        "toxicity": {
                          "type": "number",
                          "description": "Score from 1-100 wether the image is malicious/toxic",
                          "example": 90
                        }
                      },
                      "required": ["overall", "spam", "toxicity"]
                    },
                    "topics": {
                      "type": "array",
                      "items": { "type": "string" },
                      "description": "General topics the image depicts, lowercase and no punctuation",
                      "example": ["politics", "sports"]
                    },
                    "nsfwCategories": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "category": {
                            "type": "string",
                            "description": "The category",
                            "example": "sexual"
                          },
                          "severity": {
                            "type": "number",
                            "description": "Severity level of the category from 1-100",
                            "example": 90
                          }
                        },
                        "required": ["category", "severity"]
                      },
                      "example": [{ "category": "sexual", "severity": 90 }]
                    },
                    "suggestedActions": {
                      "type": "object",
                      "properties": {
                        "reject": {
                          "type": "boolean",
                          "description": "Whether to reject the image",
                          "example": true
                        },
                        "review": {
                          "type": "boolean",
                          "description": "Whether to flag the image",
                          "example": true
                        }
                      },
                      "required": ["reject", "review"]
                    },
                    "meta": {
                      "nullable": true,
                      "description": "The metadata of the request",
                      "example": "This is the metadata"
                    },
                    "hash": {
                      "type": "string",
                      "description": "SHA-256 hash of the image",
                      "example": "93a08bd10cd367bf83f12ba6590fcaef2f8deec8a47ce4ce88a15c7dda325ffa"
                    }
                  },
                  "required": [
                    "summary",
                    "isSafe",
                    "confidence",
                    "description",
                    "riskScores",
                    "topics",
                    "nsfwCategories",
                    "suggestedActions",
                    "hash"
                  ]
                }
              }
            }
          }
        }
      },
      "delete": {
        "security": [{ "Bearer": [] }],
        "parameters": [
          {
            "schema": {
              "type": "string",
              "minLength": 3,
              "example": "27fbdc0b-b295-46ce-93f5-81b2fc08a381"
            },
            "required": true,
            "name": "id",
            "in": "path"
          }
        ],
        "responses": { "204": { "description": "No content" } }
      }
    },
    "/queues/{queueId}": {
      "post": {
        "security": [{ "Bearer": [] }],
        "requestBody": {
          "description": "image",
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "enum": ["text", "image"],
                    "description": "Type of content to moderate",
                    "example": "text"
                  },
                  "content": {
                    "type": "string",
                    "description": "The content to moderate. Can either be a text, url or base64 encoded image",
                    "example": "This is a very cool api"
                  },
                  "meta": {
                    "type": "object",
                    "properties": {},
                    "description": "Any metadata you want to store with the content",
                    "example": "{}"
                  },
                  "actorId": {
                    "type": "string",
                    "description": "An ID of a user that is performing an action in your system",
                    "example": "123"
                  }
                },
                "required": ["type", "content"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Response of the created queue item",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": { "type": "string" },
                    "status": {
                      "type": "string",
                      "enum": ["processing", "pending"]
                    }
                  },
                  "required": ["id", "status"]
                }
              }
            }
          },
          "404": { "description": "Queue not found" }
        }
      }
    },
    "/queues/{queueId}/items/{itemId}": {
      "get": {
        "security": [{ "Bearer": [] }],
        "parameters": [
          {
            "schema": {
              "type": "string",
              "minLength": 3,
              "example": "27fbdc0b-b295-46ce-93f5-81b2fc08a381"
            },
            "required": true,
            "name": "id",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Fetch a queue item by its ID",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": { "type": "string" },
                    "type": { "type": "string", "enum": ["text", "image"] },
                    "accepted": { "type": "boolean" },
                    "status": {
                      "type": "string",
                      "enum": ["pending", "accepted", "rejected", "error"]
                    },
                    "content": { "type": "string" },
                    "moderation": { "nullable": true }
                  },
                  "required": ["id", "type", "accepted", "status", "content"]
                }
              }
            }
          },
          "404": { "description": "Queue item not found" }
        }
      }
    }
  }
}
