> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tenetlabs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# API overview

> The PII Engine (Enterprise) wire protocol: detect (/detect, /redact, /deidentify, DELETE /sessions) and rehydrate (/reidentify) behind VPC Lattice, IAM SigV4 per caller, JSON in and out, snake_case throughout.

**Two endpoints, one protocol.** The detect service and the rehydrate service are separate Amazon VPC Lattice services inside your VPC. Every request is signed with SigV4 as the caller's own IAM role, over HTTPS on 443. JSON in, JSON out, `snake_case` fields.

| Service | Base URL | Routes |
| - | - | - |
| Detect | `DetectEndpoint` output (Terraform `detect_endpoint`; EKS: the detect HTTPRoute's `application-networking.k8s.aws/lattice-assigned-domain-name` annotation), `https://<name>.<hash>.vpc-lattice-svcs.<region>.on.aws` | `POST /detect`, `POST /redact`, `POST /deidentify`, `DELETE /sessions/{session_id}` |
| Rehydrate | `RehydrateEndpoint` output (Terraform `rehydrate_endpoint`; EKS: the rehydrate HTTPRoute's annotation) | `POST /reidentify` |

Lattice forwards only those exact methods and paths — case-sensitive, no trailing slash. Anything else, including `/reidentify` on the detect endpoint and the health probes, is a `404` from Lattice and never reaches a task.

## Auth

Sign each request with AWS Signature Version 4:

| | |
| - | - |
| Service name | `vpc-lattice-svcs` |
| Region | The service's Region |
| Payload | Unsigned: send `x-amz-content-sha256: UNSIGNED-PAYLOAD` |
| Credentials | The caller's own IAM role (task role, IRSA, instance profile, assumed role). Temporary credentials add `x-amz-security-token`. |

Use the `tenet-pii-lattice` client (`pip install https://platform.tenetlabs.com/enterprise/current/tenet_pii_lattice.tar.gz`; Python 3.11+, `boto3`), or any SigV4 signer — plain botocore `SigV4Auth` is enough. The calling role must be named for that route in the service's auth policy (detect, erasure or rehydrate invoker list) **and** have `vpc-lattice-svcs:Invoke` in its own IAM policy. A same-account caller with only one of the two is refused. Setup: [Callers](https://docs.tenetlabs.com/pii-engine/deploy/ecs-cloudformation.md#callers).

A refusal is always a fixed `403`. Lattice answers it when the auth policy denies the request; the service answers `{"detail": "forbidden"}` when its own re-check fails, and logs the reason at `WARNING`. There is no `401` and no bearer token.

## Endpoints

| Endpoint | Does | Stores anything? |
| - | - | - |
| `POST /detect` | `{"text"}` → `{"findings": [{label, start, end, confidence, source}]}` | No |
| `POST /redact` | Detect, then rewrite with `strategy`: `mask` (default), `last_four`, `hash_prefix`, `drop` | No |
| `POST /deidentify` | Replace spans with `[LABEL_N]` placeholders; store the originals, sealed to the vault key pair's public key, under a session | Yes — vault, for the session TTL |
| `DELETE /sessions/{session_id}` | Erase a session. Erasure invoker roles only. Writes a `tenet.erasure-audit.v1` record first. | Deletes. Always `204`. |
| `POST /reidentify` | Restore placeholders from the session; write a `tenet.reidentify-audit.v3` record first | Writes the audit record |

`/detect`, `/redact` and `/deidentify` accept optional `confidence_threshold` (float) and `code_filter` (bool) per request; the service default threshold is `0.55`. `hash_prefix` needs a server-side key (`TENET_PII_SERVE_HASH_KEY`); without one it's a `400`.

`GET /healthz` (liveness, `{"status": "ok", "version": "<engine version>"}`) and `GET /readyz` (model loaded and vault reachable) are served on port `19991` inside each task or pod for container health checks, Kubernetes probes and the Lattice target groups. Callers can't reach them.

## Example

```bash theme={null}
# The tenet-pii-lattice CLI signs with your current AWS credentials. Text comes from stdin.
echo "Email jane@example.com about the invoice." \
  | python -m tenet_pii_lattice "$DETECT_ENDPOINT" deidentify
# → {"text": "Email [EMAIL_1] about the invoice.", "session_id": "AbC…", "expires_at": 1790000000.0,
#    "findings": [{"label": "EMAIL", "start": 6, "end": 19, "confidence": 1.0, "source": "regex"}],
#    "timings": {"detect_ms": …, "vault_ms": …, "total_ms": …}}

echo "Sure, I have sent [EMAIL_1] a reminder." \
  | python -m tenet_pii_lattice "$REHYDRATE_ENDPOINT" reidentify "AbC…"
# → {"text": "Sure, I have sent jane@example.com a reminder.", "session_id": "AbC…", "restored": 1, "unresolved": []}
```

```python theme={null}
from tenet_pii_lattice import LatticeClient, TenetLatticeError

with LatticeClient(detect_endpoint) as detect:          # one client per thread; reuses its connection
    out = detect.deidentify("Email jane@example.com about the invoice.")

with LatticeClient(rehydrate_endpoint) as rehydrate:     # as a role in the rehydrate invoker list
    restored = rehydrate.reidentify(reply_text, out["session_id"])["text"]
```

`/reidentify` and `DELETE /sessions/{session_id}` responses carry `X-Request-ID`, equal to the `request_id` of the audit record the call wrote. Reuse connections: each new connection pays a TLS handshake.

## Errors

Every non-2xx from the service carries `detail` — a string, except `422`, where it's a list of validation errors (`loc`, `msg`, `type`). Lattice's own `403` and `404` carry Lattice's body. Treat any non-2xx as failure; the client raises `TenetLatticeError(status, detail)`.

| Status | Where | Meaning |
| - | - | - |
| `400` | `/redact`, `/deidentify`, `/reidentify` | Unknown `strategy`; `hash_prefix` without a key; session limit (10,000 placeholders); malformed `session_id` |
| `403` | All routes | Refused by the Lattice auth policy, or by the service's re-check. Fix IAM, the invoker lists or the approval tag; don't retry. |
| `404` | `/deidentify`, `/reidentify` | Unknown or expired `session_id` |
| `404` | Any other method or path | Not routed by Lattice |
| `409` | `/deidentify` | Concurrent writes to one session — retry |
| `422` | All routes with a body | Body validation (e.g. missing `text`) |
| `503` | `/reidentify` | Audit record couldn't be written; nothing restored |
| `503` | `DELETE /sessions/{session_id}` | Erasure audit record couldn't be written; nothing deleted |

## About this reference

The endpoint pages are generated from the services' own OpenAPI schema for the current image. The error responses on those pages — including `403`, Lattice's `404`, `409` and `503` — are part of the contract. The **Try it** playground can't reach your services — they're internal to your VPC and need SigV4.

## Links

* [Placeholders and sessions](https://docs.tenetlabs.com/pii-engine/concepts/placeholders-and-sessions.md)
* [Rehydration and audit](https://docs.tenetlabs.com/pii-engine/concepts/rehydration-and-audit.md)
* [Callers on ECS](https://docs.tenetlabs.com/pii-engine/deploy/ecs-cloudformation.md#callers), [on EKS](https://docs.tenetlabs.com/pii-engine/deploy/eks-helm.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.