# SDK and operations

> Mask Swedish personal data in browsers and Node.js with maskera and @maskera/core: clinical profile, custom rules, ONNX self-hosting, and production checklist.
>
> Canonical: https://maskera.dev/en/docs/sdk (en) · sv: https://maskera.dev/docs/sdk · Markdown: https://maskera.dev/en/docs/sdk.md · Overview for agents: https://maskera.dev/llms.txt

Use maskera (rules + 68 MB Swedish AI model) or @maskera/core (rules only, zero dependencies) directly in your own TypeScript or JavaScript code.

[Overview](https://maskera.dev/en/docs) · [@maskera/mcp](https://maskera.dev/en/docs/mcp) · [Client guides](https://maskera.dev/en/docs/clients) · [SDK & operations](https://maskera.dev/en/docs/sdk) · [Troubleshooting](https://maskera.dev/en/docs/troubleshooting)

You know it worked when

The example below sends text without names or personnummer to the model, and restore(answer) brings back the exact original.

## Pick a package

Both packages share the same synchronous rule engine and restore map. maskera re-exports everything from @maskera/core. Both run in the browser (WASM or WebGPU) and in Node 18+.

| Package | Includes | Best when |
| --- | --- | --- |
| maskera + @huggingface/transformers | Deterministic Swedish rules + the maskera-sv-ner ONNX model (68 MB in q4, 100 MB in q8). | Free-form Swedish text with names, street addresses, places, and organisations. |
| @maskera/core | Format and check-digit rules only, zero dependencies, synchronous. | Structured logs, constrained runtimes, or when you want no model weights. |

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

JS / TS

```
import { createNerRecognizer, redactWithNer } from "maskera"

const recognizer = 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]"

const answer = await askAI(text)
restore(answer)
```

## Core flow, clinical profile, and custom detectors

Create one recognizer at startup and reuse it across calls. For Swedish healthcare text, profile: "clinical" retains doses, measurements, and care terms while masking personal data. Add custom patterns with regexDetector.

TypeScript

```
import {
  createNerRecognizer,
  hybridDefaultDetectors,
  redactWithNer,
  regexDetector,
} from "maskera"

const recognizer = createNerRecognizer()

// Custom patterns are added to the built-in rules, not used instead of them
const caseIdDetector = regexDetector("ARENDE", /(?<!\p{L})ÄRENDE-\d{4}-\d{4}(?!\p{L})/gu)

const { text, restore } = await redactWithNer(
  "Patient Anna Lindqvist (19900101-2385) i ÄRENDE-2026-0412 fick Alvedon 500 mg.",
  {
    recognizer,
    profile: "clinical",
    detectors: [...hybridDefaultDetectors, caseIdDetector],
  },
)
// text: "Patient [NAMN_1] ([PERSONNUMMER_1]) i [ARENDE_1] fick Alvedon 500 mg."

const answer = await callYourModel(text)
const finalReply = restore(answer)
```

## Self-hosting the model and offline operation

By default, the model weights are fetched once from Hugging Face, checked with sha256 against a pinned commit, and cached locally. On air-gapped networks, download the model once and point to the folder.

TypeScript

```
// Download the model once, pinned to the published revision:
// hf download joelhagvall/maskera-sv-ner onnx/model_quantized.onnx config.json \
//   tokenizer.json tokenizer_config.json special_tokens_map.json \
//   --revision e0d5d017383c2732c5cc3c962fd1afdd73bb8035 \
//   --local-dir /opt/models/maskera-sv-ner-v24

// q8 is fastest on Node CPU; use q4 in browsers
const recognizer = createNerRecognizer({
  localModelPath: "/opt/models",
  model: "maskera-sv-ner-v24",
  allowRemoteModels: false,
  dtype: "q8",
})
```

## Production checklist

Maskera is defense in depth, not a zero-leak compliance guarantee.

- Reuse one createNerRecognizer() instance per process so the model is not reloaded per request.
- Never store the restore map in the same log, database, or trace as the redacted text.
- Fail closed on model errors: never fall through and forward unredacted text if NER throws.
- Run a synthetic smoke test on deploy with made-up Swedish data before sending real traffic.

## Read next

- [Overview →Pick a mode and check that masking works.](https://maskera.dev/en/docs)
- [@maskera/mcp →Proxy, MCP server and hook for AI agents.](https://maskera.dev/en/docs/mcp)
- [Client guides →Ready-made steps for Claude, Codex, Cursor and more.](https://maskera.dev/en/docs/clients)
- [Troubleshooting →Common issues and what local masking does not cover.](https://maskera.dev/en/docs/troubleshooting)

- [Agent setup prompt (setup-prompt.md)](https://maskera.dev/setup-prompt.md)
- [Machine-readable index (llms.txt)](https://maskera.dev/llms.txt)
- [@maskera/mcp on npm](https://www.npmjs.com/package/@maskera/mcp)
- [maskera on npm](https://www.npmjs.com/package/maskera)
- [Source code on GitHub](https://github.com/joelhagvall/maskera)
- [Model on Hugging Face](https://huggingface.co/joelhagvall/maskera-sv-ner)

Product

- [Products](https://maskera.dev/en/services)
- [Documentation](https://maskera.dev/en/docs)
- [Industries](https://maskera.dev/en/industries)
- [Accuracy](https://maskera.dev/en/accuracy)
- [Customer portal](https://app.maskera.dev/en/login?utm_source=maskera_dev&utm_medium=referral&utm_content=footer_portal)

Trust

- [Security](https://maskera.dev/en/security)
- [Privacy & transparency](https://maskera.dev/en/privacy)
- [FAQ](https://maskera.dev/en/faq)
- [Privacy policy](https://maskera.dev/en/privacy-policy)
- [Test data](https://maskera.dev/en/test-data)

Project

- [Open source](https://github.com/joelhagvall/maskera)
- [Custom-trained Swedish AI model](https://huggingface.co/joelhagvall/maskera-sv-ner)
- [White paper (PDF)](https://maskera.dev/whitepaper.pdf)
- [About & contact](https://maskera.dev/en/about)

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