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 Face Restoration on the web — pay with any Lightning wallet, no setup needed.
Restore Faces via L402
Restore blurry, damaged, or AI-generated faces to sharp, natural quality. Adjustable fidelity lets you balance between quality enhancement and identity preservation.
API Endpoint: https://sats4ai.com/api/l402/restore-face
Constraints
- Image must be base64-encoded (with or without
data:prefix) - Fidelity: 0.0 (max quality) to 1.0 (max identity preservation), default 0.5
- Optional background enhancement and face upsampling
- 5 sats per image
Step 1: Initial Request (get Invoice)
Send your base64 image and desired fidelity. You will receive a 402 Payment Required response with a Lightning invoice.
Request body:
{
"image": "<base64-encoded-image>",
"fidelity": 0.5
}Example curl command:
curl -X POST https://sats4ai.com/api/l402/restore-face \
-H "Content-Type: application/json" \
-d '{
"image": "<base64-encoded-image>",
"fidelity": 0.5
}' \
-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 (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/restore-face \
-H "Content-Type: application/json" \
-H "Authorization: L402 <YOUR_MACAROON>:<YOUR_PREIMAGE>" \
-d '{
"image": "<base64-encoded-image>",
"fidelity": 0.5
}'Successful response includes image_url (URL to restored image — download promptly).
Easier: Use lnget
lnget handles the full L402 flow automatically — invoice, payment, and re-request in one command.
IMAGE_B64=$(base64 -w0 photo.png)
lnget -X POST https://sats4ai.com/api/l402/restore-face \
--json "{\"image\":\"$IMAGE_B64\",\"fidelity\":0.5}"Python Example
import requests, base64
# Encode image
with open("photo.png", "rb") as f:
image_b64 = base64.b64encode(f.read()).decode()
payload = { "image": image_b64, "fidelity": 0.5 }
# Step 1 — get invoice
r = requests.post("https://sats4ai.com/api/l402/restore-face",
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/restore-face",
json=payload,
headers={
"Content-Type": "application/json",
"Authorization": "L402 <macaroon>:<preimage>"
})
result = r2.json()
print(result["image_url"]) # URL to restored image (download promptly)Request Parameters
image: string required
Base64-encoded image data. Can include the data:image/png;base64, prefix or just the raw base64 string.
fidelity: number (optional)
Balance between quality and identity preservation. 0.0 = maximum quality enhancement, 1.0 = maximum identity preservation. Default: 0.5.
background_enhance: boolean (optional)
Also enhance the background (not just faces).
face_upsample: boolean (optional)
Upsample restored faces for higher resolution output.
upscale: number (optional)
Overall upscale factor for the output image.
modelId: number or string (optional)
Omit for the best default model.
Pricing
5 sats per image.
Use Cases
- Restore old or damaged family photos
- Fix blurry faces in surveillance or security footage
- Improve AI-generated faces that look slightly off
- Enhance portrait photos from low-quality cameras