# Moderate Image Source: https://docs.contentmod.io/api-reference/image/create POST /image # Delete Image Mod Source: https://docs.contentmod.io/api-reference/image/delete DELETE /text/{id} # Get Image Mod Source: https://docs.contentmod.io/api-reference/image/get GET /image/{id} # Introduction Source: https://docs.contentmod.io/api-reference/introduction Example section for showcasing API endpoints > [!NOTE] > > Check out our [SDKs](/sdks) section if you are using one of the languages we support. > **[ContentMod Endpoints](https://api.contentmod.io/doc)** > > View the OpenAPI specification file ## Authentication All API endpoints are authenticated using Bearer tokens and picked up from the specification file. ```json theme={null} "security": [ { "bearerAuth": [] } ] ``` # Add Queue Item Source: https://docs.contentmod.io/api-reference/queues/create POST /queues/{queueId} # Get Queue Item Source: https://docs.contentmod.io/api-reference/queues/get-item GET /queues/{queueId}/items/{itemId} # Moderate Text Source: https://docs.contentmod.io/api-reference/text/create POST /text # Delete Text Mod Source: https://docs.contentmod.io/api-reference/text/delete DELETE /text/{id} # Get Text Mod Source: https://docs.contentmod.io/api-reference/text/get GET /text/{id} # Discord Source: https://docs.contentmod.io/integrations/discord How to start moderating your Discord server with ContentMod. ![](https://mintcdn.com/contentmod/GotvW6r7XKcIHJdj/assets/discord-dm.png?fit=max\&auto=format\&n=GotvW6r7XKcIHJdj\&q=85\&s=c75050d1691b702ac3108efb6a078555) ## Getting Started To get started with ContentMod on Discord, you will need to add our bot to your server. You can do this by clicking the button below: [![](/assets/discord-mark.svg) Open in Discord](https://discord.com/oauth2/authorize?client_id=1305812211616452678\&permissions=395137203206\&integration_type=0\&scope=bot) Or by finding our app in the Discord App directory or by visiting this link: [https://discord.com/application-directory/1305812211616452678](https://discord.com/application-directory/1305812211616452678) ## Connecting your Discord server Once you have added the bot to your server, you will need to connect it to your ContentMod account. To do this, follow these steps: 1. Open the Discord server where you want to moderate. 2. In the chat, type `/connect` and press enter. 3. A message will appear asking to you to open the ContentMod dashboard. Click the link to open it. 4. Once you have opened the dashboard and logged in you will be taken to the screen to connect your Discord server. ![](https://mintcdn.com/contentmod/GotvW6r7XKcIHJdj/assets/discord-connect.png?fit=max\&auto=format\&n=GotvW6r7XKcIHJdj\&q=85\&s=7b6466eb433475a294af6643de128252) ## Removing the app If at any point you want to Disconnect the bot from your ContentMod account You can write the following command in the Discord server: `/disconnect` Running this command will prompt you to confirm the action. Once you confirm, the integration will be removed. To fully remove the app either uninstall the app in the Discord App directory or kick the bot from the server. # Introduction Source: https://docs.contentmod.io/introduction Welcome to ContentMod, a powerful and efficient **content moderation API** designed to help you ensure a safe, compliant, and user-friendly environment for your digital platforms. With our API, you can seamlessly analyze and moderate both **text** and **images**, while extracting relevant information tailored to your specific needs." ## Key Features 1. **Text Moderation**: Detect and flag inappropriate, harmful, or non-compliant content such as hate speech, profanity, and personal data leaks. 2. **Image Moderation**: Identify explicit, offensive, or otherwise restricted visual content with robust AI-powered image analysis. 3. **Information Extraction**: Extract relevant details, including flagged keywords, image tags, sentiment analysis, and metadata, for actionable insights. 4. **Customizable Rules**: Tailor moderation parameters to meet your specific requirements, ensuring precision and relevance. 5. **Real-time Performance**: Achieve rapid results with low latency, suitable for real-time applications. ## Why Choose ContentMod? * **Scalable**: Designed to handle workloads of all sizes, from startups to enterprise-level applications. * **Secure**: Built with data privacy and security in mind, ensuring compliance with major regulations such as GDPR and CCPA. * **Developer-Friendly**: Easy-to-integrate RESTful API with detailed documentation and code samples for a smooth development experience. * **Constantly Improving**: Backed by state-of-the-art AI models that are regularly updated to stay ahead of evolving challenges. ## Use Cases * Social media platforms moderating user-generated content. * E-commerce websites ensuring compliance with product listing guidelines. * Educational tools preventing the sharing of inappropriate material. * Corporate tools maintaining safe and productive communication environments. * Any other use case where you need to ensure content quality and safety. With ContentMod, managing content quality and safety becomes effortless. Let us handle moderation so you can focus on building a better experience for your users. ## Getting Started To get started with ContentMod, you can choose to use our SDKs or our APIs. Both options offer similar functionality and are easy to integrate into your project. > **[SDKs](/sdks)** > > Use one of our SDKs to get started with ContentMod > **[APIs](/api-reference)** > > Connect directly to our APIs to get started with ContentMod # Billing Source: https://docs.contentmod.io/projects/billing ### Project-Based Billing with Stripe Billing for ContentMod is managed seamlessly through **Stripe**, ensuring secure and transparent payment processing on a project-by-project basis. #### How It Works: * **Independent Billing**: Each project you create is billed separately, allowing for precise cost tracking and budgeting. * **Secure Payments**: All transactions are processed through Stripe, a trusted global payment platform. * **Flexible Payment Options**: Support for multiple payment methods, including credit/debit cards, digital wallets, and more. * **Detailed Invoices**: Receive individual invoices for each project, making it easy to manage expenses and reconcile payments. #### Benefits: * Perfect for users managing multiple clients or initiatives. * Ensures clear separation of costs across projects. * Easy-to-monitor billing via the Stripe dashboard or our platform. Start managing your project billing effortlessly with **Stripe's** robust and reliable payment infrastructure. # Introduction Source: https://docs.contentmod.io/projects/intro ## Projects and Billing Overview With ContentMod, users have the flexibility to create and manage multiple projects independently. Each project operates in its own sandboxed environment with dedicated resources, quotas, and billing. This structure provides a seamless way to organize and optimize your content moderation workflows. ### Key Highlights: 1. **Independent Projects**: * Each user can create multiple projects tailored to different applications or use cases. * Projects are isolated, ensuring no overlap in quotas or configurations. 2. **Dedicated Quotas**: * Each project comes with its own quota for tokens, API calls, or other resources. * Quotas can be monitored and adjusted individually to suit your requirements. 3. **Separate Billing**: * Projects are billed separately, offering clear and transparent cost tracking. * Receive detailed invoices for each project, making it easy to manage budgets for multiple initiatives. 4. **Flexible Management**: * Easily create, update, or delete projects through the user-friendly dashboard or API. * Configure specific rules, moderation settings, and limits for each project as needed. ### Example Use Case: Suppose you're running a digital agency with multiple clients: * Create a separate project for each client. * Allocate specific token quotas based on the client's subscription tier. * Receive individual billing statements for clear client cost reconciliation. This approach ensures precise resource allocation and expense management, empowering you to focus on delivering value while we handle the complexity. ### Getting Started * **Step 1**: Log in to your account and navigate to the **Projects** section. * **Step 2**: Click **Create New Project** and define its settings. * **Step 3**: Track usage and billing from the dashboard. With ContentMod, managing multiple projects has never been easier. Organize smarter, bill clearer, and scale faster! # Review Queues Source: https://docs.contentmod.io/queues/intro Review queues to moderate content ![](https://mintcdn.com/contentmod/GotvW6r7XKcIHJdj/assets/queue-dashboard.png?fit=max\&auto=format\&n=GotvW6r7XKcIHJdj\&q=85\&s=3a81f7aad595c5fa888e1d6a98b0860a) ## Get started To get started with Review Queues, head to the Create Queue page and follow the steps to create a new queue. Choose wether to create a fully automated queue or a manual queue. ### Fully Automated Queue A fully automated queue will automatically accept or reject content based on the parameters you set when you create the queue. You can choose wether to fully reject content or put it into a manual review. A fully automated queue requires a paid plan to use. ### Manual Review Queue A manual review queue will require you to manually accept or review every single item in the queue. You can set it so it runs the moderation AI to generate a moderation report to help you review the content. A fully manual queue is available for every plan and is free to use forever. ### Posting Content If you are using one of the SDKs, you can head over to the [SDKs](/sdks) section to find out how to post content to a queue. If you are integrating through our API, you can use the [Add Queue Item](/api-reference/queues/create) endpoint to post content to a queue. ### Getting Queue ID Once you have created a queue, you can find the queue ID in the URL of the dashboard. The queue ID is the last part of the URL. Or you can click the Copy button that is next to the name of the queue in the dashboard. ![](https://mintcdn.com/contentmod/GotvW6r7XKcIHJdj/assets/queue-copy.png?fit=max\&auto=format\&n=GotvW6r7XKcIHJdj\&q=85\&s=1f9f12352931d95bd5977882d03cea6b) # Add Queue Item Source: https://docs.contentmod.io/sdks/typescript/add-queue-item Add an item to a queue To add an item to a queue you can use the queue().addItem method. ```ts index.ts theme={null} import { ContentMod } from "@contentmod/sdk"; const contentMod = new ContentMod({ publicKey: "", secretKey: "", }); const queueId = ""; const queue = contentMod.queue(queueId); // Add an item to the queue const res = await queue.addItem({ type: "text", // Can also be image content: "Some bad text", }); ^? // {"id": "27fbdc0b-b295-46ce-93f5-81b2fc08a381", "status": "pending"} console.log(res); // ``` ## Request **type** `string` *required* The type of the item to add to the queue. Example: `text` `image` **content** `string` *required* The content of the item to add to the queue. Either text, image url or base64 encoded image. Example: `Hello world` `https://example.com/image.jpg` `/9j/4AAQSkZJRgABAQAASABIAAD/...` **actorId** `string` An ID of a user that is performing an action in your system. Example: `123` **meta** `object` Any additional metadata you want to include with the moderation request that will be saved. Example: `{"userId": "1234"}` # Get Image Moderation Source: https://docs.contentmod.io/sdks/typescript/get-image Get an image moderation by its ID To get an image moderation by its ID, use the `image.get` function: ```ts index.ts theme={null} import { ContentMod } from "@contentmod/sdk"; const contentMod = new ContentMod({ publicKey: "", secretKey: "", }); const moderationId = ""; const imageMod = await contentMod.image.get(moderationId); console.log(imageMod); ``` Please refer to the [Get Image Api Response](/api-reference/image/get) for more information on the `ImageModerationResponse` object. ## Properties **image** `string` *required* Image to moderate Example: `https://example.com/image.jpg` **options** `object` An object of options for the moderation request **Options** **meta** `object` Any additional metadata you want to include with the moderation request that will be saved. Example:`{"userId": "1234"}` **callbackUrl** `string` A webhook callback url that will be called when the moderation request is completed. Example: `https://example.com/webhook` **defer** `boolean` Whether to defer the moderation request. If this value is true the request will be queued and you will receive the response later in a webhook that you have set up. Or you can look it up later using the id returned. Example: `true` ## Response The `ImageModerationResponse` object contains the following properties: **id** `string` *required* The ID of the moderation request. Example: `27fbdc0b-b295-46ce-93f5-81b2fc08a381` **isSafe** `boolean` *required* Whether the image is considered safe. Example: `true` **confidence** `number` *required* Confidence of the safety of the image from 1-100. Example: `90` **sentiment** `string` *required* Sentiment of the image, either negative, neutral or positive. available sentiment values are: * negative * neutral (default) * positive Example: `positive` **sentimentScore** `number` *required* Sentiment score from 1-100 (negative, neutral, positive). Example: `90` **riskScores** `object` *required* Overall risk score from 1-100. Example: `90` **topics** `array` *required* General topics the image depicts, lowercase and no punctuation. Example: `["politics", "sports"]` **nsfwCategories** `array` *required* An array of the categories of the image. The available categories are: * adult\_content * suggestive\_imagery * strong\_language * violence\_gore * horror\_disturbing * alcohol * tobacco * substance\_use * gambling * dating\_relationship * medical\_procedures" * crude\_humor * political\_content Example: `[{"category": "sexual", "severity": 90}]` **summary** `object` *required* Summary of the image. **Summary** **totalFlags** `number` *required* Total flags. Example: `1` **contentRating** `string` *required* Content rating of the image (e.g. G, PG, PG-13, R, NC-17). Example: `G` **language** `string` *required* The language code of the text, eg. en, fr, de. Example: `en` Example: `{"profanity": true, "totalFlags": 1, "contentRating": "G", "language": "en"}` **suggestedActions** `object` *required* Suggested actions for the image. **Suggested Actions** **reject** `boolean` *required* Whether to reject the image. Example: `true` **review** `boolean` *required* Whether to flag the image. Example: `true` Example: `{"reject": true, "review": true}` **request** `object` *required* The request object. Example: `{"requestId": "27fbdc0b-b295-46ce-93f5-81b2fc08a381", "timestamp": "2023-04-05T12:00:00.000Z"}` **meta** `object` *required* The metadata of the request object that the user provided. Example: `{"userId": "12345"}` **hash** `string` *required* The SHA-256 hash of the image. Used for content comparison purposes. Example: `93a08bd10cd367bf83f12ba6590fcaef2f8deec8a47ce4ce88a15c7dda325ffa` # Get Queue Item Source: https://docs.contentmod.io/sdks/typescript/get-queue-item Get an item that has been added to a queue To get an item that has been added to a queue you can use the `queue().getItem` method. ```ts index.ts theme={null} import { ContentMod } from "@contentmod/sdk"; const contentMod = new ContentMod({ publicKey: "", secretKey: "", }); const queueId = ""; const queue = contentMod.queue(queueId); const itemId = ""; // Add an item to the queue const res = await queue.getItem(itemId); console.log(res); ``` ## Response The `QueueItemResponse` object contains the following properties: **id** `string` *required* The ID of the moderation request. Example: `27fbdc0b-b295-46ce-93f5-81b2fc08a381` **type** `string` *required* The type of the item. Example: `text` **accepted** `boolean` *required* Wether the item has been accepted or not. Example: `true` **status** `string` *required* The status of the item. available status values are: * processing * pending * accepted * rejected Example: `accepted` **content** `string` *required* The original content of the item. Example: `Hello world` **moderation** `object` **Moderation** **id** `string` *required* The ID of the moderation request. Example: `27fbdc0b-b295-46ce-93f5-81b2fc08a381` **isSafe** `boolean` *required* Whether the text is considered safe. Example: `true` **confidence** `number` *required* Confidence of the safety of the text from 1-100. Example: `90` **sentiment** `string` *required* Sentiment of the text, either negative, neutral or positive. available sentiment values are: * negative * neutral (default) * positive Example: `positive` **sentimentScore** `number` *required* Sentiment score from 1-100 (negative, neutral, positive). Example: `90` **riskScores** `object` *required* Overall risk score from 1-100. Example: `90` **topics** `array` *required* General topics the text depicts, lowercase and no punctuation. Example: `["politics", "sports"]` **nsfwCategories** `array` *required* An array of the categories of the text. The available categories are: * adult\_content * suggestive\_imagery * strong\_language * violence\_gore * horror\_disturbing * alcohol * tobacco * substance\_use * gambling * dating\_relationship * medical\_procedures" * crude\_humor * political\_content Example: `[{"category": "sexual", "severity": 90}]` **summary** `object` *required* Summary of the text. Example: `{"profanity": true, "totalFlags": 1, "contentRating": "G", "language": "en"}` **suggestedActions** `object` *required* Suggested actions for the text. **Suggested Actions** **reject** `boolean` *required* Whether to reject the text. Example: `true` **review** `boolean` *required* Whether to flag the text. Example: `true` Example: `{"reject": true, "review": true}` **content** `string` *required* The original text. Example: `This is the original text` **filteredContent** `string` *required* The text with profanity replaced by \*. Example: `This is a filtered text` **request** `object` *required* The request object. Example: `{"requestId": "27fbdc0b-b295-46ce-93f5-81b2fc08a381", "timestamp": "2023-04-05T12:00:00.000Z"}` **meta** `object` *required* The metadata of the request object that the user provided. Example: `{"userId": "12345"}` **hash** `string` *required* The SHA-256 hash of the text. Used for content comparison purposes. Example: `93a08bd10cd367bf83f12ba6590fcaef2f8deec8a47ce4ce88a15c7dda325ffa` # Get Text Moderation Source: https://docs.contentmod.io/sdks/typescript/get-text Get a text moderation by its ID To get a text moderation by its ID, use the `text.get` function: ```ts index.ts theme={null} import { ContentMod } from "@contentmod/sdk"; const contentMod = new ContentMod({ publicKey: "", secretKey: "", }); const moderationId = ""; const textMod = await contentMod.text.get(moderationId); console.log(textMod); ``` Please refer to the [Get Text Api Response](/api-reference/text/get) for more information on the `TextModerationResponse` object. ## Properties **text** `string` *required* Text to moderate Example: `Some bad text` **options** `object` An object of options for the moderation request **Options** **meta** `object` Any additional metadata you want to include with the moderation request that will be saved. Example:`{"userId": "1234"}` **callbackUrl** `string` A webhook callback url that will be called when the moderation request is completed. Example: `https://example.com/webhook` **defer** `boolean` Whether to defer the moderation request. If this value is true the request will be queued and you will receive the response later in a webhook that you have set up. Or you can look it up later using the id returned. Example: `true` ## Response The `TextModerationResponse` object contains the following properties: **id** `string` *required* The ID of the moderation request. Example: `27fbdc0b-b295-46ce-93f5-81b2fc08a381` **isSafe** `boolean` *required* Whether the text is considered safe. Example: `true` **confidence** `number` *required* Confidence of the safety of the text from 1-100. Example: `90` **sentiment** `string` *required* Sentiment of the text, either negative, neutral or positive. available sentiment values are: * negative * neutral (default) * positive Example: `positive` **sentimentScore** `number` *required* Sentiment score from 1-100 (negative, neutral, positive). Example: `90` **riskScores** `object` *required* Overall risk score from 1-100. Example: `90` **topics** `array` *required* General topics the text depicts, lowercase and no punctuation. Example: `["politics", "sports"]` **nsfwCategories** `array` *required* An array of the categories of the text. The available categories are: * adult\_content * suggestive\_imagery * strong\_language * violence\_gore * horror\_disturbing * alcohol * tobacco * substance\_use * gambling * dating\_relationship * medical\_procedures" * crude\_humor * political\_content Example: `[{"category": "sexual", "severity": 90}]` **summary** `object` *required* Summary of the text. Example: `{"profanity": true, "totalFlags": 1, "contentRating": "G", "language": "en"}` **suggestedActions** `object` *required* Suggested actions for the text. **Suggested Actions** **reject** `boolean` *required* Whether to reject the text. Example: `true` **review** `boolean` *required* Whether to flag the text. Example: `true` Example: `{"reject": true, "review": true}` **content** `string` *required* The original text. Example: `This is the original text` **filteredContent** `string` *required* The text with profanity replaced by \*. Example: `This is a filtered text` **request** `object` *required* The request object. Example: `{"requestId": "27fbdc0b-b295-46ce-93f5-81b2fc08a381", "timestamp": "2023-04-05T12:00:00.000Z"}` **meta** `object` *required* The metadata of the request object that the user provided. Example: `{"userId": "12345"}` **hash** `string` *required* The SHA-256 hash of the text. Used for content comparison purposes. Example: `93a08bd10cd367bf83f12ba6590fcaef2f8deec8a47ce4ce88a15c7dda325ffa` # Installation Source: https://docs.contentmod.io/sdks/typescript/installation Installation instructions for the Typescript SDK ## Installation The ContentMod Typescript SDK is available on npm. To install it, run the following command: ```bash npm theme={null} npm i @contentmod/sdk ``` ```bash yarn theme={null} yarn add @contentmod/sdk ``` ```bash pnpm theme={null} pnpm add @contentmod/sdk ``` ```bash bun theme={null} bun add @contentmod/sdk ``` ## Initializing the Client To initialize the client with your access key and secret key, you can use the following code: ```ts index.ts theme={null} import { ContentMod } from "@contentmod/sdk"; const contentMod = new ContentMod({ publicKey: "", secretKey: "", }); ``` # Moderate Image Source: https://docs.contentmod.io/sdks/typescript/moderate-image Moderate image using the Typescript SDK ## Moderate Image To moderate image, you can use the `image.moderate` method. This method takes in a image string and returns a `Promise` that resolves to a `ImageModerationResponse` object. ### Image from URL ```ts index.ts theme={null} const contentMod = new ContentMod({ publicKey: "", secretKey: "", }); // Simple image moderation with a link const response = await contentMod.image.moderate( "https://example.com/image.jpg" ); // Image moderation with additional metadata to be saved with the moderation request const response2 = await contentMod.image.moderate( "https://example.com/image.jpg", { meta: { userId: "1234", }, } ); // Optionally you can pass in an webhook callback url if you want to be notified when the moderation request is completed const response3 = await contentMod.image.moderate( "https://example.com/image.jpg", { meta: { userId: "1234", }, callbackUrl: "https://example.com/webhook", } ); ``` ### Webhook Callback If you pass in a webhook callback url, the response will only be an object with the `id` property. ### Image from Base64 encoded string ```ts index.ts theme={null} import { ContentMod } from "@contentmod/sdk"; import fs from "fs"; const contentMod = new ContentMod({ publicKey: "", secretKey: "", }); // Read file from disk const img = fs.readFileSync("./pingu.jpeg"); // Convert to base64 encoded string const base64 = img.toString("base64"); // Submit image moderation const imgResponse = await contentMod.image.moderate(base64, { meta: { userId: "1234", }, }); ``` ## Properties **image** `string` *required* Image to moderate Example: `https://example.com/image.jpg` **options** `object` An object of options for the moderation request **Options** **meta** `object` Any additional metadata you want to include with the moderation request that will be saved. Example:`{"userId": "1234"}` **callbackUrl** `string` A webhook callback url that will be called when the moderation request is completed. Example: `https://example.com/webhook` **defer** `boolean` Whether to defer the moderation request. If this value is true the request will be queued and you will receive the response later in a webhook that you have set up. Or you can look it up later using the id returned. Example: `true` ## Response The `ImageModerationResponse` object contains the following properties: **id** `string` *required* The ID of the moderation request. Example: `27fbdc0b-b295-46ce-93f5-81b2fc08a381` **isSafe** `boolean` *required* Whether the image is considered safe. Example: `true` **confidence** `number` *required* Confidence of the safety of the image from 1-100. Example: `90` **sentiment** `string` *required* Sentiment of the image, either negative, neutral or positive. available sentiment values are: * negative * neutral (default) * positive Example: `positive` **sentimentScore** `number` *required* Sentiment score from 1-100 (negative, neutral, positive). Example: `90` **riskScores** `object` *required* Overall risk score from 1-100. Example: `90` **topics** `array` *required* General topics the image depicts, lowercase and no punctuation. Example: `["politics", "sports"]` **nsfwCategories** `array` *required* An array of the categories of the image. The available categories are: * adult\_content * suggestive\_imagery * strong\_language * violence\_gore * horror\_disturbing * alcohol * tobacco * substance\_use * gambling * dating\_relationship * medical\_procedures" * crude\_humor * political\_content Example: `[{"category": "sexual", "severity": 90}]` **summary** `object` *required* Summary of the image. **Summary** **totalFlags** `number` *required* Total flags. Example: `1` **contentRating** `string` *required* Content rating of the image (e.g. G, PG, PG-13, R, NC-17). Example: `G` **language** `string` *required* The language code of the text, eg. en, fr, de. Example: `en` Example: `{"profanity": true, "totalFlags": 1, "contentRating": "G", "language": "en"}` **suggestedActions** `object` *required* Suggested actions for the image. **Suggested Actions** **reject** `boolean` *required* Whether to reject the image. Example: `true` **review** `boolean` *required* Whether to flag the image. Example: `true` Example: `{"reject": true, "review": true}` **request** `object` *required* The request object. Example: `{"requestId": "27fbdc0b-b295-46ce-93f5-81b2fc08a381", "timestamp": "2023-04-05T12:00:00.000Z"}` **meta** `object` *required* The metadata of the request object that the user provided. Example: `{"userId": "12345"}` **hash** `string` *required* The SHA-256 hash of the image. Used for content comparison purposes. Example: `93a08bd10cd367bf83f12ba6590fcaef2f8deec8a47ce4ce88a15c7dda325ffa` # Moderate Text Source: https://docs.contentmod.io/sdks/typescript/moderate-text Moderate text using the Typescript SDK ## Moderate Text To moderate text, you can use the `text.moderate` method. This method takes in a text string and returns a `Promise` that resolves to a `TextModerationResponse` object. ```ts index.ts theme={null} const contentMod = new ContentMod({ publicKey: "", secretKey: "", }); // Simple text moderation const response = await contentMod.text.moderate("Some bad text"); // Text moderation with additional metadata to be saved with the moderation request const response2 = await contentMod.text.moderate("Some bad text", { meta: { userId: "1234", }, }); // Optionally you can pass in an webhook callback url if you want to be notified when the moderation request is completed const response3 = await contentMod.text.moderate("Some bad text", { callbackUrl: "https://example.com/webhook", }); ``` ### Webhook Callback If you pass in a webhook callback url, the response will only be an object with the `id` property. ## Properties **text** `string` *required* Text to moderate Example: `Some bad text` **options** `object` An object of options for the moderation request **Options** **meta** `object` Any additional metadata you want to include with the moderation request that will be saved. Example:`{"userId": "1234"}` **callbackUrl** `string` A webhook callback url that will be called when the moderation request is completed. Example: `https://example.com/webhook` **defer** `boolean` Whether to defer the moderation request. If this value is true the request will be queued and you will receive the response later in a webhook that you have set up. Or you can look it up later using the id returned. Example: `true` ## Response The `TextModerationResponse` object contains the following properties: **id** `string` *required* The ID of the moderation request. Example: `27fbdc0b-b295-46ce-93f5-81b2fc08a381` **isSafe** `boolean` *required* Whether the text is considered safe. Example: `true` **confidence** `number` *required* Confidence of the safety of the text from 1-100. Example: `90` **sentiment** `string` *required* Sentiment of the text, either negative, neutral or positive. available sentiment values are: * negative * neutral (default) * positive Example: `positive` **sentimentScore** `number` *required* Sentiment score from 1-100 (negative, neutral, positive). Example: `90` **riskScores** `object` *required* Overall risk score from 1-100. Example: `90` **topics** `array` *required* General topics the text depicts, lowercase and no punctuation. Example: `["politics", "sports"]` **nsfwCategories** `array` *required* An array of the categories of the text. The available categories are: * adult\_content * suggestive\_imagery * strong\_language * violence\_gore * horror\_disturbing * alcohol * tobacco * substance\_use * gambling * dating\_relationship * medical\_procedures" * crude\_humor * political\_content Example: `[{"category": "sexual", "severity": 90}]` **summary** `object` *required* Summary of the text. Example: `{"profanity": true, "totalFlags": 1, "contentRating": "G", "language": "en"}` **suggestedActions** `object` *required* Suggested actions for the text. **Suggested Actions** **reject** `boolean` *required* Whether to reject the text. Example: `true` **review** `boolean` *required* Whether to flag the text. Example: `true` Example: `{"reject": true, "review": true}` **content** `string` *required* The original text. Example: `This is the original text` **filteredContent** `string` *required* The text with profanity replaced by \*. Example: `This is a filtered text` **request** `object` *required* The request object. Example: `{"requestId": "27fbdc0b-b295-46ce-93f5-81b2fc08a381", "timestamp": "2023-04-05T12:00:00.000Z"}` **meta** `object` *required* The metadata of the request object that the user provided. Example: `{"userId": "12345"}` **hash** `string` *required* The SHA-256 hash of the text. Used for content comparison purposes. Example: `93a08bd10cd367bf83f12ba6590fcaef2f8deec8a47ce4ce88a15c7dda325ffa` # Webhooks Source: https://docs.contentmod.io/sdks/typescript/webhooks Parse webhooks received from ContentMod We provide a utility function to parse webhooks received from ContentMod and make them Type safe. To parse a webhook, you can use the `parseWebhook` function. ```ts index.ts theme={null} import { ContentMod, WebhookEvent } from "@contentmod/sdk"; const body = req.body; // JSON body of the POST request. const contentMod = new ContentMod({ publicKey: "", secretKey: "", }); const webhook = contentMod.parseWebhook(body); switch (webhook.event) { case WebhookEvent.ModerationCompleted: console.log("moderation.completed", webhook); break; case WebhookEvent.QueueReviewCompleted: console.log("queue.review.completed", webhook.data.status); break; } console.log(webhook); ```