Req plugin that transparently handles HTTP 402 Payment Required responses.
Intercepts 402 responses, detects the payment protocol (x402 or MPP), checks spending budget, signs a payment, and retries the request with payment credentials attached. Retries at most once per request to prevent infinite loops.
Usage
req =
Req.new(url: "https://api.example.com/data")
|> Raxol.Payments.Req.AutoPay.attach(
wallet: Raxol.Payments.Wallets.Env,
protocols: [:x402, :mpp],
ledger: ledger_pid,
policy: SpendingPolicy.dev(),
agent_id: :my_agent
)
{:ok, response} = Req.get(req)Options
:wallet(required) -- module implementingRaxol.Payments.Wallet:protocols-- list of protocol atoms, default[:x402, :mpp]:ledger-- Ledger server for budget tracking (optional):policy--SpendingPolicystruct; when set,approved_domainsandrequire_confirmation_aboveare enforced against the request URL host before the wallet is asked to sign:agent_id-- identifier for ledger tracking (required if ledger given):on_confirm-- 2-arity function(amount, domain) -> :approve | :denycalled whenpolicy.require_confirmation_aboveis exceeded. Runs synchronously inside the Req response step. Absent or non-:approvereturn denies the payment.
Summary
Functions
Attach the auto-pay plugin to a Req request.
Functions
@spec attach( Req.Request.t(), keyword() ) :: Req.Request.t()
Attach the auto-pay plugin to a Req request.