The problem
A scan can look like a normal document while containing no selectable text. A text-based agent sees an image or an empty extraction instead of the words on the page. It needs optical character recognition before it can search or reason about the content.
How NativePort helps
NativePort connects the document to Mistral’s reading service. It recognizes printed text and returns a readable version with page structure, so your agent can summarize or search the document. You can keep the page boundaries to trace an answer back to the scan.
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()
print("\n\n".join(page["markdown"] for page in result["pages"]))For a PNG or JPG, use {"type": "image_url", "image_url": ...} in document and keep pages: [0]. The output is extracted text and Markdown; this call does not add a searchable text layer to your original PDF.
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.