Skip to main content
Sessions provide a simplified API for anonymizing and rehydrating text across multiple turns, with automatic PII map persistence.

Creating a Session

Both keyProvider and piiStorageProvider are required for sessions. Without them, session() will throw an error.

AnonymizerSession Interface


session.anonymize()

Anonymizes text and automatically saves the PII map.

Multi-Message Consistency

Entity IDs are consistent across multiple calls:

session.rehydrate()

Loads the PII map from storage and restores original values.

Cross-Request Rehydration


session.load()

Manually load the stored PII map.

session.exists()

Check if a session has stored data.

session.delete()

Remove a session from storage.

session.anonymizeJson()

Recursively walks a JSON-serializable value and anonymizes every string leaf. Non-string values (numbers, booleans, nulls) pass through unchanged. The PII map is saved to storage after processing.
Strings are processed sequentially (not in parallel) to ensure deterministic PII ID assignment.

session.rehydrateJson()

Recursively walks a JSON-serializable value and rehydrates every string leaf that contains PII placeholders.

Complete Example


Multiple Conversations


Session vs Direct Anonymize