# Anonymisation (/docs/entwickler/anonymisation)

> Replace names, IBANs and other personal data before a request reaches the model, get the original values back, and see what detection misses.

With `"anonymize": true`, PeakPrivacy looks for personal data in your messages and replaces it with invented values before the request reaches the model. In the answer, it puts the original values back.

Use it as an extra layer for text that goes to a model on the [Extern] level, in case personal data slipped past your own filtering. It doesn't replace choosing the right model: detection is automatic and incomplete, and some parts of a request aren't processed at all. Everything on this page was tested against the live API on 11.11.2026 with invented data.

> **Data protection:** in legal terms, this feature pseudonymises: the model receives invented substitutes, and PeakPrivacy keeps the link to the real values. Pseudonymised data is still personal data, and the same rules apply as to the original. Whether you may send it to an external model is decided by your organisation and its data protection officer, not by this field.

## What it does
- **Before the model:** in every message except `system` messages, detected values are replaced by invented values of the same kind. "Sandra Keller" becomes, for example, "William Henry", and an IBAN becomes another IBAN. The model sees no placeholders, so it writes natural text.
- **After the model:** PeakPrivacy replaces the substitutes in the answer with the original values, in `content` and in the arguments of `tool_calls`.
- **No streaming:** the request returns one JSON response, even with `"stream": true`.
- **Security level:** `security_levels.with_anon` in [`GET /v1/ai/models`](/docs/entwickler/models#tiers) shows the level of a model with anonymisation. For some models on the [Extern] level it is 4 instead of 5, but the badge stays [Extern]. For models where `with_anon` equals `without_anon`, the level doesn't change, although the anonymiser still runs.

## When to use it
1. **Choose the level first.** Personal and confidential data belongs on a [Schweiz] model. See [Which data belongs on which level](/docs/sicherheit/sicherheitsstufen#welche-daten) (German) and [Choosing a model](/docs/entwickler/choose-a-model).
2. **Remove what you can in your own code.** Your code knows which fields are personal. Leave them out, or send a customer number instead of a name. That is more reliable than any detection.
3. **Turn on `anonymize` as an extra layer** when a task needs an external model and your organisation allows it.

## Try it
The request asks `gpt-4.1`, an external model, for a payment reminder with an invented name, address and IBAN.

**curl**

```bash
curl -s https://api.peakprivacy.ch/v1/ai/chat/completions \
  -H "Authorization: Bearer $PEAKPRIVACY_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -d '{
    "model": "gpt-4.1",
    "anonymize": true,
    "messages": [{
      "role": "user",
      "content": "Write a two-sentence payment reminder for invoice RE-2026-0142 to Sandra Keller, Bahnhofstrasse 12, 8001 Zürich. Ask her to pay to IBAN CH93 0076 2011 6238 5295 7."
    }]
  }' | jq -r '.choices[0].message.content'
```

**Python**

```python
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.peakprivacy.ch/v1/ai",
    api_key=os.environ["PEAKPRIVACY_API_KEY"],
)

completion = client.chat.completions.create(
    model="gpt-4.1",
    messages=[{
        "role": "user",
        "content": "Write a two-sentence payment reminder for invoice RE-2026-0142 to Sandra Keller, "
                   "Bahnhofstrasse 12, 8001 Zürich. Ask her to pay to IBAN CH93 0076 2011 6238 5295 7.",
    }],
    extra_body={"anonymize": True},
)
print(completion.choices[0].message.content)
```

**JavaScript**

```js
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.peakprivacy.ch/v1/ai",
  apiKey: process.env.PEAKPRIVACY_API_KEY,
});

const completion = await client.chat.completions.create({
  model: "gpt-4.1",
  messages: [{
    role: "user",
    content: "Write a two-sentence payment reminder for invoice RE-2026-0142 to Sandra Keller, " +
      "Bahnhofstrasse 12, 8001 Zürich. Ask her to pay to IBAN CH93 0076 2011 6238 5295 7.",
  }],
  // @ts-expect-error PeakPrivacy field (only needed in TypeScript)
  anonymize: true,
});
console.log(completion.choices[0].message.content);
```

The answer contains the real values, because PeakPrivacy restored them:

```text
Dear Sandra Keller, this is a friendly reminder that invoice RE-2026-0142 remains unpaid. Kindly arrange payment to IBAN CH93 0076 2011 6238 5295 7 at your earliest convenience.
```

### See what the model received
Asking the model to repeat the name proves nothing: the substitute in its answer is restored too. Make it write the values in a form the restore step doesn't recognise, for example with a space between every character. Use this check only with test data.

**curl**

```bash
curl -s https://api.peakprivacy.ch/v1/ai/chat/completions \
  -H "Authorization: Bearer $PEAKPRIVACY_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -d '{
    "model": "gpt-4.1",
    "anonymize": true,
    "messages": [{
      "role": "user",
      "content": "Don'\''t write a reminder. List the name, the street and the IBAN from this text exactly as you received them, with a space between every character, one per line: Sandra Keller, Bahnhofstrasse 12, 8001 Zürich, IBAN CH93 0076 2011 6238 5295 7."
    }]
  }' | jq -r '.choices[0].message.content'
```

**Python**

```python
completion = client.chat.completions.create(
    model="gpt-4.1",
    messages=[{
        "role": "user",
        "content": "Don't write a reminder. List the name, the street and the IBAN from this text exactly "
                   "as you received them, with a space between every character, one per line: "
                   "Sandra Keller, Bahnhofstrasse 12, 8001 Zürich, IBAN CH93 0076 2011 6238 5295 7.",
    }],
    extra_body={"anonymize": True},
)
print(completion.choices[0].message.content)
```

**JavaScript**

```js
const check = await client.chat.completions.create({
  model: "gpt-4.1",
  messages: [{
    role: "user",
    content: "Don't write a reminder. List the name, the street and the IBAN from this text exactly " +
      "as you received them, with a space between every character, one per line: " +
      "Sandra Keller, Bahnhofstrasse 12, 8001 Zürich, IBAN CH93 0076 2011 6238 5295 7.",
  }],
  // @ts-expect-error PeakPrivacy field (only needed in TypeScript)
  anonymize: true,
});
console.log(check.choices[0].message.content);
```

```text
J o h n   N e l s o n
B a h n h o f s t r a s s e   1 2
G B 6 1 N O A S 8 9 3 5 9 6 3 9 9 1 6 1 0 9
```

The model never saw the name or the IBAN, but it did see the street. Your substitutes will differ. Without `anonymize`, the same request returns the real values.

## What gets replaced
Results of our tests with invented data. Detection depends on the wording around a value, so run [the check](/docs/entwickler/anonymisation#check) with invented data shaped like yours.

| Data | Replaced |
|---|---|
| Person names | Yes |
| IBANs, credit card numbers, IP addresses | Yes |
| E-mail addresses | Yes. An address on an unusual domain such as `alpenblick.example` was only partly replaced. |
| Phone numbers | Sometimes: replaced in a labelled list, kept in running text |
| Street, house number, postcode, town | No |
| Company names | No |
| Dates, including dates of birth | No |
| AHV numbers | No |

Context can identify a person without any of these: "the new head of the municipal administration in Seewil" names nobody and is still unique.

## Limits
- System messages are sent unchanged. Keep personal data out of the system prompt.
- The Responses endpoint doesn't anonymise. `/v1/ai/responses` accepts the field, but sends `input` and `instructions` unchanged. Use chat completions.
- Only text is processed. Images in a message are sent unchanged.
- Only exact substitutes are restored. If the model shortens, inflects or reformats a substitute, it stays in the answer. Asked for a greeting with only the first name, `gpt-4.1` wrote "Hello, Stephanie!" to Sandra Keller. Check answers before they reach customers.
- Answers take longer. Some anonymised requests took several times as long as the same request without `anonymize`. The [120-second limit](/docs/entwickler/errors#timeouts) applies, and you can't stream.

> **Known limitation:** with `"stream": true`, an anonymised request returns one JSON response instead of a stream. The OpenAI SDKs then yield no chunks and raise no error, so your code receives an empty answer. **Workaround:** send anonymised requests without `stream`.

## See also
- [Chat completions › Anonymisation](/docs/entwickler/chat-completions#anonymize)
- [Choosing a model](/docs/entwickler/choose-a-model)
- [Security levels](/docs/sicherheit/sicherheitsstufen) (German)
- [Anonymisierung](/docs/sicherheit/anonymisierung) (German, for data protection officers)
