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 Text Translation on the web — pay with any Lightning wallet, no setup needed.

Document Translation via L402

Translate text across 119 languages with ultra-fast inference. Dynamic pricing based on text length: 1,000 characters per sat, minimum 4 sats.

Privacy-preserving: no data is stored after processing. Ideal for translating legal documents, medical records, contracts, or any sensitive text without uploading to third-party translation services.

API Endpoint: https://sats4ai.com/api/l402/translate-text

Supported Languages

119 languages supported including English, Spanish, French, German, Portuguese, Italian, Dutch, Russian, Chinese, Japanese, Korean, Arabic, Hindi, Turkish, Polish, Swedish, Norwegian, Danish, Finnish, Czech, Romanian, Hungarian, Ukrainian, Greek, Thai, Vietnamese, Indonesian, Malay, Hebrew, Farsi, Bengali, Tamil, Urdu, Swahili, Filipino, Georgian, Armenian, Azerbaijani, Kazakh, Icelandic, Welsh, Basque, and many more.

Source language is auto-detected if not specified.

Example request body:

{
  "text": "The patient reported persistent headaches over the past two weeks, with no improvement from over-the-counter medication.",
  "targetLanguage": "Spanish",
  "sourceLanguage": "English"
}

Step 1: Initial Request (get Invoice)

Send your text. You will receive a 402 Payment Required response with a Lightning invoice priced by text length.

curl -X POST https://sats4ai.com/api/l402/translate-text \
-H "Content-Type: application/json" \
-d '{
  "text": "Hello, how are you today?",
  "targetLanguage": "French"
}' \
-i

Expected response headers:

www-authenticate: L402 macaroon="<YOUR_MACAROON>", invoice="<LIGHTNING_INVOICE>"

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

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/translate-text \
-H "Content-Type: application/json" \
-H "Authorization: L402 <YOUR_MACAROON>:<YOUR_PREIMAGE>" \
-d '{
  "text": "Hello, how are you today?",
  "targetLanguage": "French"
}'

Successful response: {"translatedText": "...", "sourceLanguage": "English", "targetLanguage": "French"}

Easier: Use lnget

lnget handles the full L402 flow automatically — invoice, payment, and re-request in one command.

lnget -X POST https://sats4ai.com/api/l402/translate-text \
  --json '{"text":"Hello, how are you?","targetLanguage":"Japanese"}'

Python Example

import requests

payload = {
    "text": "The contract shall be governed by the laws of the State of New York.",
    "targetLanguage": "German",
    "sourceLanguage": "English"  # optional — auto-detected if omitted
}

# Step 1 — get invoice
r = requests.post("https://sats4ai.com/api/l402/translate-text",
    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/translate-text",
    json=payload,
    headers={
        "Content-Type": "application/json",
        "Authorization": "L402 <macaroon>:<preimage>"
    })
result = r2.json()
print(result["translatedText"])
print(result["targetLanguage"])   # "German"
print(result["sourceLanguage"])   # "English"

Request Parameters

text: string required

The text to translate. Can be any length.

targetLanguage: string required

The language to translate to (e.g., "Spanish", "French", "Japanese").

sourceLanguage: string optional

The source language. Auto-detected if omitted.

modelId: number optional

AI model ID. Can be omitted — the translation model is selected automatically.

Use Cases

  • Translate legal contracts or medical documents without uploading to cloud services
  • AI agents that need to communicate across languages
  • Translate user-generated content for multilingual apps
  • Privacy-sensitive document translation (no data stored)
  • Batch translation of product descriptions or support articles