This site is not affiliated with or endorsed by Vercel, Inc. Read the docs, then deploy or run each experiment yourself.
AI

Receipt to JSON Lab

Turn receipt text or an uploaded image into structured expense JSON with line items - text-only works without vision.

Run this experiment yourself

Demos are not embedded on this site. Deploy a standalone copy on Vercel or run the experiment app locally.

Local development

cd apps/experiments/receipt-to-json-lab
pnpm install
pnpm dev

Then open http://localhost:3010.

This is an experimental demo. Use it as a starting point for your own projects.

Receipt to JSON Lab extracts { merchant, date, currency, total, lineItems[] } from pasted receipt text or an uploaded image. Text-only requests use generateObject with a prompt; images add AI SDK image parts (vision) while still accepting an optional text hint. Download the result as JSON from the demo. Missing keys return 503 - nothing is fabricated.

Features

  • Text or image – paste works without vision; PNG/JPEG/WebP/GIF optional.
  • Structured expense schema – Zod-validated merchant, date, currency, total, line items.
  • Download JSON – client helper writes expense.json.
  • Sample receipt – prefilled ACME Coffee example.
  • Honest 503 when AI Gateway / OpenAI is not configured.

Server Reference

POST /api/receipt

JSON { "text": "..." } or multipart/form-data with text and optional image file (max 4MB).

Success (200)

{
  "merchant": "ACME Coffee",
  "date": "2026-03-15",
  "currency": "USD",
  "total": 12.1,
  "lineItems": [
    { "description": "Latte", "quantity": 1, "unitPrice": 4.5, "total": 4.5 }
  ],
  "provider": "ai-gateway",
  "usedVision": false
}
StatusCause
503No AI provider
400Empty input, bad image type, or oversized file

Implementation Details

Provider gate + truncate

aiProviderAvailable() then truncateText (MAX_RECEIPT_TEXT = 8000).

Text vs vision path

Without an image, the handler uses prompt. With an image, it sends messages with { type: 'text' } and { type: 'image', image, mediaType } so text-only demos never require vision models.

Use Cases

  • Prototype expense ingestion pipelines.
  • Compare text OCR paste vs multimodal extraction.
  • Teach typed generateObject schemas for line items.

Limitations

  • Do not upload sensitive financial documents to public demos.
  • Vision quality depends on image clarity and model support.
  • No auth or rate limiting.
  • Totals are model-inferred; verify before bookkeeping use.

Use in your project

Copy app/api/receipt/route.ts, lib/services.ts, and lib/ai-model.ts. Keep the text-only branch so local demos work without a vision-capable model.

Deployment

Deploy on Vercel

Prompts for AI_GATEWAY_API_KEY.

Local Development

cd apps/experiments/receipt-to-json-lab
pnpm install
pnpm dev

Configuration

VariableRequiredPurpose
AI_GATEWAY_API_KEYYes (or OPENAI_API_KEY)Preferred provider
OPENAI_API_KEYNoFallback
AI_MODELNoModel override

Vercel / Next.js Features Used

  • AI SDK generateObject (text + image parts)
  • Vercel AI Gateway
  • Route Handlers
  • Zod

Next Steps

On this page