Events
17 Mar, 21 - 21 Mar, 10
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
The custom categories (rapid) API lets you quickly respond to emerging harmful content incidents. You can define an incident with a few examples in a specific topic, and the service will start detecting similar content.
Follow these steps to define an incident with a few examples of text content and then analyze new text content to see if it matches the incident.
Important
This new feature is only available in select Azure regions. See Region availability.
Caution
The sample data in this guide might contain offensive content. User discretion is advised.
Use the sample code in this section to create a text incident, add samples to the incident, deploy the incident, and then detect text incidents.
In the commands below, replace <your_api_key>
, <your_endpoint>
, and other necessary parameters with your own values.
The following command creates an incident with a name and definition.
curl --location --request PATCH 'https://<endpoint>/contentsafety/text/incidents/<text-incident-name>?api-version=2024-02-15-preview' \
--header 'Ocp-Apim-Subscription-Key: <your-content-safety-key>' \
--header 'Content-Type: application/json' \
--data '{ \"incidentName\": \"<test-incident>\", \"incidentDefinition\": \"<string>\"}'
Use the following command to add text examples to the incident.
curl --location 'https://<endpoint>/contentsafety/text/incidents/<text-incident-name>:addIncidentSamples?api-version=2024-02-15-preview' \
--header 'Ocp-Apim-Subscription-Key: <your-content-safety-key>' \
--header 'Content-Type: application/json' \
--data-raw '{
\"IncidentSamples\": [
{ \"text\": \"<text-example-1>\"},
{ \"text\": \"<text-example-2>\"},
...
]
}'
Use the following command to deploy the incident, making it available for the analysis of new content.
curl --location 'https://<endpoint>/contentsafety/text/incidents/<text-incident-name>:deploy?api-version=2024-02-15-preview' \
--header 'Ocp-Apim-Subscription-Key: <your-content-safety-key>' \
--header 'Content-Type: application/json'
Run the following command to analyze sample text content for the incident you just deployed.
curl --location 'https://<endpoint>/contentsafety/text:detectIncidents?api-version=2024-02-15-preview' \
--header 'Ocp-Apim-Subscription-Key: <your-content-safety-key>' \
--header 'Content-Type: application/json' \
--data '{
\"text\": \"<test-text>\",
\"incidentNames\": [
\"<text-incident-name>\"
]
}'
Use the sample code in this section to create an image incident, add samples to the incident, deploy the incident, and then detect image incidents.
In the commands below, replace <your_api_key>
, <your_endpoint>
, and other necessary parameters with your own values.
The following command creates an image incident:
curl --location --request PATCH 'https://<endpoint>/contentsafety/image/incidents/<image-incident-name>?api-version=2024-02-15-preview' \
--header 'Ocp-Apim-Subscription-Key: <your-content-safety-key>' \
--header 'Content-Type: application/json' \
--data '{
\"incidentName\": \"<image-incident-name>\"
}'
Use the following command to add examples images to your incident. The image samples can be URLs pointing to images in an Azure blob storage container, or they can be Base64 strings.
curl --location 'https://<endpoint>/contentsafety/image/incidents/<image-incident-name>:addIncidentSamples?api-version=2024-02-15-preview' \
--header 'Ocp-Apim-Subscription-Key: <your-content-safety-key>' \
--header 'Content-Type: application/json' \
--data '{
\"IncidentSamples\": [
{
\"image\": {
\"content\": \"<base64-data>\",
\"bloburl\": \"<your-blob-storage-url>.png\"
}
}
]
}'
Use the following command to deploy the incident, making it available for the analysis of new content.
curl --location 'https://<endpoint>/contentsafety/image/incidents/<image-incident-name>:deploy?api-version=2024-02-15-preview' \
--header 'Ocp-Apim-Subscription-Key: <your-content-safety-key>' \
--header 'Content-Type: application/json'
Use the following command to upload a sample image and test it against the incident you deployed. You can either use a URL pointing to the image in an Azure blob storage container, or you can add the image data as a Base64 string.
curl --location 'https://<endpoint>/contentsafety/image:detectIncidents?api-version=2024-02-15-preview' \
--header 'Ocp-Apim-Subscription-Key: <your-content-safety-key>' \
--header 'Content-Type: application/json' \
--data '{
\"image\": {
\"url\": \"<your-blob-storage-url>/image.png\",
"content": "<base64-data>"
},
\"incidentNames\": [
\"<image-incident-name>\"
]
}
}'
The following operations are useful for managing incidents and incident samples.
curl --location GET 'https://<endpoint>/contentsafety/text/incidents?api-version=2024-02-15-preview' \
--header 'Ocp-Apim-Subscription-Key: <your-content-safety-key>'
curl --location GET 'https://<endpoint>/contentsafety/text/incidents/<text-incident-name>?api-version=2024-02-15-preview' \
--header 'Ocp-Apim-Subscription-Key: <your-content-safety-key>'
curl --location --request DELETE 'https://<endpoint>/contentsafety/text/incidents/<text-incident-name>?api-version=2024-02-15-preview' \
--header 'Ocp-Apim-Subscription-Key: <your-content-safety-key>'
This command retrieves the unique IDs of all the samples associated with a given incident object.
curl --location GET 'https://<endpoint>/contentsafety/text/incidents/<text-incident-name>/incidentsamples?api-version=2024-02-15-preview' \
--header 'Ocp-Apim-Subscription-Key: <your-content-safety-key>'
Use an incident sample ID to look up details about the sample.
curl --location GET 'https://<endpoint>/contentsafety/text/incidents/<text-incident-name>/incidentsamples/<your-incident-sample-id>?api-version=2024-02-15-preview' \
--header 'Ocp-Apim-Subscription-Key: <your-content-safety-key>'
Use an incident sample ID to retrieve and delete that sample.
curl --location 'https://<endpoint>/contentsafety/text/incidents/<text-incident-name>:removeIncidentSamples?api-version=2024-02-15-preview' \
--header 'Ocp-Apim-Subscription-Key: <your-content-safety-key>' \
--header 'Content-Type: application/json' \
--data '{
\"IncidentSampleIds\": [
\"<your-incident-sample-id>\"
]
}'
curl --location GET 'https://<endpoint>/contentsafety/image/incidents?api-version=2024-02-15-preview' \
--header 'Ocp-Apim-Subscription-Key: <your-content-safety-key>'
curl --location GET 'https://<endpoint>/contentsafety/image/incidents/<image-incident-name>?api-version=2024-02-15-preview' \
--header 'Ocp-Apim-Subscription-Key: <your-content-safety-key>'
curl --location --request DELETE 'https://<endpoint>/contentsafety/image/incidents/<image-incident-name>?api-version=2024-02-15-preview' \
--header 'Ocp-Apim-Subscription-Key: <your-content-safety-key>'
This command retrieves the unique IDs of all the samples associated with a given incident object.
curl --location GET 'https://<endpoint>/contentsafety/image/incidents/<image-incident-name>/incidentsamples?api-version=2024-02-15-preview' \
--header 'Ocp-Apim-Subscription-Key: <your-content-safety-key>'
Use an incident sample ID to look up details about the sample.
curl --location GET 'https://<endpoint>/contentsafety/image/incidents/<image-incident-name>/incidentsamples/<your-incident-sample-id>?api-version=2024-02-15-preview' \
--header 'Ocp-Apim-Subscription-Key: <your-content-safety-key>'
Use an incident sample ID to retrieve and delete that sample.
curl --location 'https://<endpoint>/contentsafety/image/incidents/<image-incident-name>:removeIncidentSamples?api-version=2024-02-15-preview' \
--header 'Ocp-Apim-Subscription-Key: <your-content-safety-key>' \
--header 'Content-Type: application/json' \
--data '{
\"IncidentSampleIds\": [
\"<your-incident-sample-id>\"
]
}'
Events
17 Mar, 21 - 21 Mar, 10
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowTraining
Module
Use AI responsibly with Azure AI Content Safety - Training
As the amount of user-generated online content increases, so does the need to ensure harmful material is moderated effectively. Azure AI Content Safety resource includes features to help organizations moderate and manage both user-generated and AI-generated content.
Certification
Microsoft Certified: Security Operations Analyst Associate - Certifications
Investigate, search for, and mitigate threats using Microsoft Sentinel, Microsoft Defender for Cloud, and Microsoft 365 Defender.
Documentation
Quickstart: Custom categories (preview) - Azure AI services
Use the custom categories API to create your own content categories and train the Content Safety model for your use case.
Embedded content safety - Azure AI Content Safety - Azure AI services
Embedded content safety is designed for on-device scenarios where cloud connectivity is intermittent or unavailable.
Harm categories in Azure AI Content Safety - Azure AI services
Learn about the different content moderation flags and severity levels that the Azure AI Content Safety service returns.