REST API Code Examples β Python, Node.js, cURL
Analyze, anonymize, encrypt, decrypt PII via REST API. Token-based pricing (200 free tokens). Bearer token auth. Synchronous API. Code examples for Python, Node.js, JavaScript, cURL.
Code Examples
π Python (requests)
import requests
response = requests.post(
"https://anonym.legal/api/presidio/analyze",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={"text": "John Smith, SSN 123-45-6789", "language": "en"},
)
print(response.json()["results"])
π¦ Node.js (fetch)
const response = await fetch(
"https://anonym.legal/api/presidio/analyze",
{
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.API_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
text: "Jane Doe, email jane@ex.com",
language: "en"
})
}
);
const { results } = await response.json();
console.log(results);
API Endpoints
π /analyze
Detect & extract PII entities from text. Returns entity types, positions, confidence scores.
π /anonymize
Replace detected PII with redactions, masks, hashes, or encryption. Returns anonymized text.
π /deanonymize
Decrypt previously encrypted PII. Requires decryption key. Bearer token auth.
cURL Example: Analyze
curl -X POST https://anonym.legal/api/presidio/analyze \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"text": "John Smith works at Acme Corp",
"language": "en"
}'
# Response
{
"results": [
{
"entity_type": "PERSON",
"start": 0,
"end": 10,
"score": 0.95
},
{
"entity_type": "ORGANIZATION",
"start": 20,
"end": 29,
"score": 0.88
}
]
}
Token-Based Pricing
Free Plan
200 tokens/month. Analysis cost follows a formula (e.g. analyzing 1,000 characters with 10 entity types enabled and 3 matches costs 3 tokens). Ideal for learning & testing.
Basic Plan
β¬3 / 1,000 tokens per month. Pro β¬15 / 4,000, Business β¬29 / 10,000 β see anonym.legal/pricing.
Use Case: AI Pipeline Integration
LLM Privacy Layer
import requests
from langchain.chat_models import ChatOpenAI
API = "https://anonym.legal/api/presidio"
HEADERS = {"Authorization": "Bearer YOUR_API_KEY"}
llm = ChatOpenAI(model="gpt-4")
# Customer input with PII
user_input = "My name is John, SSN 123-45-6789"
# 1. Detect PII
found = requests.post(f"{API}/analyze", headers=HEADERS,
json={"text": user_input, "language": "en"}).json()["results"]
# 2. Anonymize it before the text reaches the LLM
sanitized = requests.post(f"{API}/anonymize", headers=HEADERS,
json={"text": user_input, "language": "en",
"analyzer_results": found}).json()["text"]
response = llm.predict(text=sanitized)
Watch the API In Action
See PII detection and anonymization via REST API and MCP Server
Get Started with API
Sign up for free API key. 200 tokens included. Code examples in Python, Node.js, cURL. Synchronous API.
Get API KeyAlso from anonym.legal