Solutions/Paid APIs (L402)
Paid APIs (L402)
Use your Phoenixd node as the payment backend for an API that charges for data, content, or compute.
Implement the L402 payment and access layer in your application or compatible middleware, using your node to create Lightning invoices.
How L402 works
- A client requests a protected resource.
- Your application returns HTTP
402 Payment Requiredwith a Lightning invoice and a credential, typically a macaroon, bound to the invoice's payment hash. - The client pays the invoice and obtains the payment preimage.
- The client retries with the credential and preimage. Your application validates both before granting access.
Your application defines pricing, credential expiry, and the resources or usage each payment unlocks.
Build with your node
Connect your backend to your Phoenixd node to create invoices. Add middleware that issues L402 challenges, signs credentials, and verifies the client's proof of payment.
Keep node credentials and credential signing keys on your server. Clients receive the invoice and access credential.
Learn more
- L402 protocol overview
- Phoenixd HTTP API
- toll-booth, an example of L402 middleware with a Phoenixd backend. Verify compatibility with your node and application before integrating it.