CODE EXAMPLES β€” DEVELOPERS

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);

No. There is no SDK package. The REST API works with any HTTP client: call it with requests in Python or fetch in Node.js. Code examples are on the Code Examples page.

The MCP Server exposes 9 privacy tools, for example anonym_legal_analyze_text, anonym_legal_anonymize_text and anonym_legal_detokenize_text, that MCP-capable agents can call directly. MCP access is included in Pro and Business. Prevents PII leakage in RAG pipelines and agent workflows.

The API is synchronous. Batch endpoints process arrays of text in a single call. The API runs on EU servers. Document content is not stored after processing, unless you use the optional history.

The API runs on our EU-hosted infrastructure. Document content is not stored after processing, unless you use the optional history. For enterprise self-hosting requirements, contact us.

Yes. Send arrays of text strings in a single API call. The batch endpoint (POST /api/presidio/batch) takes up to 5 texts per request on Basic, 10 on Pro and 50 on Business.

Free tier: 200 tokens per 30 days in the web app (API access starts with Basic). Basic: €3/month (1,000 tokens). Pro: €15/month (4,000 tokens, adds the MCP Server). Business: €29/month (10,000 tokens). What a call costs depends on text length and the entities found, so one call can cost more than one token.

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 Key

Frequently Asked Questions

Nothing needs to be installed except an HTTP client. With requests: requests.post('https://anonym.legal/api/presidio/analyze', headers={'Authorization': 'Bearer YOUR_API_KEY'}, json={'text': 'John Smith, SSN 123-45-6789', 'language': 'en'}). Pass the results to POST /api/presidio/anonymize to get anonymized output.

No. There is no SDK package for any language. The REST API works with any HTTP client β€” Python (requests), Node.js (fetch), Go (net/http), Java (OkHttp/HttpClient), Ruby (Net::HTTP), PHP (Guzzle), C# (HttpClient), Rust (reqwest).

Bearer token authentication. Generate your API token at anonym.legal/app/settings (Developer tab). Pass it as Authorization: Bearer YOUR_TOKEN header on every request.