Opami ProtectOpen the console

API reference

Base URL: https://api-protect.opami.ai. Send every call with Authorization: Bearer opk_....

POST /v1/detect

Finds private and sensitive data in plain text and returns it in the same response. This is the only route an API key can call. Keys are managed in the console. Request limits are on the Rate limits page.

Request

One UTF-8 JSON object with two required fields and four optional fields.

FieldTypeNotes
modelstringRequired on every call. There is no default.
textstringPlain text to check. It is not trimmed.
excludearray of stringsOptional. Categories, category.sub or full types to leave out of the answer. See Detection types.
outputstringOptional. "detections" (default), "placeholders" or "replace". See Placeholders and Fake data. Any other value returns 400 invalid_request, no charge. "replace" is billed at 2×.
seedstringOptional, only with "output": "replace". 1 to 128 UTF-8 bytes. See Fake data.
localestringOptional, only with "output": "replace". "auto" (default) or the language of the fakes. See Fake data.

Optional header Idempotency-Key: 1 to 255 visible ASCII characters. The key is remembered for 24 hours and is shared across your keys and the console. A reuse within 24 hours returns 409 idempotency_key_reused and no charge when the first call was charged or is still running. A call that ended with nothing charged (model_busy, model_unavailable) frees its key, so the same key can be retried. The API does not replay a result. Without the header there is no retry protection, so a retried call is a new call. See Rate limits: how to retry.

The 24 hours count per account and operation. They are shared across all your API keys and are not reset at UTC midnight or month end. A reuse in that window of a key whose call was charged or is still running gets the 409, even if the text or model changed. A lost result cannot be recovered. To get a new result, send the call with a new key. That call can be charged. After 24 hours, a resend with the same key may be treated as a new call and billed.

Response

The example is an illustration of the offset rules. A real model may return different spans and types.

{
  "request_id": "6f1c0a52-3c1e-4a53-9d1d-0a8f2e5b7c11",
  "model": "protect-v1",
  "detections": [
    { "text": "Zoë Müller", "type": "person.name.full", "start": 0, "end": 10, "entity_id": "person.name#1" },
    { "text": "zoe@example.com", "type": "contact.email", "start": 22, "end": 37, "entity_id": "contact.email#1" }
  ],
  "usage": { "characters": 37, "cost_eur": "0.00007400", "cost_usd": "0.00007400" }
}

Each detection has text, type, start, end and entity_id.

Same entity, same id

When the same person, company or value is mentioned more than once, those detections share one entity_id. Here the first name alone is linked to the full name:

{ "text": "José Silva", "type": "person.name.full", "start": 0, "end": 10, "entity_id": "person.name#1" },
{ "text": "José", "type": "person.name.first", "start": 21, "end": 25, "entity_id": "person.name#1" }

What is linked: name variants of one person (full name and first name alone), titles ("Dr. Silva"), initials, acronyms of a company name, and the same value repeated. What is not linked: pronouns, descriptions such as "the company", and an email address to its owner. These are rules applied after the model, not a guarantee: expect misses and an occasional wrong link.

Excluding types

exclude takes categories, category.sub or full types, matching whole segments. Excluded detections are not returned, and the text is still charged in full. Send at most 50 entries. Add unknown to drop spans the model detects without a type, so only named data types come back. An entry that matches no type returns 400 unknown_category. Only the number of entries is logged.

curl https://api-protect.opami.ai/v1/detect \
  -H "Authorization: Bearer $OPAMI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"protect-v1","text":"Write to Zoë Müller at zoe@example.com.","exclude":["health","banking"]}'
curl https://api-protect.opami.ai/v1/detect \
  -H "Authorization: Bearer $OPAMI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"protect-v1","text":"Write to Zoë Müller at zoe@example.com.","exclude":["unknown"]}'

The full list of types is on the Detection types page.

Placeholders

With "output": "placeholders" the response has the usual fields, detections included, plus:

The same entity gets the same placeholder everywhere in the text, and the number counts per label. Labels come in the language the model detects: English, Portuguese, French or Spanish. Any other language gets English labels. There is no option to choose the labels yet. Billing is the same as without output.

exclude still applies, before numbering. An excluded type stays unchanged in placeholder_text and gets no entry. Numbers count only the entities that remain, so there are no gaps: with person.name excluded, the first email address is still [EMAIL_1], so a placeholder can have a different number than in a call without exclude. With unknown excluded, untyped pieces stay as written.

curl https://api-protect.opami.ai/v1/detect \
  -H "Authorization: Bearer $OPAMI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"protect-v1","text":"Write to Zoë Müller at zoe@example.com.","output":"placeholders"}'

Putting the original values back

The API stores nothing, so it cannot restore the text for you. Keep the response, then replace each placeholder with its text in your own code:

restored = data["placeholder_text"]
for p in data["placeholders"]:
    restored = restored.replace(p["placeholder"], p["text"])

