ID Document OCR for KYC
Read the text on passports, driving licences, and ID cards with one API call. Pixicular returns each line as JSON; your code maps the lines to the fields your KYC flow needs.
Published 2026-05-18 · Updated 2026-10-26

detect-text service returns each line with a confidence score, and your code turns the lines into fields.TL;DR. To extract text from an ID document with an API, POST the image to Pixicular with services=detect-text. The API returns every line of text it reads, each with a confidence percentage, as JSON in one call. Your code maps those lines to fields such as name or document number. OCR captures data for KYC; it does not verify identity.
How does ID document OCR work?
The detect-text service runs optical character recognition on the uploaded image. It finds the text on the document, reads it, and returns one entry per line in a detections list. Each entry carries the text as read (detectedText), its type (LINE), and a confidence percentage. On a passport data page that means the document title, the issuing country, field captions such as "Surname", the values next to them, and the two lines of the machine-readable zone (MRZ) at the bottom.
The API stops there. It does not match lines to fields, classify the document, or normalise dates: there is no surname or dateOfBirth key in the response. That part is your code, and for most identity documents it is manageable, because the MRZ was designed for machines: fixed positions, a fixed character set, and check digits that tell you whether a read is plausible. Pixicular's image analysis API gives you the raw lines in one call; a few dozen lines of parsing turn them into a record you can validate.

