# Receipt OCR with Mistral OCR and Vercel AI SDK

> Implementation pattern for structured receipt extraction using Mistral and Vercel AI SDK

A practical code recipe showing how to parse receipt images into typed, structured JSON using Mistral's vision models and the Vercel AI SDK. It demonstrates how to combine schema-based generation (\`generateObject\`) with custom retry logic and timeout handling. It is pulled directly from Midday's open-source document processing pipeline.

## How it works

The best OCR for extracting structured receipt data: Mistral OCR + Vercel AI SDK — insanely cheap.

Code (packages/documents/src/processors/receipt-processor.ts):

- Imports: mistral from '@ai-sdk/mistral', generateObject from 'ai', receiptPrompt, receiptSchema, GetDocumentRequest type, retryCall util.

- ReceiptProcessor class with \#processDocument({ documentUrl }: GetDocumentRequest): throws if no documentUrl; calls retryCall(() =\> generateObject({ model: mistral('mistral-medium-latest'), schema: receiptSchema, abortSignal: AbortSignal.timeout(20000) (20s), messages: \[{ role: 'system', content: receiptPrompt }, { role: 'user', content: \[{ type: 'image', image: documentUrl }\] }\], providerOptions: { mistral: { documentImageLimit: 4 } } })); returns result.object.

- getReceipt(params: GetDocumentRequest): returns { ...result, type: 'expense', date: result.date, amount: result.total\_amount, currency: result.currency, name: result.store\_name, tax\_amount: result.tax\_amount, tax\_rate: result.tax\_rate, tax\_type: result.tax\_type, language: result.language, metadata: { register\_number: result.register\_number ?? null, cashier\_name: result.cashier\_name ?? null, email: result.email ?? null } }.

Follow-up in thread: 'code here https://github.com/midday-ai/midday' (Invoicing, Time tracking, File reconciliation, Storage, Financial Overview & Assistant for Freelancers).

## What it is for

- Extract structured transaction data from receipt images into a database
- Implement reliable LLM API calls with retry wrappers and timeout abort signals
- Build automated expense tracking and invoice processing workflows

## Key points

- Uses Vercel AI SDK's generateObject for strictly typed JSON output
- Integrates Mistral vision models via @ai-sdk/mistral
- Includes retry logic and timeout abort signals for resilient API calls
- Normalizes receipt fields including tax rate, total amount, currency, and store metadata

## Pricing

Open source

## Details

- Type: Tip
- Category: [Development](https://xiry.app/topics/development.md)
- Open source: yes
- Platforms: Code library
- For: TypeScript and AI application developers building financial or expense-tracking tools
- Alternative to: Tesseract OCR, AWS Textract, Google Cloud Document AI
- Tags: ocr, mistral, vercel ai sdk, typescript, receipts, ai

## Why it was saved

- [@pontusab, 10 August 2025](https://x.com/pontusab/status/1954436470057427181): Declares Mistral OCR the best and 'insanely cheap' option for structured receipt extraction, and the code is copy-pasteable: it parses receipt images into typed fields (date, amount, currency, store name, tax, language, metadata).

## Related

- [Fred Rivett's Frontend and AI Dev Stack](https://xiry.app/resources/fred-rivett-s-frontend-and-ai-dev-stack): Curated modern frontend and AI product development stack recommendations. (List, Free)
- [Minimal Web-Connected AI Agent in TypeScript](https://xiry.app/resources/minimal-web-connected-ai-agent-in-typescript): TypeScript snippet to build a web-searching agent using Vercel AI SDK and Exa (Tip, Free)
- [Starter.diy](https://xiry.app/resources/starter-diy-2164): Full-stack SaaS starter with Next.js 15, Convex, and Clerk Billing (GitHub repo, Open source)
- [v0 by Vercel](https://xiry.app/resources/v0-by-vercel): AI assistant to generate and iterate on web user interfaces and apps (Web app, Freemium)
- ["Easy Mode" Open Source AI Stack](https://xiry.app/resources/easy-mode-open-source-ai-stack): An opinionated reference architecture for building full-stack open-source AI applications (Framework, Open source)
- [@json-render/react-pdf](https://xiry.app/resources/json-render-react-pdf): Render structured JSON specifications into PDFs using React PDF (GitHub repo, Open source)

Updated 11 October 2026. Page: https://xiry.app/resources/receipt-ocr-with-mistral-ocr-and-vercel-ai-sdk

Make your own library: Xiry takes your saved reels, tweets, Reddit bookmarks and Watch Later videos, makes them searchable and pulls the useful stuff out, like this library. It's invite-only for now; join the waitlist at https://xiry.app/#waitlist.
