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 Zimbabwe national IDs, MRNs, phone numbers, addresses, dates of birth, email addresses and card numbers.
  2. spaCy NER Model: spaCy's general English Named Entity Recognition model (en_core_web_lg), run through Microsoft Presidio, to identify patient and physician names.

Detected entities are replaced with deterministic tokens (e.g., "Tendai Moyo" becomes <PERSON_1>). 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 reference (e.g. a FHIR R4 Patient ID). Accepted for future audit linking; not used yet.

Response

Response fields

NameTypeRequiredDescription
statusstringRequired"success" when the text was scrubbed.
scrubbed_textstringRequiredInput text with PHI replaced by reversible tokens such as <PERSON_1>.
entities_foundintegerRequiredNumber of PHI entities detected and tokenized.
processing_time_msnumberRequiredProcessing time in milliseconds.
token_map_idstringRequiredID of the stored token map (kept 24 hours) used by /v1/inbound/detokenize.
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 Tendai Moyo, ID 63-123456A73, phone 0772 123 456, presents with a persistent 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 Tendai Moyo, ID 63-123456A73, presents with a fever.",
  fhir_context="Patient/p-28491"
)
print(result.scrubbed_text)
{
  "status": "success",
  "scrubbed_text": "Patient <PERSON_1>, ID <NATIONAL_ID_1>, phone <PHONE_1>, presents with a persistent fever of 39.2°C.",
  "entities_found": 3,
  "processing_time_ms": 6.2,
  "token_map_id": "tmap_a1b2c3d4-e5f6-7890"
}