Which document types are supported?
Because detect-text is general-purpose OCR rather than a template engine, it reads any document whose text is legible in the photo. What changes between document types is the parsing work on your side:
| Document type | What OCR reads | What your parser does |
|---|---|---|
| Passport | Data-page text, plus the two 44-character MRZ lines (TD3) at the bottom | Parse the MRZ by position, validate its four check digits, and cross-check it against the printed fields |
| National ID card | Printed text on each side; many cards carry a three-line, 30-character MRZ (TD1) on the back | Send each side as its own image; parse and validate the TD1 MRZ where there is one |
| Driving licence | Printed text; EU card licences number their fields (1 surname, 2 given names, 3 date of birth, 4b expiry, 5 licence number) | Map lines by field number or caption; the PDF417 barcode on many US licences is not decoded |
| Residence permit | Printed text; card-format permits usually carry a TD1 MRZ | Same as ID cards: parse and validate the MRZ, then the printed fields |
detect-text reads printed text only. It does not decode barcodes, read the NFC chip in an e-passport or ID card, or tell you which document it is looking at. If you need the type, take it from the MRZ document code (P for passports; I, A or C for ID cards) or ask the user to choose before capture. The API documentation has the current response schema.
What does the detect-text response look like?
A request returns one JSON document with a key per requested service under services. For detect-text, the value is a detections list. The example below is a fictional specimen passport issued by "Utopia" (UTO, the test code used in ICAO specimens). The list is trimmed for length; in a real response the field captions come back as lines too.
{
"success": true,
"requestId": "req_Lq3VbX8sT2mN6yKcPa",
"services": {
"detect-text": {
"detections": [
{ "detectedText": "PASSPORT", "type": "LINE", "confidence": 99.6 },
{ "detectedText": "UTOPIA", "type": "LINE", "confidence": 99.4 },
{ "detectedText": "SPECIMEN", "type": "LINE", "confidence": 99.7 },
{ "detectedText": "ANNA MARIA", "type": "LINE", "confidence": 99.1 },
{ "detectedText": "14 FEB 1990", "type": "LINE", "confidence": 98.8 },
{ "detectedText": "12 JUN 2034", "type": "LINE", "confidence": 98.6 },
{
"detectedText": "P<UTOSPECIMEN<<ANNA<MARIA<<<<<<<<<<<<<<<<<<<",
"type": "LINE",
"confidence": 95.9
},
{
"detectedText": "X4K8L2M7Q5UTO9002144F3406120<<<<<<<<<<<<<<04",
"type": "LINE",
"confidence": 95.2
}
]
}
},
"photo": { "id": "photo_8RkTn2WqZf5LcY7hJd", "status": "COMPLETED" },
"creditCost": 1,
"processingTimeMs": 1250,
"processedAt": "2026-10-26T09:30:00.000Z"
}Each confidence is a percentage for that line, not for a field. Do not depend on the order of the lines: find the ones you need by their content (the MRZ by its length and character set, a date by its format) rather than by index. The full schema is in the API documentation.
Code: calling the ID document OCR API
Authenticate with a bearer token in the Authorization header and upload the image as multipart/form-data with a file part. The API accepts JPEG, PNG, WebP, AVIF, and TIFF images up to 10 MB and between 100×100 and 4096×4096 pixels. The TypeScript example reads a passport and parses its MRZ, validating the check digits before it trusts any value.
curl
curl -X POST https://api.pixicular.com/v1/detect \
-H "Authorization: Bearer $PIXICULAR_API_KEY" \
-F "file=@./passport-data-page.jpg" \
-F "services=detect-text"TypeScript — parse a passport MRZ
interface TextDetection {
detectedText: string;
type: "LINE" | "WORD";
confidence: number;
}
// ICAO 9303 check digit: weights 7, 3, 1; "<" = 0, A = 10 ... Z = 35.
function checkDigit(field: string): string {
const value = (c: string) =>
c === "<" ? 0 : /\d/.test(c) ? Number(c) : c.charCodeAt(0) - 55;
const sum = [...field].reduce(
(acc, c, i) => acc + value(c) * [7, 3, 1][i % 3],
0,
);
return String(sum % 10);
}
// Read a passport data page, then parse its two-line (TD3) MRZ yourself.
async function readPassportMrz(file: Blob) {
const body = new FormData();
body.append("file", file);
body.append("services", "detect-text");
const res = await fetch("https://api.pixicular.com/v1/detect", {
method: "POST",
headers: { Authorization: `Bearer ${process.env.PIXICULAR_API_KEY}` },
body,
});
// 202 means the request was queued under load: poll its statusUrl (see the docs).
if (res.status === 202) return { status: "retry_later" };
if (!res.ok) throw new Error(`Pixicular returned ${res.status}`);
const result = await res.json();
const lines: TextDetection[] =
result.services["detect-text"]?.detections ?? [];
// TD3 MRZ lines are 44 characters of A-Z, 0-9 and "<"; drop OCR spaces.
const mrz = lines
.map((l) => l.detectedText.replace(/\s/g, "").toUpperCase())
.filter((t) => /^[A-Z0-9<]{44}$/.test(t));
const line1 = mrz.find((t) => /^P[A-Z<]+$/.test(t));
const line2 = mrz.find((t) => t !== line1);
if (!line1 || !line2) return { status: "manual_review" };
const documentNumber = line2.slice(0, 9);
const birthDate = line2.slice(13, 19); // YYMMDD
const expiryDate = line2.slice(21, 27); // YYMMDD
const checksPass =
checkDigit(documentNumber) === line2[9] &&
checkDigit(birthDate) === line2[19] &&
checkDigit(expiryDate) === line2[27] &&
checkDigit(line2.slice(0, 10) + line2.slice(13, 20) + line2.slice(21, 43)) ===
line2[43];
// A failed check digit means a misread (or a bad document): ask for a new photo.
if (!checksPass) return { status: "manual_review" };
const [surname, givenNames = ""] = line1.slice(5).split("<<");
return {
status: "parsed",
surname: surname.replace(/</g, " ").trim(),
givenNames: givenNames.replace(/</g, " ").trim(),
documentNumber,
birthDate,
expiryDate,
};
}The parser is yours to extend: TD1 ID cards use three 30-character lines with the same check-digit scheme. You can request detect-text alongside other services in one call by passing a comma-separated list in services — for example age estimation on the document portrait, whose estimated range you can compare with the date of birth in the MRZ. Each service is billed as one operation. See the API documentation for authentication and the multi-service response schema.
How accurate is ID document OCR?
Pixicular does not publish an accuracy figure for OCR, and the result depends more on the photo than on anything else. Measure it on a sample of images that look like your real uploads before you set thresholds. Most missing or misread text comes from the capture:
- Resolution: the smallest characters, usually the MRZ, must be sharp. Do not shrink phone photos hard before upload; the API accepts up to 4096 px on a side.
- Angle: photograph the document flat and front-on; steep angles distort characters.
- Lighting: use diffuse light; a glare hotspot on the laminate can hide a whole line.
- Completeness: keep the whole document in frame; a cropped MRZ cannot be validated.
Use the per-line confidence to decide what needs a second look — for example, send any MRZ line below 90 to manual review, then tune that threshold on your own data. Check digits are the stronger signal: a mismatch means a character was misread (or the document is not what it claims to be), so ask for a new photo rather than guessing the correction.
Where does OCR fit in a KYC onboarding flow?
Know-your-customer checks establish that customers are who they say they are. OCR does not do that: it turns the text on a document into data, but it does not prove the document is genuine, unaltered, or held by the person presenting it. Pixicular does not check security features, detect edited documents, read e-passport chips, run liveness checks, or compare a selfie with the document portrait. Treat detect-text as the data-capture step in a flow that an identity verification provider, or trained reviewers, complete:
- Capture: the user photographs the document. Client-side checks (file size, blur, minimum resolution) reject unusable photos before upload.
- Extract: your server sends the image to
/v1/detectwithservices=detect-textand receives the text lines. - Parse and validate: your code parses the MRZ, checks the check digits, and confirms the expiry date is in the future.
- Pre-fill: the onboarding form shows the parsed values for the user to confirm, which cuts typing errors.
- Verify: document authenticity, liveness, and face match run in your identity verification step, with sanctions and PEP screening as your regulation requires.
- Escalate: low-confidence reads, failed check digits, and mismatches between the MRZ and what the user typed go to manual review.
If you only need to know whether a user is likely an adult, a document check may be more than you need: the age verification API guide covers how photo age estimation and document checks combine.
GDPR, data minimisation, and KYC compliance
Identity document data — names, dates of birth, document numbers, addresses, and the image itself — is personal data under the GDPR and comparable laws. Processing it needs a lawful basis: for regulated financial services this is usually a legal obligation under anti-money-laundering rules; elsewhere it may be a contract or consent with a clear purpose. Some countries add rules for national identification numbers (GDPR Article 87 lets member states set them).
Know where the data goes. Per the Pixicular privacy policy, uploaded images are retained for 30 days after analysis, and detection results — which for detect-text include the extracted text — for the life of your account plus 90 days. Include that in your data protection impact assessment (DPIA) and records of processing. On your side, the practical pattern is minimisation:
- Send the document image to the
detect-textservice. - Parse the fields your KYC process needs (name, date of birth, document number, expiry).
- Store those fields, not the raw image, against the user record unless a regulation requires the image.
- Keep the stored fields only as long as your obligations require: typically the customer relationship plus any mandated retention period.
This section is general information, not legal advice; confirm your obligations with your data protection officer. For extracting text from other kinds of images, see the general OCR API guide.
Frequently asked questions
How do you extract text from an ID document with an API?
POST the document image to https://api.pixicular.com/v1/detect with services=detect-text. Pixicular reads the text on the document and returns each line it finds in a detections list, with the text and a confidence percentage. It does not return named fields such as surname or date of birth: your code maps the lines to the fields you need, for example by parsing a passport's machine-readable zone (MRZ) and validating its check digits.
Which ID document types does the OCR API support?
detect-text is general-purpose OCR, so it reads printed text on any document photo: passport data pages, national ID cards, driving licences and residence permits. It has no document templates and does not classify the document type. It reads printed text only; it does not decode barcodes such as PDF417 or read the chip in an e-passport. Images can be JPEG, PNG, WebP, AVIF or TIFF, up to 10 MB and between 100×100 and 4096×4096 pixels.
How accurate is ID document OCR?
Pixicular does not publish an accuracy figure for OCR, so measure it on images that look like your own uploads. Results are best on sharp, evenly lit, flat photos of the whole document; glare on laminate, blur, low resolution, steep angles and cropped edges cause missing or misread characters. Use the per-line confidence to send weak reads to manual review, and validate the MRZ check digits, which catch many single-character misreads.
Is ID document OCR enough for KYC?
No. OCR captures the text on a document; it does not prove that the document is genuine or that it belongs to the person submitting it. Pixicular does not check security features, detect edited documents, read e-passport chips, run liveness checks or match a selfie to the document portrait. Use OCR to pre-fill and cross-check onboarding data, and use a dedicated identity verification provider or trained reviewers for the verification itself.
Are the ID images I send stored, and what does the GDPR require?
Per the Pixicular privacy policy, uploaded images are retained for 30 days after analysis and detection results, which for detect-text include the extracted text, for the life of your account plus 90 days. Identity document data is personal data under the GDPR, so you need a lawful basis (for regulated firms usually a legal obligation under anti-money-laundering rules), a retention policy and, in many cases, a data protection impact assessment. Keep only the fields your KYC process needs. This is general information, not legal advice.
Add ID document OCR to your onboarding flow
The fastest way to evaluate detect-text is to send a photo of a test document with the curl command above and run your parser on the lines that come back. Pick a plan on the pricing page and follow the API documentation for authentication and the full response schema.