Warning: placeholders are pseudonymisation, not a guarantee of anonymity. Anything the model misses stays in the text, and the rest of the text can still identify a person.

Fake data

Replace mode is live in 7 languages: English, Portuguese, French, Spanish, German, Italian and Dutch. With "output": "replace" every detection is replaced by realistic fake data of the same type: a fake name for a name, a fake email address for an email address, and so on. The response has the usual fields, detections included and unchanged, plus:

Two more optional fields work only with "output": "replace". Sending either one with another output returns 400 invalid_request, no charge.

exclude still applies. An excluded type stays unchanged in replaced_text and gets no entry in replacements, and an excluded value is never chosen as a fake. With unknown excluded, untyped pieces stay as written. If a kept detection has the same value as an excluded one elsewhere in the text, that other occurrence is replaced too."output": "replace" is billed at 2× the rate of its pricing band: usage.cost_eur is twice the value for the same text with "detections" or "placeholders" (37 characters in a new month = "0.00014800" instead of "0.00007400"). The characters count once toward your monthly bands. See Pricing and credits. The API does not log or store seed, replaced_text or replacements.

curl https://api-protect.opami.ai/v1/detect \
  -H "Authorization: Bearer $OPAMI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"protect-v1","text":"Write to Zoë Müller at zoe@example.com.","output":"replace","seed":"order-4711","locale":"auto"}'
"usage": { "characters": 37, "cost_eur": "0.00014800", "cost_usd": "0.00014800" }

How the fakes are chosen

Warning: replace is pseudonymisation, not a guarantee of anonymity. Anything the model misses stays in the text unchanged, among fakes that make it harder to spot, and the rest of the text can still identify a person.

Offsets

start and end count Unicode code points in the text you sent. They are zero-based and end-exclusive, so text[start:end] in Python gives the detection. In the example above the text is Zoë Müller 😀 wrote to zoe@example.com. The name covers positions 0 to 10, and the emoji counts as one position (it takes two in JavaScript strings, so convert with Array.from(text) before slicing).

Counting characters

Spaces count. There is no normalization and no per-request minimum.

Examples of refused requests

Each is refused before the model runs, with no charge.

{"text":"Hello"}
-> 400 invalid_request
{"model":"protect-unknown","text":"Hello"}
-> 400 unknown_model
{"model":"protect-v1","text":""}
-> 400 invalid_text
{"model":"protect-v1","text":"\u3000 \n"}
-> 400 invalid_text

Whitespace-only text includes non-ASCII whitespace such as U+3000. Text that has other characters is never trimmed.

Limits

Model versions

You choose the model on every call. protect-v1 is the current model and supports 52 languages. During the beta we improve it in place; your requests keep working. From launch, a new version gets a new name, and the old one stays available.

Errors

Every error has the same shape:

{ "error": { "code": "invalid_request", "message": "..." }, "request_id": "..." }
StatusCodeMeaning
400invalid_requestThe body is not a valid request: not JSON, wrong Content-Type, unknown fields, model or text missing, or an invalid Idempotency-Key.
400invalid_textThe text is empty or whitespace only. Refused before the model runs, no charge.
400unknown_categoryAn entry in exclude matches no category, sub-category or type. See Detection types. No charge.
400unknown_modelThe model name does not exist.
400amount_out_of_rangeConsole checkout only, not /v1/detect: the top-up amount is outside the allowed range.
401unauthorizedThe key is missing, invalid or revoked. All three look the same.
401key_expiredThe key has expired. Create a new key on the API keys page and use it instead.
402insufficient_creditYour credit cannot cover this call. Add credit and retry.
403account_not_activeThe account is waiting for activation. Questions: hello@opami.ai.
403account_blockedThe account is blocked. Contact hello@opami.ai.
404resource_not_foundThe resource does not exist, or belongs to another account.
409idempotency_key_reusedThe Idempotency-Key was used in the last 24 hours by a call that was charged or is still running, even with the same text. No charge for this call. A call that ended with nothing charged (model_busy, model_unavailable) frees its key, and a call refused with 402 does not use up the key.
408request_timeoutThe body took more than 30 seconds to arrive, or the request took more than 60 seconds. Retry with a new Idempotency-Key. See Rate limits.
409key_limit_reachedConsole key creation only: the account already has 25 active keys. Revoke one first.
413text_too_longMore than 20,000 code points of text, or a /v1/detect body over 1 MB. The message says which limit.
413request_too_largeA body over 64 KB on any other customer route.
429rate_limitedToo many requests, or 4 detections already running for the account. Wait Retry-After seconds and retry. See Rate limits.
429model_busyThe model is at capacity. Wait Retry-After seconds and retry with the same Idempotency-Key. See Rate limits.
503access_check_unavailableThe access check could not run. Nothing was processed. Retry shortly.
503model_unavailableThe model could not answer. Nothing is charged and the key is freed. Retry shortly with the same Idempotency-Key.
503service_unavailableStorage or billing settlement failed. Nothing is charged. Retry shortly.

A failed or refused call is never charged.