Installation
Quick start (FastAPI)
Quick start (Flask)
l402_required(price_sats, lightning) — decorator
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
price_sats | int | ✅ | Price in satoshis |
lightning | LightningProvider | ✅ | Provider instance |
Behavior
- No
Authorizationheader: Returns402with invoice, macaroon, price - Valid
L402 <macaroon>:<preimage>header: Route executes normally - Invalid/expired token: Returns
401 - Replayed token: Returns
401 Token already used
402 Response
verify_token(token) — standalone
Replay protection
In-memory (default — single process)
Redis (production — multi-instance)
For multiple workers or instances, useRedisReplayAdapter so every instance shares the same spent-token store:
RedisReplayAdapter.check_and_mark uses SET key 1 NX EX ttl — atomic, race-condition free.