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. Agents: CLW

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

Want to try this without a terminal? Use Photo Colorization on the web — pay with any Lightning wallet, no setup needed.

Photo Colorization via L402

Colorize black-and-white or grayscale photos using AI. Produces vivid, natural colorization that text/vision LLMs cannot do. Uses DDColor (dual-decoder, ICCV 2023).

API Endpoint: https://sats4ai.com/api/l402/colorize-image

Constraints

  • Image must be base64-encoded (with or without data: prefix)
  • Best results with grayscale or black-and-white input
  • Returns JSON with image URL
  • 5 sats per image

Step 1: Initial Request (get Invoice)

Send your base64 image. You will receive a 402 Payment Required response with a Lightning invoice.

Request body:

{
  "image": "<base64-encoded-grayscale-image>"
}

Example curl command:

curl -X POST https://sats4ai.com/api/l402/colorize-image \
-H "Content-Type: application/json" \
-d '{
  "image": "<base64-encoded-grayscale-image>"
}' \
-i

Step 2: Pay the Lightning Invoice

Pay the invoice with any Lightning wallet. Save the preimage your wallet provides after payment.

Step 3: Re-send with Payment Proof

The JSON payload must be identical to Step 1.

curl -X POST https://sats4ai.com/api/l402/colorize-image \
-H "Content-Type: application/json" \
-H "Authorization: L402 <YOUR_MACAROON>:<YOUR_PREIMAGE>" \
-d '{
  "image": "<base64-encoded-grayscale-image>"
}'

Successful response includes image_url (URL to colorized image — download promptly).

Easier: Use lnget

lnget handles the full L402 flow automatically.

IMAGE_B64=$(base64 -w0 old_photo.png)

lnget -X POST https://sats4ai.com/api/l402/colorize-image \
  --json "{\"image\":\"$IMAGE_B64\"}"

Python Example

import requests, base64

# Encode grayscale image
with open("old_photo.png", "rb") as f:
    image_b64 = base64.b64encode(f.read()).decode()

payload = {
    "image": image_b64,
    "model_size": "large"  # optional: "large" (best) or "tiny" (faster)
}

# Step 1 — get invoice
r = requests.post("https://sats4ai.com/api/l402/colorize-image",
    json=payload,
    headers={"Content-Type": "application/json"})

# Step 2 — pay invoice with your Lightning wallet, get preimage

# Step 3 — re-send with auth
r2 = requests.post("https://sats4ai.com/api/l402/colorize-image",
    json=payload,
    headers={
        "Content-Type": "application/json",
        "Authorization": "L402 <macaroon>:<preimage>"
    })
result = r2.json()
print(result["image_url"])  # URL to colorized image (download promptly)

Request Parameters

image: string required

Base64-encoded grayscale or black-and-white image.

model_size: string (optional, default "large")

Model variant: "large" for best quality or "tiny" for faster processing.

Pricing

5 sats per image.

Use Cases

  • Restore old family photos with realistic color
  • Colorize historical or archival images
  • Add color to grayscale medical or satellite imagery
  • Batch-colorize photo collections via script or agent