API Documentation

Introduction

The Extract Passport Data API lets you extract data from passports of any country programmatically. It uses artificial intelligence to process the images, extract every field on the data page, and validate the MRZ with the ICAO 9303 check digits.

Base URL: https://extractpassportdata.com/api/v1

Authentication

Every API request must be authenticated with an API key. Include your API key in the X-API-Key header of each request.

curl -H "X-API-Key: pass_your_api_key" \
  https://extractpassportdata.com/api/v1/balance

You can create and manage your API keys from the dashboard.

Upload Methods

The API supports several ways to send images. The method is detected automatically from the Content-Type header.

MethodContent-TypeRecommended for
Recommended
Multipart
multipart/form-datacurl, Postman, HTML forms
Base64 JSONapplication/jsonJavaScript, mobile apps
URL Fetchapplication/jsonCloud-hosted images
Binarioimage/jpeg, image/png, image/webpCLI tools, streaming

Endpoints

POST/api/v1/extract

Extracts data from an image of the passport data page.

RecommendedMultipart Form-Data

Send files directly. Ideal for curl and Postman.

FieldTypeDescription
image_frontfilePassport data page (required)
image_backfileAdditional page (optional)
curl -X POST https://extractpassportdata.com/api/v1/extract \
  -H "X-API-Key: pass_your_api_key" \
  -F "image_front=@./passport.jpg" \
  -F "image_back=@./passport_extra.jpg"

Base64 JSON

Send base64-encoded images. The data-URL prefix is optional.

FieldTypeDescription
image_frontstringBase64 of the front image (required)
image_backstringBase64 of the back image (optional)
# Codificar imagen a base64
IMAGE_BASE64=$(base64 -i passport.jpg)

curl -X POST https://extractpassportdata.com/api/v1/extract \
  -H "X-API-Key: pass_your_api_key" \
  -H "Content-Type: application/json" \
  -d "{\"image_front\": \"$IMAGE_BASE64\"}"

URL Fetch

Send URLs of hosted images. Only HTTPS URLs are allowed.

FieldTypeDescription
image_front_urlstringHTTPS URL of the front image (required)
image_back_urlstringHTTPS URL of the back image (optional)
curl -X POST https://extractpassportdata.com/api/v1/extract \
  -H "X-API-Key: pass_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "image_front_url": "https://storage.example.com/passport.jpg",
    "image_back_url": "https://storage.example.com/passport_extra.jpg"
  }'

Binary Upload

Send the raw image as the request body. Supports one image per request.

curl -X POST https://extractpassportdata.com/api/v1/extract \
  -H "X-API-Key: pass_your_api_key" \
  -H "Content-Type: image/jpeg" \
  --data-binary @./passport.jpg

Successful response

{
  "success": true,
  "extraction_id": "clx1234567890",
  "data": {
    "passportNumber": "G12345678",
    "surname": "GOMEZ VELAZQUEZ",
    "givenNames": "MARGARITA",
    "nationality": "MEXICANA",
    "dateOfBirth": "05/07/1980",
    "sex": "F",
    "placeOfBirth": "COAHUILA",
    "dateOfIssue": "05/07/2023",
    "dateOfExpiry": "05/07/2033",
    "issuingCountry": "MEX",
    "issuingAuthority": "SRE",
    "personalNumber": "GOVM800705MCLRLR01",
    "mrzLine1": "P<MEXGOMEZ<VELAZQUEZ<<MARGARITA<<<<<<<<<<<<<",
    "mrzLine2": "G123456786MEX8007050F3307054<<<<<<<<<<<<<<08"
  },
  "tokens_remaining": 19,
  "upload_method": "multipart"
}
GET/api/v1/balance

Returns your account’s current token balance.

Example

curl https://extractpassportdata.com/api/v1/balance \
  -H "X-API-Key: pass_your_api_key"

Response

{
  "success": true,
  "balance": 20
}

Integration Examples

JavaScript / Node.js

// Usando fetch con FormData
const formData = new FormData();
formData.append('image_front', fileInput.files[0]);

const response = await fetch('https://extractpassportdata.com/api/v1/extract', {
  method: 'POST',
  headers: {
    'X-API-Key': 'pass_your_api_key'
  },
  body: formData
});

const result = await response.json();
console.log(result.data);

Python

import requests

url = 'https://extractpassportdata.com/api/v1/extract'
headers = {'X-API-Key': 'pass_your_api_key'}

# Usando archivos (multipart)
files = {
    'image_front': open('passport.jpg', 'rb'),
    'image_back': open('passport_extra.jpg', 'rb')
}

response = requests.post(url, headers=headers, files=files)
result = response.json()
print(result['data'])

PHP

<?php
$curl = curl_init();

curl_setopt_array($curl, [
    CURLOPT_URL => 'https://extractpassportdata.com/api/v1/extract',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => ['X-API-Key: pass_your_api_key'],
    CURLOPT_POSTFIELDS => [
        'image_front' => new CURLFile('passport.jpg'),
        'image_back' => new CURLFile('passport_extra.jpg')
    ]
]);

$response = curl_exec($curl);
$result = json_decode($response, true);
print_r($result['data']);

Error codes

CodeHTTPDescription
MISSING_API_KEY401No API key provided
INVALID_API_KEY401Invalid or revoked API key
MISSING_IMAGE400No front image provided
INVALID_IMAGE_FORMAT400Unsupported format (use JPEG, PNG, or WebP)
IMAGE_TOO_LARGE400Image exceeds 10 MB
INVALID_BASE64400Failed to decode base64
INVALID_MULTIPART400Failed to parse the multipart form
URL_FETCH_FAILED400Could not fetch the image from the URL
URL_INVALID400Invalid URL (must be HTTPS)
URL_BLOCKED400URL blocked for security reasons
URL_TIMEOUT400Timed out fetching the image (10s)
UNSUPPORTED_CONTENT_TYPE415Unsupported Content-Type
INSUFFICIENT_TOKENS402Insufficient token balance
RATE_LIMITED429Too many failed or in-flight requests per minute; successful extractions do not count (see the Retry-After header)
TOO_MANY_FAILED_EXTRACTIONS429Too many consecutive failed extractions; check your image quality
EXTRACTION_FAILED500Extraction error (token refunded)
INTERNAL_ERROR500Internal server error

Extracted fields

The API extracts the following fields from the passport data page:

passportNumber

Passport number

surname

Surname(s)

givenNames

Given names

nationality

Nationality

dateOfBirth

Date of birth

sex

Sex

placeOfBirth

Place of birth

dateOfIssue

Date of issue

dateOfExpiry

Date of expiry

issuingCountry

Issuing country (ICAO code)

issuingAuthority

Issuing authority

personalNumber

Personal number (if present)

mrzLine1

MRZ line 1

mrzLine2

MRZ line 2

Limits and quotas

  • Each extraction consumes 1 token
  • Maximum image size: 10MB
  • Supported formats: JPEG, PNG, WebP
  • URL-fetch timeout: 10 seconds
  • If an extraction fails because of a system error, the token is refunded automatically
  • Tokens never expire