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 SMS Messaging on the web — pay with any Lightning wallet, no setup needed.
Using the L402 SMS Sending API
You can send an SMS by sending a POST request to our L402-protected SMS endpoint. Follow the steps below, which include example `curl` commands.
API Endpoint: https://sats4ai.com/api/l402/send-sms
Step 1: Initial Request (to get Macaroon and Invoice)
First, make a request to the API with your desired SMS parameters (phone number and message). This initial request will not send the SMS yet; instead, it will return a 402 Payment Required status along with the L402 headers (a macaroon and a Lightning invoice).
Example `curl` command:
curl -X POST https://sats4ai.com/api/l402/send-sms \
-H "Content-Type: application/json" \
-d '{"phone_number":"+1234567890","message":"Hello, this is a test SMS!"}' \
-iExplanation of the command:
-X POST: Specifies an HTTP POST request.https://sats4ai.com/api/l402/send-sms: The target API URL for sending SMS.-H "Content-Type: application/json": Indicates the request body is JSON.-d '{...}': The JSON data payload with your SMS details (see "Request Body Parameters" below).-i: Tells `curl` to include HTTP response headers in the output (so you can see thewww-authenticateheader).
Expected Response Headers:
You will receive an HTTP/1.1 402 Payment Required response. Look for the www-authenticate header:
www-authenticate: L402 macaroon="<YOUR_MACAROON_STRING_HERE>", invoice="<YOUR_LIGHTNING_INVOICE_HERE>"<YOUR_MACAROON_STRING_HERE>: Your unique access token (the "ticket" for this specific SMS request).<YOUR_LIGHTNING_INVOICE_HERE>: The Lightning Network invoice you need to pay to send the SMS.
Step 2: Pay the Lightning Invoice
Copy the <YOUR_LIGHTNING_INVOICE_HERE> string and pay it using any Lightning-enabled Bitcoin wallet. Upon successful payment, your wallet will provide you with a preimage. The preimage is your cryptographic proof of payment.
Step 3: Final Request (to Send the SMS)
Once you have the macaroon (from Step 1) and the preimage (from Step 2), make the exact same POST request again. This time, include an Authorization header containing both.
Important: The JSON data payload (-d '{...}') in this second request must be identical to the one sent in Step 1.
Example `curl` command:
curl -X POST https://sats4ai.com/api/l402/send-sms \
-H "Content-Type: application/json" \
-H "Authorization: L402 <YOUR_MACAROON_STRING_HERE>:<YOUR_PREIMAGE_HERE>" \
-d '{"phone_number":"+1234567890","message":"Hello, this is a test SMS!"}'Explanation of changes:
- Replace
<YOUR_MACAROON_STRING_HERE>with the actual macaroon from Step 1. - Replace
<YOUR_PREIMAGE_HERE>with the actual preimage from Step 2. - The
-H "Authorization: L402 <macaroon>:<preimage>"header is added to authorize the SMS sending.
Expected Successful Response:
If the L402 authentication is valid, the API will process your request and attempt to send the SMS. You should receive a success response, typically a JSON object confirming the submission:
OkayNote: The exact success response format may vary. Check the API provider's documentation for specific details.
Request Body Parameters
The POST request body should be a JSON object with the following structure:
{
"phone_number": "+1234567890",
"message": "Hello, this is a test SMS!"
}phone_number: string
The recipient's phone number in E.164 international format.
Example: "+1234567890"
message: string
The content of the SMS text message.
Maximum length: 120 characters.
Example: "Hello, this is a test SMS!"