Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Guidance for building and deploying AI solutions on Azure using Azure AI services and Copilot for Azure
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/sdk/azure-ai-contentsafety-ts.md
1# Azure AI Content Safety — TypeScript SDK Quick Reference23> Condensed from **azure-ai-contentsafety-ts**. Full patterns (blocklist CRUD, image moderation, severity thresholds)4> in the **azure-ai-contentsafety-ts** plugin skill if installed.56## Install7```bash8npm install @azure-rest/ai-content-safety @azure/identity @azure/core-auth9```1011## Quick Start12```typescript13import ContentSafetyClient, { isUnexpected } from "@azure-rest/ai-content-safety";14import { AzureKeyCredential } from "@azure/core-auth";15const client = ContentSafetyClient(endpoint, new AzureKeyCredential(key));16```1718## Non-Obvious Patterns19- REST client — `ContentSafetyClient` is a function, not a class20- Text: `client.path("/text:analyze").post({ body: { text, categories: [...] } })`21- Image: `client.path("/image:analyze").post({ body: { image: { content: base64 } } })`22- Blocklist create: `.path("/text/blocklists/{blocklistName}", name).patch({...})`23- API key import: `AzureKeyCredential` from `@azure/core-auth` (not `@azure/identity`)2425## Best Practices261. Always use `isUnexpected()` — type guard for error handling272. Set appropriate thresholds — different categories may need different severity levels283. Use blocklists for domain-specific terms to supplement AI detection294. Log moderation decisions — keep audit trail for compliance305. Handle edge cases — empty text, very long text, unsupported image formats31