L402 API
Pay with Bitcoin, get AI results. Copy-paste the commands below.
Choose a service:
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)
No Account Profile
No account or subscription. We keep minimal payment, delivery, refund, and abuse-prevention records. Providers process inputs when required.
Want to try this without a terminal? Use Image Editing on the web — pay with any Lightning wallet, no setup needed.
Edit Images via L402
Edit images using AI. Describe the changes you want in plain text, and the AI applies them. Returns JSON with the image URL.
Background removal, style transfer, object removal, color changes, and more — describe what you want and get the result. No image editing software needed.
API Endpoint: https://sats4ai.com/api/l402/edit-image
Constraints
- Image must be base64-encoded (with or without
data:prefix) - Output formats:
jpg,png,webp - Aspect ratio options:
match_input_image,1:1,4:3,16:9 - Media URLs expire after 2 hours — download promptly
Step 1: Initial Request (get Invoice)
Send your editing instructions and base64 image. You will receive a 402 Payment Required response with a Lightning invoice.
Request body:
{
"prompt": "Change the jacket to red leather, keep the face and pose unchanged",
"image": "<base64-encoded-image>",
"aspect_ratio": "match_input_image",
"output_format": "png"
}Example curl command:
curl -X POST https://sats4ai.com/api/l402/edit-image \
-H "Content-Type: application/json" \
-d '{
"prompt": "Change the jacket to red leather, keep the face and pose unchanged",
"image": "<base64-encoded-image>",
"aspect_ratio": "match_input_image",
"output_format": "png"
}' \
-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/edit-image \
-H "Content-Type: application/json" \
-H "Authorization: L402 <YOUR_MACAROON>:<YOUR_PREIMAGE>" \
-d '{
"prompt": "Change the jacket to red leather, keep the face and pose unchanged",
"image": "<base64-encoded-image>",
"aspect_ratio": "match_input_image",
"output_format": "png"
}'Successful response includes image_url (URL to edited image — download promptly).
Easier: Use lnget
lnget handles the full L402 flow automatically — invoice, payment, and re-request in one command.
# Encode your image first
IMAGE_B64=$(base64 -w0 photo.png)
lnget -X POST https://sats4ai.com/api/l402/edit-image \
--json "{\"prompt\":\"Remove the parked car on the left, keep everything else as it is\",\"image\":\"$IMAGE_B64\",\"output_format\":\"png\"}"Python Example
import requests, base64
# Encode image
with open("photo.png", "rb") as f:
image_b64 = base64.b64encode(f.read()).decode()
payload = {
"prompt": "Change the jacket to red leather, keep the face and pose unchanged",
"image": image_b64,
"aspect_ratio": "match_input_image",
"output_format": "png"
}
# Step 1 — get invoice
r = requests.post("https://sats4ai.com/api/l402/edit-image",
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/edit-image",
json=payload,
headers={
"Content-Type": "application/json",
"Authorization": "L402 <macaroon>:<preimage>"
})
result = r2.json()
print(result["image_url"]) # URL to edited image (download promptly)Request Parameters
prompt: string required
Editing instructions describing what to change. Be specific: "Remove the background" or "Change the sky to sunset orange".
image: string required
Base64-encoded image data. Can include the data:image/png;base64, prefix or just the raw base64 string.
aspect_ratio: string (optional)
Output aspect ratio. Options: "match_input_image" (default), "1:1", "4:3", "16:9".
output_format: string (optional)
Output image format. Options: "jpg" (default), "png", "webp".
resolution: string (optional)
Output resolution. Options: "1K" (1024px, default), "2K" (2048px), "4K" (4096px). Price varies by resolution.
modelId: number or string (optional)
Omit for the best default model.
Pricing
Resolution-tiered pricing:
| Output | Price |
|---|---|
| Any output size | 200 sats |
Use Cases
- Replace image backgrounds for product photos
- Apply style transfers or artistic effects to photos
- Remove unwanted objects from images
- Batch-edit images via script or agent without manual editing tools
- Need a genuine transparent cutout? Use remove-background — this endpoint returns an opaque image even with
output_format: png