Contact Us

Tell us about your stack and the privacy problems you're trying to solve. We typically respond within one business day.

Prefer email? support@philterd.ai

Please do not enter PII or PHI in this form. If you need to share an example, use a sanitized one.

Knowledge base How-to

Calling PhEye's API Directly

Call PhEye's REST API from any language: find person names with scores and character offsets, set labels and thresholds, and handle text longer than the model reads.

For PhEye

PhEye is the model server behind the Philterd toolkit. Philter and Phileas call it to find person names, and any application can call it the same way: post text over HTTP, and get back each entity with its label, a confidence score, and its character offsets. This guide covers the API of the published PhEye 1.3.0 images: checking the service, finding entities, the request fields, reading scores, and handling text longer than the model reads.

Detection is probabilistic. The scores tell you how confident the model is, not whether a span is a name, so validate the results against your own text.

Your application posts text to PhEye's /find endpoint, optionally with labels and a threshold. PhEye runs the model bundled in its container and returns each entity it found: the label name, the matched text Toni Levine, a confidence score of 0.996, and start and end offsets 30 and 41. Your code uses the offsets to redact or tag the text. PhEye 1.3.0 reads only the first 512 words of a request, so longer text has to be split before sending.

Start PhEye

Each image bundles one model, downloaded into the image when it was built, so the container needs no network access to Hugging Face at runtime. The default English name model is pii_en_small:

docker run -d --name pheye -p 5000:5000 philterd/ph-eye:1.3.0-pii_en_small

until curl -sf http://localhost:5000/status > /dev/null; do sleep 2; done
curl http://localhost:5000/status
healthy

GET /status returns the plain text healthy once the model has loaded. The service has no authentication of its own, so run it on a private network and let only the applications that need it reach port 5000.

Find entities

Post JSON with a text field to /find:

curl -s -X POST http://localhost:5000/find \
  -H "Content-Type: application/json" \
  -d '{"text": "Please forward the invoice to Toni Levine and copy Maria Gonzalez."}'
[{"end":41,"label":"name","score":0.9955614805221558,"start":30,"text":"Toni Levine"},{"end":65,"label":"name","score":0.9915621876716614,"start":51,"text":"Maria Gonzalez"}]

The response is a JSON array with one object per entity:

FieldMeaning
labelThe entity type. The English name models use name.
textThe matched text.
scoreThe model’s confidence, from 0 to 1.
start, endCharacter offsets into the text you sent, counted in Unicode code points as Python does: text[start:end] is the match. A client that counts UTF-16 units, such as JavaScript, Java, or .NET, is off after any character outside the Basic Multilingual Plane, such as an emoji.

An empty array means nothing scored above the threshold.

The request fields

FieldRequiredMeaning
textYesThe text to search.
labelsNoThe entity labels to look for. Left out or empty, the model’s own labels are used: ["name"] for the English name models.
thresholdNoSpans must score above this value. Left out, the model’s default is used: 0.50 for pii_en_xsmall, 0.90 for pii_en_small, 0.70 for pii_en_medium, and 0.95 for pii_en_large.

A request without text fails with status 500 and the name of the missing field as the body:

curl -s -w " [%{http_code}]\n" -X POST http://localhost:5000/find \
  -H "Content-Type: application/json" -d '{"txt": "Toni Levine"}'
'text' [500]

The models are GLiNER models, which accept any label string, but the ph-eye-pii-en-* models are trained for name. Other labels are accepted and are not what the models were evaluated on. Asking for organization alongside name returned only the name:

curl -s -X POST http://localhost:5000/find \
  -H "Content-Type: application/json" \
  -d '{"text": "The claim was reviewed by Priya Natarajan on Monday.", "threshold": 0.3, "labels": ["name", "organization"]}'
[{"end":41,"label":"name","score":0.9950360655784607,"start":26,"text":"Priya Natarajan"}]

Reading the scores

The threshold decides which spans come back. With a low threshold, weaker candidates appear with their scores:

curl -s -X POST http://localhost:5000/find \
  -H "Content-Type: application/json" \
  -d '{"text": "Ms. Rivera called back about the Jordan account.", "threshold": 0.05}'
