Skip to main content
The streaming API processes text incrementally, making it ideal for real-time LLM output, file processing, and other scenarios where text arrives in chunks.
Streaming is only available in Node.js and Bun. It is not included in the browser build.

Basic Usage

How It Works

The streaming anonymizer uses a sentence buffer that accumulates text until a sentence boundary is detected, then anonymizes complete sentences. This ensures NER has enough context for accurate detection.
An overlap region preserves context between flushes so that entities spanning buffer boundaries are detected correctly.

Stream Configuration

Low-Latency Mode

For real-time LLM token streams where latency matters more than NER accuracy:
Low-latency mode:
  • Disables NER (regex-only detection)
  • Reduces buffer sizes for faster flushing
  • Optimized for token-by-token LLM output

Events

onChunk

Fires after each buffered chunk is anonymized:

onFinish

Fires when the stream ends:

Accessing the PII Map

After the stream ends, retrieve the cumulative PII map:

Session Integration

Persist PII maps across streaming sessions:
If a session already has a stored PII map, the stream loads it and continues with consistent entity IDs.

Next Steps

LLM Proxy

Automatic anonymization for LLM API calls

Streaming API Reference

Complete streaming API documentation