L402 API
Pay with Bitcoin, get AI results. Copy-paste the commands below.
Choose a service:
Before You Start
Lightning Wallet
Phoenix, Muun, Wallet of Satoshi, Alby, or any LN wallet
Terminal or Tool
A command line, Postman, or lnget (recommended)
Private & No Signup
No account, no subscription, no personal data. Pay only when you use it
Receipt OCR (Structured Data) via L402
Extract structured data from receipts, invoices, and financial documents. Returns JSON with merchant info, line items, totals, tax, currency, and category.50 sats per page (multi-page PDFs charged per page, single images = 1 page).
Two-stage pipeline: first extracts raw text via OCR, then uses AI to parse it into a clean JSON structure. Privacy-preserving: no data is stored after processing.
API Endpoint: https://sats4ai.com/api/l402/receipt-ocr
Constraints
- Supports images (JPEG, PNG, WEBP) and PDFs
- Document must be base64-encoded (with or without data URI prefix)
- Returns both structured JSON and raw OCR text
- Categories: food, groceries, transport, utilities, medical, retail, services, entertainment, other
Example Response
{
"structured": {
"merchant": {
"name": "Whole Foods Market",
"address": "123 Main St, Austin TX",
"phone": "(512) 555-0100",
"website": null
},
"date": "2026-03-14",
"time": "14:32",
"items": [
{
"description": "Organic Bananas",
"quantity": 1,
"unitPrice": 1.99,
"total": 1.99
},
{
"description": "Almond Milk 64oz",
"quantity": 2,
"unitPrice": 4.49,
"total": 8.98
},
{
"description": "Sourdough Bread",
"quantity": 1,
"unitPrice": 5.99,
"total": 5.99
}
],
"subtotal": 16.96,
"tax": 0.85,
"taxRate": "5%",
"tip": null,
"total": 17.81,
"currency": "USD",
"paymentMethod": "Visa ending 4242",
"invoiceNumber": null,
"category": "groceries"
},
"rawText": "WHOLE FOODS MARKET\n123 Main St, Austin TX\n..."
}Step 1: Initial Request (get Invoice)
Send your base64-encoded receipt. You will receive a 402 Payment Required response with a Lightning invoice for 50 sats per page.
Request body:
{
"document": "data:image/jpeg;base64,<your-receipt-image>"
}Example curl command:
# Encode your receipt image
RECEIPT=$(base64 -w0 receipt.jpg)
curl -X POST https://sats4ai.com/api/l402/receipt-ocr \
-H "Content-Type: application/json" \
-d "{\"document\":\"data:image/jpeg;base64,$RECEIPT\"}" \
-iStep 2: Pay the Lightning Invoice
Pay the 50-sat invoice with any Lightning wallet. Save the preimage your wallet provides after payment.
Step 3: Re-send with Payment Proof
Send the exact same request again with the Authorization header.
The JSON payload must be identical to Step 1.
curl -X POST https://sats4ai.com/api/l402/receipt-ocr \
-H "Content-Type: application/json" \
-H "Authorization: L402 <YOUR_MACAROON>:<YOUR_PREIMAGE>" \
-d "{\"document\":\"data:image/jpeg;base64,$RECEIPT\"}"Easier: Use lnget
RECEIPT=$(base64 -w0 receipt.jpg)
lnget POST https://sats4ai.com/api/l402/receipt-ocr \
--json "{\"document\":\"data:image/jpeg;base64,$RECEIPT\"}"Python Example
import requests, base64
# Encode receipt image
with open("receipt.jpg", "rb") as f:
img_b64 = base64.b64encode(f.read()).decode()
payload = {
"document": f"data:image/jpeg;base64,{img_b64}"
}
# Step 1 — get invoice
r = requests.post("https://sats4ai.com/api/l402/receipt-ocr",
json=payload,
headers={"Content-Type": "application/json"})
# r.status_code == 402
# Parse macaroon and invoice from r.headers["www-authenticate"]
# Step 2 — pay invoice with your Lightning wallet, get preimage
# Step 3 — re-send with auth
r2 = requests.post("https://sats4ai.com/api/l402/receipt-ocr",
json=payload,
headers={
"Content-Type": "application/json",
"Authorization": "L402 <macaroon>:<preimage>"
})
result = r2.json()
data = result["structured"]
print(f"Merchant: {data['merchant']['name']}")
print(f"Total: {data['currency']} {data['total']}")
print(f"Category: {data['category']}")
for item in data["items"]:
print(f" - {item['description']}: {item['total']}")Request Parameters
document: string required
Base64-encoded receipt, invoice, or financial document. Can include a data URI prefix (e.g., data:image/jpeg;base64,...) or be raw base64.
Response Fields
| Field | Type | Description |
|---|---|---|
| merchant | object | name, address, phone, website |
| date | string | Transaction date |
| items | array | Line items with description, quantity, unitPrice, total |
| subtotal | number | Pre-tax total |
| tax | number | Tax amount |
| total | number | Final total |
| currency | string | Detected currency (e.g., USD, EUR) |
| category | string | Expense category |
| rawText | string | Raw OCR text (always included) |
Use Cases
- Expense tracking: snap a receipt, get structured data for your spreadsheet
- Accounting automation: extract invoice data without manual entry
- AI agents processing financial documents
- Tax preparation: categorize and total expenses from receipt photos
- Privacy-sensitive financial document processing (no data stored)