Cursor Tutorial5 min setupDeveloper friendly

Add Passport OCR to Your App using Cursor in 5 Minutes

Cursor's AI writes your boilerplate. StructOCR reads the MRZ lines. Here's the exact prompt to feed into Cursor's Composer to wire them together for instant travel onboarding.

Diagram showing a passport photo uploaded via a UI built in Cursor, sent to the StructOCR API, and returned as structured JSON containing the parsed MRZ, name, and passport number.
Upload → parse → display: the full flow takes a single API call.

Why Cursor + StructOCR is a natural fit for Travel Apps

Cursor generates incredibly accurate full-stack code using advanced AI models right in your IDE. It handles your UI components, state management, and routing automatically — but securely extracting a passport number, nationality, and expiry date from a glossy data page is something the AI can't do natively. StructOCR fills exactly that gap: one API call, structured JSON back. Feed the prompt below into Cursor's Composer, and your booking flow will be ready in seconds.

The problem: AI coding assistants can't parse glossy travel documents

Tools like Cursor are remarkable at writing code — but they stop at the boundary of complex vision tasks. You can instruct Cursor to build a beautiful booking interface in minutes, yet the actual extraction of Machine Readable Zones (MRZ) and visual data from a highly reflective passport page requires a dedicated Passport OCR API. Standard vision models routinely fail on holograms, misread country codes, or output unformatted text blocks.

The solution: ICAO-compliant parsing, instantly

StructOCR's /v1/passport endpoint accepts a photo and returns a clean JSON object with the validated travel document fields. It automatically decodes the MRZ lines to cross-check the Visual Inspection Zone (VIZ), ensuring 100% accuracy on passport numbers and dates. Because it speaks plain HTTP, Cursor can easily generate the client or server-side fetch logic to wire it up.

Integrate StructOCR using Cursor (3 Steps)

  1. Open your project in Cursor and use Composer

    Open your travel or KYC project in Cursor. Hit Cmd+I (or Ctrl+I) to open the Composer. Describe the onboarding UI you want to build.

    Try this prompt: "Build a mobile-friendly hotel check-in UI component using Tailwind. Users can upload a photo of their passport data page, and the app will display the extracted full name, passport number, nationality, and expiry date in a clean card."
  2. Tell Cursor to call the StructOCR API

    Once Cursor scaffolds the component, ask it to create a server-side API route that forwards Base64 image data to StructOCR and returns the response to your UI.

    Follow-up prompt: "Create a server-side /api/passport-ocr route. It must accept a Base64 img string, POST JSON to https://api.structocr.com/v1/passport, and authenticate with the x-api-key header using process.env.STRUCTOCR_KEY."
    // Run this only in a server-side route const response = await fetch('https://api.structocr.com/v1/passport', { method: 'POST', headers: { 'Content-Type': 'application/json', 'x-api-key': process.env.STRUCTOCR_KEY, }, body: JSON.stringify({ img: base64Image }), });
  3. Add your StructOCR API key to your .env file

    Open your local .env or .env.local file and add the StructOCR key as a server-only variable. Restart the development server after saving it.

    Private variable name: STRUCTOCR_KEY — never prefix it with NEXT_PUBLIC_. Get your key at structocr.com/dashboard
    STRUCTOCR_KEY=sk_live_xxxxxxxxxxxxxxxx

What you can build in Cursor with this integration

  • Hotel & hospitality check-in: Let international guests snap a photo of their passport to instantly populate registration cards, speeding up front-desk operations. A perfect fit for travel automation.
  • Airline booking portals: Build a mobile portal where passengers upload their passports during online check-in to automatically capture API (Advance Passenger Information) data.
  • Global KYC onboarding: Create a secure onboarding flow for fintech apps that accepts passports from 150+ countries, extracting structured names and birth dates instantly.
  • Visa application assistants: Add an upload step to a travel agency portal: extract passport details automatically to pre-fill complex international visa application forms.

The prompt and the code

