Skip to main content

Use this when an agent is about to pay an x402 seller and you want to check the 402 terms, enforce a spend cap (including a daily cumulative budget), optionally ask a human, and keep a payment log — before anything is signed.

Install

Install is free.

TypeScript:

npm install @moneytools-dev/x402-guard

Fallback (download):

curl -fsSL -o x402-guard.ts https://moneytools.dev/products/payment-safety/examples/x402-guard.ts

Python:

pip install moneytools-x402-guard

Fallback (download):

curl -fsSL -o moneytools_x402_guard.py https://moneytools.dev/products/payment-safety/examples/x402-guard.py

Do not install the unrelated PyPI package named x402-guard. The reserved name is moneytools-x402-guard.

Three-line example

import { attachToX402Client } from "@moneytools-dev/x402-guard"; // or from "./x402-guard.ts"
attachToX402Client(client, { payer: "0xYourAgentWallet", maxUsd: 0.05, dailyMaxUsd: 1, escalate: "high" });
const paid = wrapFetchWithPayment(fetch, client); // official @x402/fetch — your existing signer stays in charge
from moneytools_x402_guard import attach_to_x402_client
attach_to_x402_client(client, {"payer": "0xYourAgentWallet", "max_usd": 0.05, "daily_max_usd": 1, "escalate": "high"})

If you are not using the official x402 client, wrap the transport inside your payment wrapper:

import { wrapFetch } from "@moneytools-dev/x402-guard"; // or from "./x402-guard.ts"
const guarded = wrapFetch(fetch, { payer: "0xYourAgentWallet", maxUsd: 0.05, dailyMaxUsd: 1, escalate: "high" });
const paid = wrapFetchWithPayment(guarded, wallet);
from moneytools_x402_guard import wrap_requests, before_pay
session = wrap_requests(requests.Session(), {"payer": payer, "max_usd": 0.05, "daily_max_usd": 1})
# then attach your x402 payment adapter to this session

The package never loads a key, never signs, and never sends a payment.

Pricing

  • Install: free.
  • Checks: billed per call at 0.005 USDC via x402 (USDC on Base) after the live free tier. Verified against public docs on 2026-11-13:
    • Pay Precheck GET https://api.moneytools.dev/v1/precheck — HTTP 5 free calls/IP/endpoint/UTC day, then 0.005 USDC
    • Settle POST https://settle.moneytools.dev/v1/spend/check — trial 50 calls / 7 days (1/client/day), then 0.005 USDC
    • Approval Relay POST https://relay.moneytools.dev/v1/approvals — 3 free/day, then 0.005 USDC
  • If a MoneyTools check itself returns HTTP 401/402, the hook fails closed and does not pay MoneyTools automatically. Pass apiKey / api_key, or wait for the daily reset.
  • Spend Ledger wallet reports (0.05 USDC, or free with a MoneyTools API key) are not called automatically.

What the hook does

  1. Skip if the request already has PAYMENT-SIGNATURE or X-PAYMENT (the payment retry).
  2. Pay Precheck the seller (block / not_402 stop; warn stops unless allowWarn).
  3. Local maxUsd / max_usd against the recommended option amount.
  4. Local daily cumulative budget (dailyMaxUsd / daily_max_usd, UTC day, cross-process when a file store is used). Official x402 clients only cap a single payment (default $1).
  5. Settle POST /v1/spend/check (advisory; the hook refuses to hand the 402 back to the signer if allow: false).
  6. Optional Approval Relay (escalate: off | high | deny | always). Creates a request and returns approve_url / poll_url. The hook does not wait or poll.
  7. Append a local payment log. After a successful paid request you can also set recordSpend / record_spend to call Settle spend/record — still never auto-pays MoneyTools.

Framework guides (Vercel AI SDK, LangChain, Apify mcpc, Coinbase AgentKit, ElizaOS, OpenAI Agents SDK): https://moneytools.dev/products/payment-safety/guides/

Tests (no network, no spending)

cd sdk/x402-guard
npm test
python3 -m unittest python.test_moneytools_x402_guard

MIT © 2026 MoneyTools

Metadata

Release files for moneytools-x402-guard 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for moneytools-x402-guard 0.2.0
File Size Uploaded Provenance Actions
moneytools_x402_guard-0.2.0.tar.gz 10.6 kB Without provenance Details for moneytools_x402_guard-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for moneytools-x402-guard 0.2.0
File Interpreter ABI Platform Actions
moneytools_x402_guard-0.2.0-py3-none-any.whl Python 3 none any Details for moneytools_x402_guard-0.2.0-py3-none-any.whl

Total release size: 21.8 kB

Release files / moneytools_x402_guard-0.2.0.tar.gz

Download URL moneytools_x402_guard-0.2.0.tar.gz
Size 10.6 kB
Tags Source
SHA-256 checksum
How to use checksums
acee080f4ff5c481a6a8b0c1f3803cb72f8841495f086ee5fe0097fa26411899
BLAKE2b-256 checksum
How to use checksums
de65488e6dead52b289a104fe28621cc2c1aebfacc39837eff3341632c16366e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.5

Release files / moneytools_x402_guard-0.2.0-py3-none-any.whl

Download URL moneytools_x402_guard-0.2.0-py3-none-any.whl
Size 11.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
07474eea93ea32313f3107943e7d997f4258636106703b67dee32e7c411da4bf
BLAKE2b-256 checksum
How to use checksums
f8fea91e52a4ff772c80433d7ecfaa00efeeaf52b3b28e66cb81e63c5fb1d78b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.5

Security for moneytools-x402-guard 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page