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

Private Document Analysis via L402

Analyze contracts, financial records, legal filings, medical documents, and any sensitive file — without creating an account or leaving a trace. Document text is extracted on your machine and sent as context. It is processed in memory and never stored.

This service uses the text-generation endpoint with the fileContext parameter. Pricing is dynamic based on document length. Best model (recommended for documents): 100 characters/Sat, minimum 15 Sats/request.

API Endpoint: https://sats4ai.com/api/l402/text-generation

Privacy architecture: Extract text from your document locally (client-side or on your machine), then send only the extracted text as fileContext. The original file never leaves your device. No account is created, no document is stored, no identity is recorded. Payment via Lightning is anonymous by default.

Step 0: Extract Text from Your Document

Extract the text content from your file before sending it. For PDFs, use a library like pdfplumber (Python) or pdf-parse (Node.js). For DOCX, use python-docx or mammoth. The extracted text is sent as the fileContext string.

import pdfplumber

with pdfplumber.open("contract.pdf") as pdf:
    text = "\n".join(page.extract_text() for page in pdf.pages)

# Then send text as fileContext in the request body

Step 1: Initial Request (get Invoice)

Send the request with your document text and question. You will receive a 402 Payment Required response with a Lightning invoice priced based on the total character count (prompt + document).

Request body:

{
  "input": [
    {
      "role": "User",
      "content": "Summarize the key obligations and risks in this contract"
    }
  ],
  "model": "Best",
  "fileContext": "<extracted text of your document>",
  "fileName": "contract.pdf"
}

Example curl command:

curl -X POST https://sats4ai.com/api/l402/text-generation \
-H "Content-Type: application/json" \
-d '{"input":[{"role":"User","content":"Summarize the key obligations and risks in this contract"}],"model":"Best","fileContext":"<extracted text of your document>","fileName":"contract.pdf"}' \
-i

Expected response headers:

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

Step 2: Pay the Lightning Invoice

Pay the invoice with any Lightning wallet (Phoenix, Muun, Alby, Wallet of Satoshi, etc.). Save the preimage (proof of payment) your wallet provides after payment.

Step 3: Re-send with Payment Proof

Send the exact same request again with the Authorization header containing your macaroon and preimage.

The JSON payload must be identical to Step 1 — same document text, same question, same model.

curl -X POST https://sats4ai.com/api/l402/text-generation \
-H "Content-Type: application/json" \
-H "Authorization: L402 <YOUR_MACAROON>:<YOUR_PREIMAGE>" \
-d '{"input":[{"role":"User","content":"Summarize the key obligations and risks in this contract"}],"model":"Best","fileContext":"<extracted text of your document>","fileName":"contract.pdf"}'

The response body will contain the AI's analysis of your document as plain text.

Easier: Use lnget

lnget handles the full 3-step flow automatically — invoice, payment, and re-request in one command.

lnget POST https://sats4ai.com/api/l402/text-generation \
  --json '{"input":[{"role":"User","content":"What are the termination clauses?"}],"model":"Best","fileContext":"<document text>","fileName":"contract.pdf"}'

Request Parameters

fileContext: string (required for document analysis)

The extracted text content of your document. Extract this on your machine before sending. Its length is included in the dynamic pricing calculation.

fileName: string (optional)

Original filename. Used as a label in the prompt (e.g., [File: contract.pdf]). Helps the model understand the document type.

input: array of objects

Your question or instruction as a conversation array. At minimum one object with role: "User" and your question as content.

model: string

"Best" is strongly recommended for document analysis — it has a 262K token context window, enough for the longest contracts, reports, and research papers."Standard" is available for shorter documents at lower cost (minimum 5 Sats).

Example Questions

  • Contracts & NDAs: "List all termination clauses and the notice periods required."
  • Financial records: "Identify any liabilities over $100K and summarize the cash flow trend."
  • Legal filings: "What are the plaintiff's core claims and what damages are being sought?"
  • Medical reports: "Summarize the diagnosis and recommended treatment plan."
  • Board documents: "What decisions were made and what action items were assigned?"