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
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
Edit Images via L402
Edit images using AI. Describe the changes you want in plain text, and the AI applies them. Returns both a URL and a base64-encoded version of the edited image.
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/image-edit
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": "Remove the background and make it transparent",
"image": "<base64-encoded-image>",
"aspect_ratio": "match_input_image",
"output_format": "png"
}Example curl command:
curl -X POST https://sats4ai.com/api/l402/image-edit \
-H "Content-Type: application/json" \
-d '{
"prompt": "Remove the background and make it transparent",
"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/image-edit \
-H "Content-Type: application/json" \
-H "Authorization: L402 <YOUR_MACAROON>:<YOUR_PREIMAGE>" \
-d '{
"prompt": "Remove the background and make it transparent",
"image": "<base64-encoded-image>",
"aspect_ratio": "match_input_image",
"output_format": "png"
}'Successful response includes imageUrl (hosted URL) and base64Image (data URI).
Easier: Use lnget
# Encode your image first
IMAGE_B64=$(base64 -w0 photo.png)
lnget POST https://sats4ai.com/api/l402/image-edit \
--json "{\"prompt\":\"Make the sky sunset orange\",\"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": "Remove the background and make it transparent",
"image": image_b64,
"aspect_ratio": "match_input_image",
"output_format": "png"
}
# Step 1 — get invoice
r = requests.post("https://sats4ai.com/api/l402/image-edit",
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/image-edit",
json=payload,
headers={
"Content-Type": "application/json",
"Authorization": "L402 <macaroon>:<preimage>"
})
result = r2.json()
print(result["imageUrl"]) # URL to edited image
print(result["base64Image"]) # base64 data URI of edited imageRequest 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".
modelId: number or string (optional)
Omit for the best default model.
Use Cases
- Remove or 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
- Generate transparent PNGs for design workflows