Skip to content

OCR & PII Redaction

Text recognition with bounding boxes and PII redaction on images, powered by the Apple Vision framework. Endpoints live under /api/ocr/, are queued (poll /queue/result), and report the model as apple-vision-ocr.

Local and stateless

OCR runs host-native on our own EU infrastructure (Apple Silicon). Images and the extracted text never leave our servers and are never written to disk: they transit RAM only. The redacted image returns to you and nothing is retained.

Endpoints

EndpointUse Case
POST /api/ocr/recognizeText recognition: lines (and optionally words) with pixel bounding boxes
POST /api/ocr/redactPII redaction: blur, box or pixelate text matching regexes, presets or explicit regions
GET /api/ocr/languagesSupported recognition languages per level (fast / accurate)

Text Recognition

json
// POST /api/ocr/recognize
{
  "image": "<base64_encoded_image>",
  "recognitionLevel": "accurate",   // "fast" | "accurate"
  "granularity": "word",            // "line" | "word" (word adds per-word boxes)
  "languages": ["es-ES", "en-US"]   // omit for automatic language detection
}
json
// result (via /queue/result)
{
  "text": "Contact: john@acme.com",
  "lines": [
    {
      "text": "Contact: john@acme.com",
      "confidence": 0.97,
      "bbox": { "x": 120, "y": 45, "width": 830, "height": 42 },
      "words": [ { "text": "Contact:", "confidence": 0.97, "bbox": { "x": 120, "y": 45, "width": 210, "height": 42 } } ]
    }
  ],
  "model": "apple-vision-ocr",
  "imageSize": { "width": 3024, "height": 4032 },
  "inferenceTimeMs": 214
}

Bounding boxes use a top-left origin in pixels. Omitting languages enables automatic language detection; call GET /api/ocr/languages for the list supported per recognition level.

PII Redaction

Provide regex patterns, built-inpresets (email, phone, iban, credit_card, dni_nie) and/or explicit pixel regions. Matches are redacted at word level where possible, whole line otherwise (over-redact, never under-redact). Styles: blur (default),box,pixelate. For hard PII redaction, preferbox: blurred or pixelated text can sometimes be partially reconstructed.

json
// POST /api/ocr/redact
{
  "image": "<base64_encoded_image>",
  "presets": ["email", "phone", "iban"],
  "patterns": ["\\bAB-\\d{6}\\b"],
  "style": "blur",
  "blurStrength": 51,
  "padding": 4
}
json
// result (via /queue/result)
{
  "redactedImage": "<base64_png>",
  "detections": [
    { "text": "john@acme.com", "pattern": "email", "bbox": { "x": 320, "y": 45, "width": 240, "height": 42 }, "granularity": "word" }
  ],
  "regionsRedacted": 3,
  "counts": { "email": 1, "phone": 2 },
  "model": "apple-vision-ocr",
  "inferenceTimeMs": 268
}

Behaviour

  • Input formats: PNG, JPEG, HEIC, TIFF, WebP. EXIF orientation is normalized, so all coordinates and the returned image share one upright pixel space.
  • Images over 24MP are downscaled for recognition, but coordinates and redactions are reported at the original resolution.
  • An empty result is a success with empty arrays, not an error.
  • Concurrency is bounded by PROVIDER_CONCURRENCY_OCR (default 2).