[{"end":10,"label":"name","score":0.9934520721435547,"start":4,"text":"Rivera"},{"end":39,"label":"name","score":0.16252967715263367,"start":33,"text":"Jordan"}]

At the default 0.90, only Rivera is returned. Here “Jordan” names an account, and its low score reflects that. A score depends on the surrounding words as well as the span, so the same name can score differently in different sentences, and scores are not comparable across the four model sizes, which are calibrated differently.

Pick a threshold by measuring on labeled samples of your own text. In redaction, a missed name is a leak and an extra span is over-redaction, so most teams lean toward the lower threshold that keeps recall high. Choosing a PhEye model size and threshold walks through that measurement.

Text longer than the model reads

A model reads at most 512 words in one call, counting each punctuation mark as a word, and PhEye 1.3.0 ignores the rest of the text. A name after that point is not returned. This 555-word claim note ends with a name:

curl -s -X POST http://localhost:5000/find \
  -H "Content-Type: application/json" -d @long.json
[]

Split longer text into overlapping windows, send each one, and shift the offsets back to the whole text. This script, which uses only the Python standard library, sends windows of 400 words that share 50 words with their neighbors, so a name near a window’s edge is whole in at least one window:

import json
import os
import re
import sys
import urllib.request

PHEYE_URL = os.environ.get("PHEYE_URL", "http://localhost:5000") + "/find"
WINDOW = 400   # words per request, under the model's 512
OVERLAP = 50   # words shared by neighboring windows

# Count words the way GLiNER does: each punctuation mark is a word.
WORD = re.compile(r"\w+(?:[-_]\w+)*|\S")


def find(text, threshold=None):
    body = {"text": text}
    if threshold is not None:
        body["threshold"] = threshold
    request = urllib.request.Request(PHEYE_URL, data=json.dumps(body).encode("utf-8"),
                                     headers={"Content-Type": "application/json"})
    with urllib.request.urlopen(request) as response:
        return json.load(response)


def find_long(text, threshold=None):
    words = [m.span() for m in WORD.finditer(text)]
    if not words:
        return []
    found = {}
    first = 0
    while True:
        last = min(first + WINDOW, len(words))
        start, end = words[first][0], words[last - 1][1]
        for entity in find(text[start:end], threshold):
            # Shift offsets from the window back to the whole text.
            entity["start"] += start
            entity["end"] += start
            key = (entity["start"], entity["end"])
            # An entity in an overlap is returned twice. Keep the higher score.
            if key not in found or entity["score"] > found[key]["score"]:
                found[key] = entity
        if last == len(words):
            break
        first = last - OVERLAP
    # A name cut off at a window's edge comes back partial from one window and whole from the
    # next. Drop any entity that lies inside another.
    entities = sorted(found.values(), key=lambda e: (e["start"], -e["end"]))
    kept = []
    for entity in entities:
        if kept and entity["end"] <= kept[-1]["end"]:
            continue
        kept.append(entity)
    return kept


if __name__ == "__main__":
    text = open(sys.argv[1]).read()
    print(json.dumps(find_long(text), indent=2))

Run on the same claim note as plain text, it finds the name:

python3 find_long.py claim-notes.txt
[
  {
    "end": 3167,
    "label": "name",
    "score": 0.995262622833252,
    "start": 3156,
    "text": "Toni Levine"
  }
]

claim-notes.txt[3156:3167] is Toni Levine. A name placed inside the overlap of two windows was also returned once. Keep OVERLAP well above the longest name you expect, in words.

In the next release

PhEye’s main branch, version 1.4.0, has not been published as an image yet. Checked against a build of it, it changes three things in this guide:

  • The health check moves from GET /status to GET /health, which returns {"applicationVersion":"1.4.0","status":"UP"}.
  • GET /model returns the model’s name and limits, such as {"maxWidth":12,"maxWords":512,"name":"pii_en_small"}.
  • /find splits long text into windows itself and returns offsets into the whole text, so the 555-word note above returns Toni Levine with no client-side windowing.

Until that image is published, use the 1.3.0 behavior described above.

Where to go next