Copy the follow-up prompt into Cursor's Composer (Cmd+I) to generate the integration. The code block shows the standard fetch logic Cursor will likely produce.

Prerequisite: A free StructOCR account — get your API key at structocr.com/dashboard (no credit card required)

I need to add Passport OCR to this application securely.

1. Create a server-side POST route at /api/passport-ocr.
2. The browser should convert the selected image to Base64 and send { img } to this route.
3. The server route must POST application/json to https://api.structocr.com/v1/passport with body { img }.
4. Authenticate upstream with the x-api-key header using process.env.STRUCTOCR_KEY. Never expose this key through NEXT_PUBLIC_ or client-side code.
5. Return the StructOCR JSON response and display data.passport_number, data.surname, data.given_names, data.nationality, and data.date_of_expiry.
6. Add loading, file-size, upstream error, and invalid-response handling.

What the API returns

A comprehensive JSON object containing the parsed passport fields. Cursor can easily type this interface for TypeScript projects.

{
  "success": true,
  "data": {
    "type": "passport",
    "country_code": "USA",
    "nationality": "UNITED STATES",
    "passport_number": "E12345678",
    "surname": "DOE",
    "given_names": "JOHN",
    "sex": "M",
    "date_of_birth": "1990-01-01",
    "place_of_birth": "NEW YORK, USA",
    "date_of_issue": "2020-01-01",
    "date_of_expiry": "2030-01-01",
    "place_of_issue": "PASSPORT AGENCY"
  }
}

Technical Specs

  • Formats accepted: PNG, JPG, WEBP — optimized for smartphone and webcam photos
  • Response time: typically 1–2 seconds per passport
  • Condition handling: robust against glossy page glare, watermarks, and poor lighting
  • Data Privacy: Zero data retention architecture; images are processed in memory and immediately discarded
  • Global coverage: supports all ICAO Doc 9303 compliant passports globally

Key Features

  • MRZ Cross-checking: automatically compares the extracted visual text against the machine-readable zone to ensure absolute accuracy
  • Format validation: automatically verifies passport numbers and expiration dates against checksum rules
  • Multi-angle support: reads passports held at skewed angles or taken in busy backgrounds
  • Auto-cropping: automatically locates and crops the passport data page from the uploaded image

Live Demo: Passport scanner

No registration required. Upload a file to test the extraction.

1
Upload
2
Results

Drop files here or click to browse

JPG · PNG · WebP  ·  up to 500 files · max 4.5 MB each

No files selected

Frequently Asked Questions

Can Cursor generate the integration code for StructOCR?

Yes. StructOCR is a standard REST API. By providing Cursor's Composer with the endpoint and the required fields, it will perfectly write the fetch requests, state management, and error handling in your preferred framework (React, Vue, Svelte, etc.).

Where should I store the API key when building with Cursor?

Store it only in a server-side environment variable named `STRUCTOCR_KEY` and call StructOCR from a backend route. Never use a `NEXT_PUBLIC_` prefix, because Next.js includes those values in browser bundles.

Does StructOCR store the passport photos?

No. StructOCR operates on a strict zero-data-retention policy. Images are processed in memory to extract the JSON data and are instantly discarded, ensuring GDPR and SOC2 compliance.

Can it read passports with heavy glare over the photo?

Yes. Our models are specifically trained to read through glossy lamination glare, security laminates, and poor lighting conditions common in hotel lobbies or airport check-ins.

How can I test the accuracy before writing code?

You can verify the model live using our free passport scanner tool.

Is there a free tier to test with?

Yes. StructOCR's free plan includes 10 scans per month with no credit card required. Check out our pricing page for full details.

More Tutorials

Ready to Build with StructOCR?

Get your API key in under a minute. New users receive 200 free credits to test Passport, VIN, Lincense Plate, Container, Receipt, HIN, Driver License, ID Card, Vehicle Registration, ATM Cassette and Invoice OCR APIs.

✓ No credit card required · ✓ Instant API key · ✓ Full API access