NativePort
← All use cases

Read passport fields without retyping them

Extract named fields from a passport image for a document-review workflow.

The problem

A text agent cannot reliably turn a passport photo into a form submission without reading the image first. Dense labels, machine-readable lines, and unfamiliar names make guessing especially unhelpful: a plausible-looking value can still be wrong.

How NativePort helps

NativePort connects the image to a document reader that returns the fields you request. Your application can show those values beside the original for confirmation. Missing or unclear fields can remain empty instead of being filled with a guess.

Technical implementation

Use Python 3 with requests installed (python -m pip install requests). Set NATIVEPORT_API_KEY in your environment to your NativePort key. Run the snippets on your server, where your key stays private.

Set DOCUMENT_URL to an HTTPS URL the document service can fetch, such as a time-limited file link. The example reads page 0 (the first page). Select only pages you need, up to 100 per request; split longer documents into batches. Send the URL, not inline file bytes.

Use an image of the document’s data page. This example asks for names, passport number, nationality, and expiry date.

python
import os
import requests

BASE = "https://api.nativeport.ai"
HEADERS = {"Authorization": f"Bearer {os.environ['NATIVEPORT_API_KEY']}"}

payload = {
    "document": {"type": "image_url", "image_url": os.environ["DOCUMENT_URL"]},
    "pages": [0],
}
schema = {'type': 'object',
 'properties': {'surname': {'type': ['string', 'null']},
                'given_names': {'type': ['string', 'null']},
                'passport_number': {'type': ['string', 'null']},
                'nationality': {'type': ['string', 'null']},
                'expiry_date': {'type': ['string', 'null']}},
 'required': ['surname',
              'given_names',
              'passport_number',
              'nationality',
              'expiry_date'],
 'additionalProperties': False}
payload["document_annotation_format"] = {
    "type": "json_schema",
    "json_schema": {"name": "extraction", "strict": True, "schema": schema},
}
payload["document_annotation_prompt"] = (
    'Extract only what is visible. Use null for missing or unreadable values.'
)
response = requests.post(BASE + "/mistral/v1/ocr", headers=HEADERS,
                         json=payload, timeout=120)
response.raise_for_status()
result = response.json()
import json
fields = result.get("document_annotation")
if isinstance(fields, str):
    fields = json.loads(fields)
if fields is None:
    raise ValueError("No document annotation returned; inspect the OCR response")
print(fields)

The result is data capture, not a passport authenticity or identity check. Preserve date text as printed and normalize it only after resolving the document’s date format. Structured annotations use the Document AI rate. See the Mistral request policy for document URLs, page selection, and accepted options. OCR returns recognized content; check unclear scans against the source.

Tool costs

Tool used in the examplePrice per call
Mistral — structured extraction $0.005275 / call (1 page)

Prices in USD. Usage-based tools have no fixed per-call price. View pricing.

Let your agent build it

You don’t need to write this code yourself. Copy this page’s link and paste it into your agent. Ask it to follow the guide and implement the feature for you.