Azure AI Content Safety — Java SDK Quick Reference
Condensed from azure-ai-contentsafety-java. Full patterns (blocklist management, image moderation, 8-severity) in the azure-ai-contentsafety-java plugin skill if installed.
Install
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-ai-contentsafety</artifactId>
<version>1.1.0-beta.1</version>
</dependency>Quick Start
import com.azure.ai.contentsafety.ContentSafetyClient;
import com.azure.ai.contentsafety.ContentSafetyClientBuilder;
import com.azure.ai.contentsafety.BlocklistClient;
import com.azure.ai.contentsafety.BlocklistClientBuilder;
ContentSafetyClient client = new ContentSafetyClientBuilder()
.endpoint(endpoint).credential(credential).buildClient();Non-Obvious Patterns
- Two separate builders:
ContentSafetyClientBuilderandBlocklistClientBuilder - Image from file:
new ContentSafetyImageData().setContent(BinaryData.fromBytes(bytes)) - Image from URL:
new ContentSafetyImageData().setBlobUrl(url) - Blocklist create uses raw
BinaryData+RequestOptions(not typed model)
Best Practices
- Blocklist changes take ~5 minutes to take effect
- Only request needed categories to reduce latency
- Typically block severity >= 4 for strict moderation
- Process multiple items in parallel for throughput
- Cache blocklist results where appropriate