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.
| Field | Type | Notes |
|---|---|---|
model | string | Required on every call. There is no default. |
text | string | Plain text to check. It is not trimmed. |
exclude | array of strings | Optional. Categories, category.sub or full types to leave out of the answer. See Detection types. |
output | string | Optional. "detections" (default), "placeholders" or "replace". See Placeholders and Fake data. Any other value returns 400 invalid_request, no charge. "replace" is billed at 2×. |
seed | string | Optional, only with "output": "replace". 1 to 128 UTF-8 bytes. See Fake data. |
locale | string | Optional, 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" }
}model: the model version that ran.detections: the private and sensitive data found. An empty list means nothing was found.usage:characterscounted andcost_eurcharged for this call in euros, a decimal string with 8 places.cost_usdis a legacy alias with the same euro value, kept for compatibility (readcost_eur). Spans without a known type come back as typeunknown.
Each detection has text, type, start, end and entity_id.
entity_id: an opaque string. Two detections in the same response with the sameentity_idare the same entity. Ids mean nothing across requests, so do not store or compare them between calls, and do not parse them.excludedoes not change them. See Same entity, same 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:
placeholder_text: your text with every detection replaced by a placeholder such as[PERSON_1].placeholders: a list ofplaceholder,entity_id,typeandtext, one entry per placeholder, in order of first appearance.textis the original text of the first mention.
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:
replaced_text: your text with the replacements applied.replacements: a list ofstart,end,typeandvalue, in text order.startandendare the code-point range of your text that was replaced,typeis its type ("unknown"for an untyped piece) andvalueis the fake written there. The list can be longer thandetections: other whole occurrences of a detected value in the text are replaced too.
Two more optional fields work only with "output": "replace". Sending either one with another output returns 400 invalid_request, no charge.
seed: a string of 1 to 128 UTF-8 bytes. The same seed, text and detections give the same fakes. Without a seed, every call gives new fakes.locale:"auto"(default) uses the language detected in the text. Or choose the language of the fakes:en,pt,fr,es,de,itornl(a region such aspt-BRis accepted). Withauto, text in any other language gets English fakes. Any other value returns400 invalid_request.
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
- The same person gets the same fake everywhere in one call, and two different people never get the same fake.
- The same
seedgives the same fakes across calls, as long as the text and the detections are the same. - Sensitive categories, such as health, religion and criminal records, are generalised, not faked. No invented diagnosis, belief or conviction is written into your text.
- Types without a realistic generator get a typed placeholder, such as
[LEGAL_COURT_1]. Untyped pieces become[REDACTED].
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
éas one code point = 1.eplus a combining accent = 2.- An emoji outside the Basic Multilingual Plane = 1.
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_textWhitespace-only text includes non-ASCII whitespace such as U+3000. Text that has other characters is never trimmed.
Limits
- Text: 1 to 20,000 Unicode code points.
- Request body: 1 MB.
- Over either limit, the request is refused before the model runs with
413 text_too_long. Nothing is truncated and nothing is charged. - Rate limit: 60 requests per second per key, with a burst of 120. Over it you get
429 rate_limitedwithRetry-After. The same code covers the concurrency limit. All limits are on the Rate limits page. - Concurrency: 4 detections at the same time per account.
- Timeout: a call that takes longer than 30 seconds fails and is not charged.
- Document uploads are not supported. Send plain text.
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": "..." }| Status | Code | Meaning |
|---|---|---|
| 400 | invalid_request | The body is not a valid request: not JSON, wrong Content-Type, unknown fields, model or text missing, or an invalid Idempotency-Key. |
| 400 | invalid_text | The text is empty or whitespace only. Refused before the model runs, no charge. |
| 400 | unknown_category | An entry in exclude matches no category, sub-category or type. See Detection types. No charge. |
| 400 | unknown_model | The model name does not exist. |
| 400 | amount_out_of_range | Console checkout only, not /v1/detect: the top-up amount is outside the allowed range. |
| 401 | unauthorized | The key is missing, invalid or revoked. All three look the same. |
| 401 | key_expired | The key has expired. Create a new key on the API keys page and use it instead. |
| 402 | insufficient_credit | Your credit cannot cover this call. Add credit and retry. |
| 403 | account_not_active | The account is waiting for activation. Questions: hello@opami.ai. |
| 403 | account_blocked | The account is blocked. Contact hello@opami.ai. |
| 404 | resource_not_found | The resource does not exist, or belongs to another account. |
| 409 | idempotency_key_reused | The 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. |
| 408 | request_timeout | The 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. |
| 409 | key_limit_reached | Console key creation only: the account already has 25 active keys. Revoke one first. |
| 413 | text_too_long | More than 20,000 code points of text, or a /v1/detect body over 1 MB. The message says which limit. |
| 413 | request_too_large | A body over 64 KB on any other customer route. |
| 429 | rate_limited | Too many requests, or 4 detections already running for the account. Wait Retry-After seconds and retry. See Rate limits. |
| 429 | model_busy | The model is at capacity. Wait Retry-After seconds and retry with the same Idempotency-Key. See Rate limits. |
| 503 | access_check_unavailable | The access check could not run. Nothing was processed. Retry shortly. |
| 503 | model_unavailable | The model could not answer. Nothing is charged and the key is freed. Retry shortly with the same Idempotency-Key. |
| 503 | service_unavailable | Storage or billing settlement failed. Nothing is charged. Retry shortly. |
A failed or refused call is never charged.