Go client library for L402 (HTTP 402 Payment Required with Lightning Network) - pay-per-request APIs
l402-go is an early-stage Go project in the AI payments / x402 ecosystem, focused on api, bitcoin, go, golang. It currently has 0 GitHub stars and 0 forks, and sits alongside related tools like l402-js, routeweiler-python-sdk, lightning-wallet-mcp, boltzpay, squidbay, toll-booth.
A Go client library for L402 (HTTP 402 Payment Required with Lightning).
L402 is a payment protocol that enables pay-per-request APIs using Lightning Network:
go get github.com/joelklabo/l402-go
package main
import (
"context"
"fmt"
"net/http"
"github.com/joelklabo/l402-go"
)
func main() {
// Make initial request
resp, err := http.Get("https://example.com/api/paid-endpoint")
if err != nil {
panic(err)
}
defer resp.Body.Close()
// Parse 402 challenge
body, _ := io.ReadAll(resp.Body)
challenge, err := l402.ParseChallenge(resp.StatusCode, resp.Header, body)
if err != nil {
panic(err)
}
fmt.Printf("Pay %d sats to: %s\n", challenge.AmountSats, challenge.Invoice)
fmt.Printf("Payment hash: %s\n", challenge.PaymentHash)
// Pay the invoice (using your Lightning wallet)
// ... your payment logic here ...
// Retry with payment proof
req, _ := http.NewRequest("GET", "https://example.com/api/paid-endpoint", nil)
req.Header.Set("X-Payment-Hash", challenge.PaymentHash)
resp, err = http.DefaultClient.Do(req)
// ... handle response
}
package main
import (
"context"
"fmt"
"net/http"
"github.com/joelklabo/l402-go"
"github.com/joelklabo/l402-go/wallet"
)
func main() {
ctx := context.Background()
// Create a wallet (implement the Wallet interface)
w := wallet.NewLNbits("https://lnbits.example.com", "your-api-key")
// Configure auto-pay options
opt := l402.Options{
AutoPay: true,
MaxSats: 1000, // Maximum sats per request
RetryBackoff: []time.Duration{0, 250*time.Millisecond, 1*time.Second},
}
// Make request with auto-pay
result, err := l402.Fetch(ctx, http.DefaultClient, w, func() (*http.Request, error) {
return http.NewRequest("GET", "https://example.com/api/paid-endpoint", nil)
}, opt)
if err != nil {
panic(err)
}
fmt.Printf("Status: %d\n", result.Status)
fmt.Printf("Paid: %v\n", result.Paid)
fmt.Printf("Body: %s\n", result.Body)
}
ParseChallenge(status int, headers http.Header, body []byte) (*Challenge, error)Parses an L402 payment challenge from a 402 response.
Fetch(ctx context.Context, client *http.Client, w Wallet, makeReq func() (*http.Request, error), opt Options) (*Result, error)Executes a request with optional auto-pay support.
type Challenge struct {
Invoice string // BOLT11 Lightning invoice
PaymentHash string // Payment hash for proof
AmountSats int64 // Amount in satoshis
Message string // Human-readable message
}
type Options struct {
AutoPay bool // Enable automatic payment
MaxSats int64 // Maximum sats to auto-pay
AllowUnknownAmount bool // Allow payment when amount is unknown
RetryBackoff []time.Duration // Retry delays after payment
}
type Result struct {
Status int
Headers http.Header
Body []byte
Challenge *Challenge
Paid bool
}
Implement the Wallet interface to use auto-pay:
type Wallet interface {
PayInvoice(ctx context.Context, invoice string) (preimage string, err error)
}
Test against these live L402 endpoints:
https://wot.klabo.world/score?pubkey=...https://maximumsats.com/api/dvmBoth offer a free tier, then charge sats per request.
MIT
JavaScript client library for L402 (HTTP 402 Payment Required with Lightning Network) - pay-per-request APIs
The financial operating system for AI agents. A single HTTP client that intercepts '402 Payment Required', routes across x402, L402, and MPP, persists credentials as recoverable assets, enforces per-envelope budgets, and emits a structured trace.
MCP Server for Lightning Faucet - Give your AI agent a Bitcoin wallet
Give your AI agents a fetch() that pays. Multi-protocol, multi-chain, open source.
AI agent skill marketplace - where agents buy and sell capabilities from each other
Any API becomes a Lightning toll booth in one line. L402 middleware for Express, Hono, Deno, Bun, and Workers.
540 security tests for AI agent systems — MCP, A2A, x402/L402, decision governance, benchmark integrity, skill supply chain. AIUC-1 pre-cert, NIST AI 800-2 aligned, MCP tool-poisoning reproduction. v4.9.1
A neutral landscape analysis of AI agent payment protocols (x402, MPP, L402, Google AP2, Visa TAP + ICC, Mastercard Agent Pay, Amex ACE, Google/Shopify UCP, OpenAI ACP, and others). Maintained by Genesis Software Group, Copenhagen. Updated April 2026. CC BY 4.0.
MCP server for 402 Index: discover 15,000+ paid API endpoints across L402, x402, and MPP
Sovereign oracle protocol — cryptographically signed data over Lightning sats (L402) and USDC on Base (x402). 11 feeds, 9 exchanges, DLC attestations, MCP server. No API keys, no accounts, no trust.
Enable AI agents to access paid APIs across multiple protocols and chains with automated payment and data retrieval in one call.
Announce HTTP 402 services on Nostr for decentralised discovery. Kind 31402 parameterised replaceable events.