POST/v1/inbound/tokenize

Inbound Tokenization

Scrub and tokenize Protected Health Information from clinical text before it reaches any cloud LLM.

<10ms latency


Description

This endpoint uses a two-stage pipeline to detect and replace PHI entities:

  1. Local Regex Patterns — High-speed pattern matching for SSNs, MRNs, phone numbers, and dates of birth.
  2. spaCy NER Model — A fine-tuned Named Entity Recognition model trained on clinical corpora to identify patient names, physician names, and locations.

Detected entities are replaced with deterministic tokens (e.g., "Patient Forgive" → [ID_001]). Tokens are reversible only by the originating EnorAI instance.

Important

Tokenization runs locally. No raw PHI is transmitted to EnorAI cloud services.


Request body

Parameters

NameTypeRequiredDescription
input_textstringRequiredThe raw clinical text containing PHI to be scrubbed and tokenized.
fhir_contextstringOptionalOptional EHR system reference for FHIR R4 compliance audit linking.

Response

Response fields

NameTypeRequiredDescription
tokenized_textstringRequiredInput text with PHI replaced by deterministic tokens.
entities_foundintegerRequiredNumber of PHI entities detected and tokenized.
processing_time_msnumberRequiredProcessing time in milliseconds.
token_map_idstringRequiredUUID reference to stored token map for de-tokenization.
curl -X POST \
  https://api.enorai.com/v1/inbound/tokenize \
  -H "Authorization: Bearer $ENORAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "input_text": "Patient Forgive presents with a fever of 39.2°C.",
    "fhir_context": "Patient/p-28491"
  }'
from enorai import EnorAI
 
client = EnorAI(api_key="ENORAI_API_KEY")
 
result = client.inbound.tokenize(
  input_text="Patient Forgive presents with a fever.",
  fhir_context="Patient/p-28491"
)
print(result.tokenized_text)
{
  "status": "success",
  "scrubbed_text": "Patient [ID_001] presents with a fever of 39.2°C.",
  "entities_found": 1,
  "processing_time_ms": 6.2,
  "token_map_id": "tmap_a1b2c3d4-e5f6-7890"
}