The problem
Scanned statements and forms often combine small print, tables, stamps, and uneven page quality. A basic text extraction may return nothing or scramble columns, leaving the agent to guess which balance or label belongs to which line.
How NativePort helps
NativePort sends the selected pages to a document reader and returns their recognized text with table structure where detected. The agent gets a readable source to review, and your app can preserve page references when a person needs to check a value.
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.
import os
import requests
BASE = "https://api.nativeport.ai"
HEADERS = {"Authorization": f"Bearer {os.environ['NATIVEPORT_API_KEY']}"}
payload = {
"document": {"type": "document_url", "document_url": os.environ["DOCUMENT_URL"]},
"pages": [0],
}
response = requests.post(BASE + "/mistral/v1/ocr", headers=HEADERS,
json=payload, timeout=120)
response.raise_for_status()
result = response.json()
for page in result["pages"]:
print(f"--- Page {page['index'] + 1} ---")
print(page["markdown"])This step reads the document; it does not verify identity, validate account ownership, or reconcile balances. Use a short-lived document link and keep source page numbers alongside extracted values. 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 example | Price per call |
|---|---|
| Mistral — OCR | $0.00422 / 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.