L402 API
Pay with Bitcoin, get AI results. Copy-paste the commands below.
Choose a service:
Before You Start
Want to try this without a terminal? Use Document Extraction on the web — pay with any Lightning wallet, no setup needed.
Using the L402 OCR API
Extract text from PDFs, images, and scanned documents. Returns clean Markdown with tables, headers, and formatting preserved.
Price: 10 Sats per page · Supported formats: PDF, PNG, JPEG, TIFF, WebP, BMP
API Endpoint: https://sats4ai.com/api/l402/extract-document
Quickest: Use lnget
lnget handles the full L402 flow automatically — one command, payment included.
# Extract text from a PDF (easiest method)
DOC=$(base64 -w0 invoice.pdf)
lnget -X POST https://sats4ai.com/api/l402/extract-document \
-H "Content-Type: application/json" \
-d "{\"document\": \"data:application/pdf;base64,$DOC\"}"Step 1: Initial Request
Send the document as a base64 data URI. You will receive a 402 Payment Required response.
curl -X POST https://sats4ai.com/api/l402/extract-document \
-H "Content-Type: application/json" \
-d '{
"document": "data:application/pdf;base64,JVBERi0xLjQg..."
}' \
-iExpected Response Headers:
www-authenticate: L402 macaroon="<YOUR_MACAROON>", invoice="<LIGHTNING_INVOICE>"Step 2: Pay the Lightning Invoice
Pay the invoice with any Lightning wallet and save the preimage (proof of payment).
Step 3: Final Request
Send the exact same request with the Authorization header.
Important: The JSON payload must be identical to Step 1.
curl -X POST https://sats4ai.com/api/l402/extract-document \
-H "Content-Type: application/json" \
-H "Authorization: L402 <YOUR_MACAROON_STRING_HERE>:<YOUR_PREIMAGE_HERE>" \
-d '{
"document": "data:application/pdf;base64,JVBERi0xLjQg..."
}'Expected Successful Response:
{
"content": "# Invoice\n\n| Item | Price |\n|------|-------|\n| Widget | $9.99 |\n\nThank you for your purchase.",
"pages": 1
}Request Body Parameters
document: string (required)
Base64-encoded document as a data URI. Use data:application/pdf;base64,... for PDFs or data:image/png;base64,... for images. If no prefix is provided, PDF is assumed.
modelId: number or string (optional)
Omit for the best default model. See available models.
Response Format
content: Extracted text in Markdown format. Tables are rendered as Markdown tables, headers preserved, page breaks marked with ---.
pages: Number of pages processed.