# For developers

> Install maskera for local Swedish PII masking in the browser or Node. Open source, TypeScript and a custom-trained Swedish AI model.
>
> Canonical: https://maskera.dev/en/developers (en) · sv: https://maskera.dev/utvecklare · Markdown: https://maskera.dev/en/developers.md · Overview for agents: https://maskera.dev/llms.txt

Install maskera, create a recogniser once and mask text locally in the browser or Node. [The Swedish AI model](https://huggingface.co/joelhagvall/maskera-sv-ner) is downloaded on first use and then reused from the local cache.

## Install

```
npm install maskera @huggingface/transformers
```

Rules and AI model are included; import the entire API from maskera.

Good to know

- The first run downloads the AI model of about 43 MB. It is then reused from the local cache.
- Create the recogniser once and reuse it between calls; avoid creating a new one for every text.
- maskera supports browsers and Node 18+. In the browser, the model runs with WASM or WebGPU.

[Complete usage and configuration guide on GitHub](https://github.com/joelhagvall/maskera/blob/main/packages/ner/README.md)

## Mask text

```
import { createNerRecognizer, redactWithNer, type NerRecognizer } from "maskera"// maskera's Swedish model, about 43 MB, runs locallyconst recognizer: NerRecognizer = createNerRecognizer()const { text, restore } = await redactWithNer(  "hej jag heter anna karlsson, personnummer 19900101-2385, och bor i uppsala",  { recognizer },)text// "hej jag heter [NAMN_1], personnummer [PERSONNUMMER_1], och bor i [PLATS_1]"
```

![Diagram of maskera's two layers: your text is split between rules for fixed-format data and a Swedish AI model for free text, then merged into masked text.](https://maskera.dev/layers.svg)

Rules handle fixed-format data. The AI model handles free text such as names and addresses. Rules win when detections overlap. The model categories and default rule-engine detectors are listed category by category. [See exactly what is masked.](https://maskera.dev/en/privacy#vad-maskeras)[Open full-size diagram](https://maskera.dev/layers.svg)

## Send to the AI service and restore the response

```
// send the masked text to any AI service// detected personal data has been replaced with placeholdersconst answer: string = await fetch("https://api.example.com/chat", {  method: "POST",  body: JSON.stringify({ prompt: text }),}).then((r) => r.text())restore(answer)// placeholders are replaced with the originals, locally
```

## Optional profile for clinical text

The default mode suits mixed text. For medical records and clinical workflows, a named profile protects clinical facts while rule-based personal data is still always masked. [Read more about the clinical profile on GitHub](https://github.com/joelhagvall/maskera/blob/main/packages/ner/README.md#clinical-profile)

JS / TS

```
const { text, restore } = await redactWithNer(journalText, {  recognizer,  profile: "clinical",})
```

- [maskera on npm](https://www.npmjs.com/package/maskera)
- [Documentation and source code on GitHub](https://github.com/joelhagvall/maskera)
- [Model on Hugging Face](https://huggingface.co/joelhagvall/maskera-sv-ner)

[Open source](https://github.com/joelhagvall/maskera) · [Custom-trained Swedish AI model](https://huggingface.co/joelhagvall/maskera-sv-ner)

- [Accuracy](https://maskera.dev/en/accuracy)
- [Security](https://maskera.dev/en/security)
- [Privacy & transparency](https://maskera.dev/en/privacy)
- [Privacy policy](https://maskera.dev/en/privacy-policy)
- [Test data](https://maskera.dev/en/test-data)
- [About & contact](https://maskera.dev/en/about)
- [White paper (PDF)](https://maskera.dev/whitepaper.pdf)

A product of [Hägvall Labs AB](https://hagvall-labs.com).
