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 Object Detection on the web — pay with any Lightning wallet, no setup needed.
Object Detection via L402
Detect and locate objects in images by name. Describe what to find in natural language and get bounding box coordinates with confidence scores. Returns structured JSON that agents can act on directly.
API Endpoint: https://sats4ai.com/api/l402/detect-objects
Constraints
- Image must be base64-encoded (with or without
data:prefix) queryis required — comma-separated object names- Returns JSON with bounding boxes as
[x1, y1, x2, y2]pixel coordinates - 5 sats per image
Step 1: Initial Request (get Invoice)
Send your base64 image and query. You will receive a 402 Payment Required response with a Lightning invoice.
Request body:
{
"image": "<base64-encoded-image>",
"query": "cat, dog, person"
}Example curl command:
curl -X POST https://sats4ai.com/api/l402/detect-objects \
-H "Content-Type: application/json" \
-d '{
"image": "<base64-encoded-image>",
"query": "cat, dog, person"
}' \
-iStep 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
curl -X POST https://sats4ai.com/api/l402/detect-objects \
-H "Content-Type: application/json" \
-H "Authorization: L402 <YOUR_MACAROON>:<YOUR_PREIMAGE>" \
-d '{
"image": "<base64-encoded-image>",
"query": "cat, dog, person"
}'Example response:
{
"detections": [
{ "label": "cat", "confidence": 0.92, "bbox": [120, 45, 340, 280] },
{ "label": "person", "confidence": 0.87, "bbox": [400, 30, 550, 410] }
]
}Easier: Use lnget
lnget handles the full L402 flow automatically.
IMAGE_B64=$(base64 -w0 photo.png)
lnget -X POST https://sats4ai.com/api/l402/detect-objects \
--json "{\"image\":\"$IMAGE_B64\",\"query\":\"cat, dog, person\"}"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,
"query": "cat, dog, person",
"box_threshold": 0.25, # optional
"text_threshold": 0.25 # optional
}
# Step 1 — get invoice
r = requests.post("https://sats4ai.com/api/l402/detect-objects",
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/detect-objects",
json=payload,
headers={
"Content-Type": "application/json",
"Authorization": "L402 <macaroon>:<preimage>"
})
result = r2.json()
for det in result["detections"]:
print(f"{det['label']}: {det['confidence']:.2f} at {det['bbox']}")Request Parameters
image: string required
Base64-encoded image data.
query: string required
Comma-separated names of objects to detect (e.g. "cat, dog, person").
box_threshold: number (optional, default 0.25)
Confidence threshold for detection boxes (0-1). Lower = more detections, higher = fewer but more confident.
text_threshold: number (optional, default 0.25)
Confidence threshold for text-to-region matching (0-1).
Pricing
5 sats per image.
Use Cases
- Count specific objects in images (inventory, wildlife surveys)
- Locate elements for downstream cropping or masking
- Quality assurance — verify expected objects are present
- Agent workflows that need structured spatial data from images