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.
| Method | Content-Type | Recommended for |
|---|---|---|
| Recommended Multipart | multipart/form-data | curl, Postman, HTML forms |
| Base64 JSON | application/json | JavaScript, mobile apps |
| URL Fetch | application/json | Cloud-hosted images |
| Binario | image/jpeg, image/png, image/webp | CLI tools, streaming |
Endpoints
/api/v1/extractExtracts data from an image of the passport data page.
RecommendedMultipart Form-Data
Send files directly. Ideal for curl and Postman.
| Field | Type | Description |
|---|---|---|
image_front | file | Passport data page (required) |
image_back | file | Additional 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.
| Field | Type | Description |
|---|---|---|
image_front | string | Base64 of the front image (required) |
image_back | string | Base64 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.
| Field | Type | Description |
|---|---|---|
image_front_url | string | HTTPS URL of the front image (required) |
image_back_url | string | HTTPS 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"
}/api/v1/balanceReturns 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
| Code | HTTP | Description |
|---|---|---|
MISSING_API_KEY | 401 | No API key provided |
INVALID_API_KEY | 401 | Invalid or revoked API key |
MISSING_IMAGE | 400 | No front image provided |
INVALID_IMAGE_FORMAT | 400 | Unsupported format (use JPEG, PNG, or WebP) |
IMAGE_TOO_LARGE | 400 | Image exceeds 10 MB |
INVALID_BASE64 | 400 | Failed to decode base64 |
INVALID_MULTIPART | 400 | Failed to parse the multipart form |
URL_FETCH_FAILED | 400 | Could not fetch the image from the URL |
URL_INVALID | 400 | Invalid URL (must be HTTPS) |
URL_BLOCKED | 400 | URL blocked for security reasons |
URL_TIMEOUT | 400 | Timed out fetching the image (10s) |
UNSUPPORTED_CONTENT_TYPE | 415 | Unsupported Content-Type |
INSUFFICIENT_TOKENS | 402 | Insufficient token balance |
RATE_LIMITED | 429 | Too many failed or in-flight requests per minute; successful extractions do not count (see the Retry-After header) |
TOO_MANY_FAILED_EXTRACTIONS | 429 | Too many consecutive failed extractions; check your image quality |
EXTRACTION_FAILED | 500 | Extraction error (token refunded) |
INTERNAL_ERROR | 500 | Internal server error |
Extracted fields
The API extracts the following fields from the passport data page:
passportNumberPassport number
surnameSurname(s)
givenNamesGiven names
nationalityNationality
dateOfBirthDate of birth
sexSex
placeOfBirthPlace of birth
dateOfIssueDate of issue
dateOfExpiryDate of expiry
issuingCountryIssuing country (ICAO code)
issuingAuthorityIssuing authority
personalNumberPersonal number (if present)
mrzLine1MRZ line 1
mrzLine2MRZ 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