Skip to main content

What this does

l402-kit ships a built-in client that lets any AI agent — or any script — call L402-protected APIs without writing the payment loop yourself.
Everything in between — invoice parsing, wallet call, retry — is handled automatically.

Node.js / TypeScript

1. Install

2. Pick a wallet


Python

1. Install

2. Call the API


What happens step by step

  1. client.fetch / client.get sends the request without any auth header
  2. If the API returns 402, the client reads the invoice and macaroon from the response body (or WWW-Authenticate header)
  3. It checks your budget — throws BudgetExceededError if the price would exceed the limit
  4. It calls wallet.payInvoice(bolt11) and waits for the preimage
  5. It retries the request with Authorization: L402 <macaroon>:<preimage>
  6. Returns the final Response/httpx.Response to your code
No 402? The response is passed through untouched.

Spending report


Next steps

Wallets

Blink, Alby — full setup and options

Budget control

Per-domain limits, callbacks, reports

MCP Server

Claude Desktop integration in 2 minutes

LangChain

Drop-in tool for LangChain agents