openapi: 3.0.3 info: title: anon-pii Presidio-compatible PII API description: >- Drop-in replacement for Microsoft Presidio's /analyze and /anonymize endpoints. Detects and anonymizes PII using regex patterns, validators, and optional NER. version: 0.1.0 license: name: MIT servers: - url: http://localhost:8080 description: Local API server (anon-pii api --port 8080) paths: /analyze: post: summary: Detect PII entities in text description: >- Runs the full detection pipeline (normalization, pattern matching, validators, NER, overlap resolution) and returns nonoverlapping entities with UTF-8 byte positions and confidence scores, ready for /anonymize with the same original text. Nested URL audit detections are omitted when their enclosing URL is returned. operationId: analyze requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/AnalyzeRequest" example: text: "Contact john@example.com or call +33 6 12 34 56 78" language: en score_threshold: 0.5 entities: - EMAIL_ADDRESS - FR_PHONE_NUMBER responses: "200": description: Nonoverlapping detected entities in source order content: application/json: schema: type: array items: $ref: "#/components/schemas/RecognizerResult" example: - entity_type: EMAIL_ADDRESS start: 8 end: 24 score: 0.85 "400": description: Invalid JSON request body "413": description: Input text exceeds maximum size (50 MB) /anonymize: post: summary: Anonymize text using analyzer results description: >- Applies anonymization operators to the text at positions identified by /analyze. Supports per-entity-type operator configuration with DEFAULT fallback. operationId: anonymize requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/AnonymizeRequest" example: text: "Contact john@example.com" analyzer_results: - entity_type: EMAIL_ADDRESS start: 8 end: 24 score: 0.85 anonymizers: DEFAULT: type: replace EMAIL_ADDRESS: type: mask masking_char: "*" responses: "200": description: Anonymized text with operation details content: application/json: schema: $ref: "#/components/schemas/AnonymizeResponse" example: text: "Contact ****************" items: - operator: mask entity_type: EMAIL_ADDRESS start: 8 end: 24 text: "****************" "400": description: Invalid JSON request body "413": description: Input text exceeds maximum size (50 MB) "422": description: Invalid analyzer results (out of bounds, overlapping, or bad operator config) /supportedentities: get: summary: List supported entity types description: >- Returns all entity types the server can detect. The list depends on compiled features: regex patterns are always available, PERSON requires ner-lite or ner, LOCATION requires ner. operationId: supportedEntities parameters: - name: language in: query description: Accepted for Presidio compatibility but not used (all languages detected simultaneously). required: false schema: type: string responses: "200": description: Sorted array of entity type names content: application/json: schema: type: array items: type: string example: - ABA_ROUTING_NUMBER - AIRCRAFT_REGISTRATION - AUTH_TOKEN - CREDIT_CARD - EMAIL_ADDRESS - FR_PHONE_NUMBER - IP_ADDRESS /health: get: summary: Health check operationId: health responses: "200": description: Server is healthy /openapi.yaml: get: summary: OpenAPI specification operationId: openapi responses: "200": description: This OpenAPI 3.0 specification content: application/yaml: schema: type: object components: schemas: AnalyzeRequest: type: object required: [text, language] properties: text: type: string description: Text to analyze for PII entities language: type: string description: Accepted for Presidio compatibility (detection is language-agnostic) score_threshold: type: number format: double default: 0.5 minimum: 0.0 maximum: 1.0 description: Minimum confidence score to include a detection (clamped to 0.0-1.0) entities: type: array items: type: string description: >- If provided, select these entity types before overlap resolution. An empty list or only unknown types returns no detections. return_decision_process: type: boolean default: false description: Accepted for Presidio compatibility (not yet implemented) RecognizerResult: type: object required: [entity_type, start, end, score] properties: entity_type: type: string description: "PII entity type (e.g., EMAIL_ADDRESS, FR_PHONE_NUMBER)" start: type: integer description: Start byte offset in the input text end: type: integer description: End byte offset (exclusive) in the input text score: type: number format: double description: Confidence score (0.0-1.0) AnonymizeRequest: type: object required: [text, analyzer_results] properties: text: type: string description: Original text to anonymize analyzer_results: type: array items: $ref: "#/components/schemas/AnalyzerResult" description: Detections from /analyze (must not overlap) anonymizers: type: object additionalProperties: $ref: "#/components/schemas/AnonymizerConfig" description: >- Per-entity-type operator config. Keys are entity type names or "DEFAULT". Falls back to DEFAULT, then to replace with mapping token. AnalyzerResult: type: object required: [entity_type, start, end, score] properties: entity_type: type: string start: type: integer description: Start byte offset in the original text end: type: integer description: End byte offset (exclusive) in the original text score: type: number format: double # Operator configs — discriminated by "type" field AnonymizerConfig: oneOf: - $ref: "#/components/schemas/ReplaceConfig" - $ref: "#/components/schemas/RedactConfig" - $ref: "#/components/schemas/MaskConfig" - $ref: "#/components/schemas/HashConfig" - $ref: "#/components/schemas/EncryptConfig" - $ref: "#/components/schemas/KeepConfig" - $ref: "#/components/schemas/CustomConfig" discriminator: propertyName: type mapping: replace: "#/components/schemas/ReplaceConfig" redact: "#/components/schemas/RedactConfig" mask: "#/components/schemas/MaskConfig" hash: "#/components/schemas/HashConfig" encrypt: "#/components/schemas/EncryptConfig" keep: "#/components/schemas/KeepConfig" custom: "#/components/schemas/CustomConfig" ReplaceConfig: type: object required: [type] properties: type: type: string enum: [replace] new_value: type: string description: >- Fixed replacement string. If omitted, generates a mapping token like [EMAIL_ADDRESS_a1b2c3d4]. RedactConfig: type: object required: [type] description: Remove the detected text entirely (replace with empty string) properties: type: type: string enum: [redact] MaskConfig: type: object required: [type] properties: type: type: string enum: [mask] masking_char: type: string maxLength: 1 default: "*" description: Character used for masking chars_to_mask: type: integer minimum: 0 description: Number of characters to mask. If omitted, masks the entire value. from_end: type: boolean default: false description: If true, mask from the end instead of the start HashConfig: type: object required: [type] properties: type: type: string enum: [hash] hash_type: type: string enum: [sha256, sha512, md5] default: sha256 description: Hash algorithm to use EncryptConfig: type: object required: [type, key] properties: type: type: string enum: [encrypt] key: type: string description: >- AES key as hex string (32 chars = 128-bit, 48 = 192-bit, 64 = 256-bit). Output is ENC[hex(iv||ciphertext)]. KeepConfig: type: object required: [type] description: Leave the detected text unchanged (useful for selective anonymization) properties: type: type: string enum: [keep] CustomConfig: type: object required: [type, lambda] properties: type: type: string enum: [custom] lambda: type: string description: >- Format string with {entity_type} placeholder (e.g., "<{entity_type}>" produces "") AnonymizeResponse: type: object required: [text, items] properties: text: type: string description: The anonymized text items: type: array items: $ref: "#/components/schemas/OperatorResult" description: Details of each anonymization operation, in document order OperatorResult: type: object required: [operator, entity_type, start, end, text] properties: operator: type: string description: Operator that was applied (replace, redact, mask, hash, encrypt, keep, custom) entity_type: type: string description: Entity type that was anonymized start: type: integer description: Start byte offset of the replacement in the anonymized text end: type: integer description: End byte offset (exclusive) of the replacement in the anonymized text text: type: string description: The replacement text