Skip to main content

L402 API

Pay with Bitcoin, get AI results. Copy-paste the commands below.

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

Merge PDFs via L402

Merge multiple PDF files into a single document. Send base64-encoded PDFs and get back a download URL for the merged result. Flat rate: 100 sats per merge.

Useful for combining invoices, contracts, reports, or any set of PDFs into one file — without installing software or creating accounts with document processing services.

API Endpoint: https://sats4ai.com/api/l402/pdf-merge

Constraints

  • Minimum 2 PDF files required
  • Each file must be base64-encoded
  • Output is a single merged PDF
  • Download URL expires after 2 hours

Step 1: Initial Request (get Invoice)

Send your base64-encoded PDF files. You will receive a 402 Payment Required response with a Lightning invoice for 100 sats.

Request body:

{
  "files": [
    "<base64-encoded-pdf-1>",
    "<base64-encoded-pdf-2>",
    "<base64-encoded-pdf-3>"
  ]
}

Example curl command:

curl -X POST https://sats4ai.com/api/l402/pdf-merge \
-H "Content-Type: application/json" \
-d '{
  "files": ["<base64-pdf-1>", "<base64-pdf-2>"]
}' \
-i

Expected response headers:

www-authenticate: L402 macaroon="<YOUR_MACAROON>", invoice="<LIGHTNING_INVOICE>"

Step 2: Pay the Lightning Invoice

Pay the 100-sat invoice with any Lightning wallet (Phoenix, Muun, Alby, Wallet of Satoshi, etc.). 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/pdf-merge \
-H "Content-Type: application/json" \
-H "Authorization: L402 <YOUR_MACAROON>:<YOUR_PREIMAGE>" \
-d '{
  "files": ["<base64-pdf-1>", "<base64-pdf-2>"]
}'

Successful response: {"success": true, "url": "https://...", "fileName": "merged.pdf"}

Easier: Use lnget

# Encode PDFs to base64
PDF1=$(base64 -w0 document1.pdf)
PDF2=$(base64 -w0 document2.pdf)

lnget POST https://sats4ai.com/api/l402/pdf-merge \
  --json "{\"files\":[\"$PDF1\",\"$PDF2\"]}"

Python Example

import requests, base64

# Encode PDF files
def encode_pdf(path):
    with open(path, "rb") as f:
        return base64.b64encode(f.read()).decode()

payload = {
    "files": [encode_pdf("doc1.pdf"), encode_pdf("doc2.pdf"), encode_pdf("doc3.pdf")]
}

# Step 1 — get invoice
r = requests.post("https://sats4ai.com/api/l402/pdf-merge",
    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/pdf-merge",
    json=payload,
    headers={
        "Content-Type": "application/json",
        "Authorization": "L402 <macaroon>:<preimage>"
    })
result = r2.json()
print(result["url"])       # URL to merged PDF
print(result["fileName"])  # e.g. "merged.pdf"

Request Parameters

files: string[] required

Array of base64-encoded PDF files to merge. Minimum 2 files. Files are merged in the order provided.

Use Cases

  • Combine multiple invoice PDFs into a single document for accounting
  • Merge contract pages or addendums into one file
  • Agents that generate reports from multiple sources and need a unified output
  • Batch document assembly without desktop software
  • One-off PDF merges without installing tools or creating service accounts