National ID Card OCR API

Our National ID Card OCR API provides enterprise-grade data extraction for global identity verification. With specialized support for European (e.g., Romania), South American (e.g., Brazil, Argentina), and African regions, it automatically handles complex multi-line addresses, specialized personal numbers (CNP, CPF, NIN), and derived data fields to ensure seamless KYC automation.


Endpoint

POSThttps://api.structocr.com/v1/national-id

Request Parameters

Important: This endpoint requires application/json Content-Type. Images must be sent as Base64 strings.

ParameterInRequiredDescription
x-api-keyHeaderRequiredYour unique API key generated from the dashboard.
Content-TypeHeaderRequiredMust be set to application/json.
imgBody (JSON)RequiredThe Base64 encoded string of the ID card image.
  • Supports standard Data URI (e.g., data:image/jpeg;base64,...)
  • Supports raw Base64 strings
  • Max file size: 4.5MB
  • Formats: JPG, PNG, WebP
  • For best response time, compress to under 300 KB before sending — see compression guide

Response Schema

The following fields are extracted into the data object. All dates are normalized to YYYY-MM-DD.

FieldDescription
typeDocument type indicator (fixed as 'national_id').
country_codeISO 3166-1 alpha-3 country code (e.g., 'ROU', 'BRA').
document_numberThe unique serial number of the physical ID card.
personal_numberNational ID number (CNP for Romania, CPF for Brazil, NIN for Nigeria).
card_seriesDocument series identifier (common in EU IDs, e.g., 'RX').
surnameThe holder's last name or family name.
given_namesThe holder's first and middle names.
sexGender indicator, typically 'M' or 'F'.
date_of_birthHolder's birth date in YYYY-MM-DD format.
place_of_birthFull text location of birth (City/Region).
addressFull residential address (supports multi-line extraction).
date_of_issueThe date when the identification card was issued.
date_of_expiryThe date when the document's validity expires.
issuing_authorityThe government agency that issued the document.
additional_fieldsObject containing region-specific data and raw Machine Readable Zone (MRZ) lines.
additional_fields.mrz_line_1Raw text of the first MRZ line (if present).
additional_fields.mrz_line_2Raw text of the second MRZ line (if present).
additional_fields.mrz_line_3Raw text of the third MRZ line (if present).
additional_fields.tramite_numberArgentine DNI Trámite Number.
additional_fields.ejemplarDocument edition identifier (e.g., 'A', 'B' on Argentine DNI).
additional_fields.phone_numberPhone number extracted from the document (e.g., Ethiopia Fayda).

Code Examples

Request Implementation

curl -X POST https://api.structocr.com/v1/national-id \
  -H "Content-Type: application/json" \
  -H "x-api-key: YOUR_API_KEY" \
  -d '{
    "img": "data:image/jpeg;base64,/9j/4AAQSkZJRg..."
  }'

Success Response (200 OK)

JSON EXAMPLE
{
  "success": true,
  "data": {
    "type": "national_id",
    "country_code": "ROU",
    "nationality": "ROMANA",
    "document_number": "123456",
    "card_series": "KS",
    "personal_number": "1920319123456",
    "surname": "POPESCU",
    "given_names": "ANDREI",
    "sex": "M",
    "date_of_birth": "1992-03-19",
    "place_of_birth": "Jud. CS Mun. Reșița",
    "address": "Jud. CS Orș. Bocșa Str. Nucilor Nr. 15",
    "date_of_issue": "2020-05-10",
    "date_of_expiry": "2030-05-10",
    "issuing_authority": "SPCLEP Bocșa",
    "additional_fields": {
      "phone_number": null,
      "tramite_number": null,
      "ejemplar": null,
      "mrz_line_1": "IDROU123456<0<<<<<<<<<<<<<<<<",
      "mrz_line_2": "9203195M3005108ROU19203191234562",
      "mrz_line_3": null
    }
  }
}

Live API Test

Live Demo: ID card scanner

No registration required. Upload a file to test the extraction.

1
Upload
2
Results

Drop files here or click to browse

JPG · PNG · WebP  ·  up to 500 files · max 4.5 MB each

No files selected

Error Responses

400 Bad Request - Invalid Input

Returned when JSON is invalid or image data is missing.

{
  "status": 400,
  "code": "INVALID_REQUEST_FORMAT",  
  // or "INVALID_JSON", "INVALID_BASE64_FORMAT"
  "message":"The image data in 'img' field is malformed. Please check for illegal characters (spaces, newlines) or incorrect Base64 encoding."
}

402 Payment Required - Insufficient Credits

{
  "success": false,
  "error": "INSUFFICIENT_CREDITS",
  "message": "Your account balance is insufficient to complete this operation."
}

413 Payload Too Large

{
  "error": "FILE_TOO_LARGE"
}

415 Unsupported Media Type

{
  "error": "INVALID_CONTENT_TYPE_USE_JSON"
}

422 Unprocessable Entity - Policy Violation

{
  "success": false,
  "error": "CONTENT_POLICY_VIOLATION",
  "message": "The document content could not be processed due to safety policies."
}

500 Internal Server Error

{
  "success": false,
  "error": "PROCESSING_ERROR",
  "message": "An internal error occurred while processing the document. Please contact support if the problem persists."
}

503 Service Unavailable - System Busy

{
  "success": false,
  "error": "SYSTEM_BUSY",
  "message": "StructOCR is currently processing a high volume of requests. Please try again in a few seconds."
}

Status Code Definitions

CodeError CodeDescription
200SUCCESSRecognition success
400INVALID_REQUEST_FORMATInvalid payload or corrupted Base64. Ensure the image string has no whitespace, newlines, or illegal characters.
402INSUFFICIENT_CREDITSAccount balance too low
413FILE_TOO_LARGEDecoded image exceeds 4.5MB
415INVALID_CONTENT_TYPENot using application/json
422CONTENT_POLICY_VIOLATIONAI safety/policy block
503SYSTEM_BUSYAPI Rate limit reached