
Deploy PII Redaction | (Just Updated) Presidio Detect and Anonymize API, API Key Pre-Set
Presidio PII detection and redaction API: names, emails, phones, IPs
Just deployed
Deploy and Host PII Detection and Redaction API (Microsoft Presidio) on Railway
PII redaction finds personal data in text, such as names, email addresses, phone numbers, IP addresses, URLs, bank and card numbers, and rewrites it before the text is stored, logged or sent to a language model. This template serves Microsoft Presidio and the spaCy en_core_web_lg model behind one authenticated JSON API on CPU. The model is already inside the image, an API key is generated for you at deploy, and no GPU is needed.
About Hosting PII Detection and Redaction
This template runs presidio-analyzer and presidio-anonymizer 2.2.366 with spaCy 3.8.18 behind a small FastAPI server. Presidio's own example images are two separate Flask services with no authentication; here analysis and redaction are one service. POST /v1/redact takes {"text": "..."} (or {"texts": [...]} for a batch) and returns the redacted text, every finding with its character offsets and score, and the list of replacements. POST /v1/analyze returns the findings only. Per-entity operators choose what happens to each kind of data: replace (default: the entity name in angle brackets, such as PERSON, or your own new_value), redact, mask or hash. entities, score_threshold and allow_list narrow what is reported, and GET /v1/entities lists the 24 entity types this build detects.
The spaCy model is baked into the image, so nothing downloads at boot and the first request is answered from memory. The service sizes its thread pools from the container's own CPU quota instead of the host's core count, handles one request at a time so memory stays bounded, and refuses a text over 200,000 characters or a batch over 100 texts. The text you send is held for the length of one request and is never logged or written to disk.
Measured on Railway, 8 vCPU: a 150-character text is redacted in about 0.14 s, a 10,000-character document in 0.47 s (21,000 characters per second), a 100,000-character document in 9.4 s and the 200,000-character maximum in 28.4 s. A batch of 100 short texts takes 1.2 s (86 texts per second), and 30 sequential short requests averaged 117 ms each including the network. The model loads in 2.8 s after the container starts. Resident memory was 0.8 GB at boot and peaked at 1.5 GB after the 200,000-character request. Speed falls off on very long texts that contain thousands of findings, so split large documents into pieces of 10,000 to 50,000 characters.
Accuracy is Presidio's, not ours: pattern recognizers (email, IP, phone, IBAN, card, US SSN) are precise, while names and places come from a statistical English model and are not complete, so treat this as a strong first pass and not as a guarantee that nothing personal is left. English only.
Agent contract
- Public URL:
https://RAILWAY_PUBLIC_DOMAIN(the generated domain of thepiiservice) - Private URL:
http://pii.railway.internal:8080 - Credentials: the
API_KEYvariable of thepiiservice - Auth: send
Authorization: Bearer $API_KEYon every route exceptGET /health; a call without the key or with a wrong one answers401 - Health:
GET /healthreturns 200 once the model is loaded (503 while it loads)
# needs: RAILWAY_PUBLIC_DOMAIN, API_KEY (a variable of the pii service); also curl and grep.
# signup: none - the API has no user accounts, only the API_KEY bearer
R="https://$RAILWAY_PUBLIC_DOMAIN"
n=0; until [ "$(curl -s -o /dev/null -w '%{http_code}' "$R/health")" = 200 ]; do n=$((n+1)); [ "$n" -le 60 ] || break; sleep 5; done
curl -s -o /dev/null -w "health: %{http_code}\n" "$R/health"
B='{"text":"Please email Maria Garcia at maria.garcia@example.com or call +44 20 7946 0958."}'
curl -s -o /dev/null -w "write without key: %{http_code}\n" -X POST "$R/v1/redact" -H "Content-Type: application/json" -d "$B"
curl -s -o /dev/null -w "write wrong key: %{http_code}\n" -X POST "$R/v1/redact" -H "Authorization: Bearer not-the-key" -H "Content-Type: application/json" -d "$B"
curl -s -X POST "$R/v1/redact" -H "Authorization: Bearer $API_KEY" -H "Content-Type: application/json" -d "$B" \
| grep -o '"text":"Please[^"]*"'
A fresh deploy prints health: 200, write without key: 401, write wrong key: 401 and the redacted sentence, with the entity names PERSON, EMAIL_ADDRESS and PHONE_NUMBER in angle brackets where the name, address and number were. To keep the last four digits visible, mask instead of replacing:
curl -X POST "https://$RAILWAY_PUBLIC_DOMAIN/v1/redact" -H "Authorization: Bearer $API_KEY" -H "Content-Type: application/json" \
-d '{"text":"Call +44 20 7946 0958","operators":{"PHONE_NUMBER":{"type":"mask","masking_char":"*","chars_to_mask":12,"from_end":false}}}'
An unknown entity name, an unsupported operator or a non-JSON body answers 422 with the reason, and a text or batch over the limit answers 413. The API never fetches a URL for you: it only reads the text you send, so it cannot be pointed at an address inside your network.
Why Deploy PII Detection and Redaction API on Railway?
Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.
By deploying PII Detection and Redaction API on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.
- Personal data stays in your container — text is redacted by your own service, not sent to a hosted PII or DLP API.
- One authenticated service — analysis and redaction behind one bearer key, where the upstream examples are two open Flask apps.
- No GPU bill and no per-request fee — about 20,000 characters per second on 8 vCPU, and you pay for the container.
- Open source, commercial use — Presidio and the spaCy model are MIT licensed.
- Private by default — a generated bearer key guards every route but the health check, and the container refuses to start without one.
Common Use Cases
- Scrub prompts before an LLM call — redact names, emails and phone numbers from user text before it reaches a model provider.
- Clean logs, tickets and transcripts — strip personal data from support threads, call transcripts and application logs before storage or analytics.
- PII step for AI agents — give an LLM agent one authenticated request that says what personal data a text contains and where.
Dependencies for PII Detection and Redaction Hosting
- A service with at least 2 GB of RAM (resident memory measured at 0.8 GB idle and 1.5 GB after a 200,000-character request).
- No volume: the service keeps no state and the model is in the image.
Deployment Dependencies
- microsoft/presidio — the detection and anonymization engine, MIT, version 2.2.366
- explosion/spaCy — NLP library, MIT, version 3.8.18, with the
en_core_web_lg3.8.0 pipeline (MIT per its release metadata) - bon5co/presidio-railway — the Railway wrapper image this template deploys, Apache-2.0
- Licences: the Presidio repository is licensed "The MIT License (MIT)", which grants "permission ... free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction". The
en_core_web_lg-3.8.0release listsLicense | MIT. The pipeline's listed training sources are OntoNotes 5 (commercial, licensed by Explosion), WordNet 3.0 and CC0 vectors. The MIT notice travels with the image at/app/LICENSE.presidio.
Template Content

