The AI Guardrails SDK lets you call the Content Moderation API to detect and moderate images, videos, audio, and text. This page explains which API call mode to use for each content type and how to get the SDK.
How it works
All four content types — images, videos, audio, and text — share a common pattern:
Synchronous detection: Submit content and receive results in the same response. Best for single items where you need an immediate result.
Asynchronous detection: Submit content and get back a
taskId. Poll for results using thetaskId, or configure a callback URL to receive results automatically. Best for batch workloads or large files.
The table below shows which mode is available for each content type and which is recommended.
| Content type | Synchronous | Asynchronous | Recommended mode |
|---|---|---|---|
| Image | Available | Available | Asynchronous for batch; synchronous (one image recommended per request) |
| Video | Frame sequences only | Full video detection | Asynchronous |
| Audio | Not available | Available | Asynchronous (only option) |
| Text | Available | Not available | Synchronous (only option) |
When you use one API for multiple detection scenarios, the total fee is calculated as: price per scenario × amount of content detected.
API capabilities by content type
Image detection
Image detection features — including pornography detection, terrorist content detection, optical character recognition (OCR), and logo detection — are all available through a single API.
Synchronous image detection API
Submit one or more images and receive all detection results in the response. For best accuracy, submit one image per request.
Asynchronous image detection API
Submit images in batches. The API returns a taskId for each image. After submission, use the taskId to retrieve the detection results. Use this mode for batch image detection.
Video detection
Video detection features — including pornography detection, terrorist content detection, and logo detection — are all available through a single API.
Synchronous video detection API
Supports detection of image frame sequences extracted from a video only. This method is not recommended. Use the asynchronous API for full video detection.
Asynchronous video detection API
Submit a video detection task and retrieve results using the taskId, or set a callback URL to receive results when detection is complete. Use this mode for video content detection.
Audio moderation
The audio moderation API supports detection of both audio streams and audio files. Only an asynchronous API is available. After submitting a detection task, retrieve results using the taskId or set a callback URL to receive callback notifications.
Text moderation
Only a synchronous API is available for text moderation. Submit one or more text entries per request and receive detection results in the response.
Prerequisites
Before you begin, complete the following steps.
Step 1: Install the SDK for your language
The AI Guardrails SDK is available for the following languages:
Step 2: Download the code examples
Download green-sdk-sample_doc for complete code examples in Java, PHP, and Python.
API versions earlier than 2018-05-09 are offline. If you receive an HTTP status code 400 error with error code InvalidAction.NotFound, switch to API version 2018-05-09.
Step 3: (Optional) Use a third-party SDK for other languages
If your language is not listed above — such as C#, C++, Node.js, or Python 3.5 — call the AI Guardrails API directly over HTTP, or use a third-party SDK.
Alibaba Cloud does not provide maintenance for third-party SDKs. They are listed for reference only.
What's next
Review the API overview to understand the full API surface before making your first call.
Follow the installation guide for your language to configure your credentials and make your first detection request.