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

HTML/Markdown to PDF via L402

Convert HTML or Markdown content into a downloadable PDF document. Flat rate: 50 sats per conversion.

Useful for generating invoices, reports, contracts, or any formatted document from code — without installing wkhtmltopdf, puppeteer, or other PDF libraries.

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

Constraints

  • Supports HTML and Markdown input formats
  • CSS styling is supported in HTML (inline or in <style> tags)
  • Output is always PDF
  • Download URL expires after 24 hours

Example: HTML Input

{
  "html": "<h1>Invoice #1234</h1><p>Amount: $500.00</p><table><tr><th>Item</th><th>Price</th></tr><tr><td>Consulting</td><td>$500</td></tr></table>",
  "format": "html"
}

Example: Markdown Input

{
  "html": "# Invoice #1234\n\nAmount: **$500.00**\n\n| Item | Price |\n|------|-------|\n| Consulting | $500 |",
  "format": "markdown"
}

Step 1: Initial Request (get Invoice)

Send your content. You will receive a 402 Payment Required response with a Lightning invoice for 50 sats.

curl -X POST https://sats4ai.com/api/l402/html-to-pdf \
-H "Content-Type: application/json" \
-d '{
  "html": "<h1>Hello World</h1><p>My PDF content</p>",
  "format": "html"
}' \
-i

Expected response headers:

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

Step 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/html-to-pdf \
-H "Content-Type: application/json" \
-H "Authorization: L402 <YOUR_MACAROON>:<YOUR_PREIMAGE>" \
-d '{
  "html": "<h1>Hello World</h1><p>My PDF content</p>",
  "format": "html"
}'

Successful response: {"url": "https://...", "fileName": "document.pdf"}

Easier: Use lnget

# HTML to PDF
lnget POST https://sats4ai.com/api/l402/html-to-pdf \
  --json '{"html":"<h1>Report</h1><p>Generated at $(date)</p>","format":"html"}'

# Markdown to PDF
lnget POST https://sats4ai.com/api/l402/html-to-pdf \
  --json '{"html":"# Report\nGenerated dynamically","format":"markdown"}'

Python Example

import requests

html_content = """
<html>
<head><style>body { font-family: Arial; } table { border-collapse: collapse; width: 100%; }
th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }</style></head>
<body>
  <h1>Invoice #1234</h1>
  <p>Date: 2026-03-14</p>
  <table>
    <tr><th>Item</th><th>Qty</th><th>Price</th></tr>
    <tr><td>API Consulting</td><td>10 hrs</td><td>$1,500</td></tr>
    <tr><td>Setup Fee</td><td>1</td><td>$200</td></tr>
  </table>
  <p><strong>Total: $1,700</strong></p>
</body>
</html>
"""

payload = {"html": html_content, "format": "html"}

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

Request Parameters

html: string required

The HTML or Markdown content to convert to PDF.

format: string optional, default: "html"

Input format: "html" or "markdown".

Use Cases

  • AI agents generating invoices or receipts as PDFs
  • Convert Markdown documentation to printable PDFs
  • Generate styled reports from HTML templates
  • Create contracts or agreements from structured data
  • One-off PDF generation without installing libraries