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

One line, no code: call MoneyTools with AgentCash

AgentCash (npx agentcash) pays from your own AgentCash wallet (USDC on Base, ~/.agentcash/wallet.json). No MoneyTools account. Failed calls are not charged.

# Wallet Risk Card, 0.02 USDC
npx agentcash fetch "https://tools.moneytools.dev/v1/wallet-risk?address=vitalik.eth&chain=base"
# Pay precheck before paying any x402 seller, 0.005 USDC (free daily tier first)
npx agentcash fetch "https://api.moneytools.dev/v1/precheck?url=https://example.com/paid&method=GET"
# See the price and input schema first, without paying
npx agentcash check "https://tools.moneytools.dev/v1/wallet-risk"

Metadata

Release files for moneytools-x402-guard 0.2.1

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.1
File Size Uploaded Provenance Actions
moneytools_x402_guard-0.2.1.tar.gz 11.0 kB Without provenance Details for moneytools_x402_guard-0.2.1.tar.gz

Built distribution (wheel)

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

Total release size: 22.4 kB

Release files / moneytools_x402_guard-0.2.1.tar.gz

Download URL moneytools_x402_guard-0.2.1.tar.gz
Size 11.0 kB
Tags Source
SHA-256 checksum
How to use checksums
dcb4f0d93e7b94ad8a10a4d61ffbe2af65d17db739b6815874d86934b31b79bd
BLAKE2b-256 checksum
How to use checksums
18e228e1da97995c72ca0715dbf6836427ce7df8c815a70528879bc87b3dc49e
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.1-py3-none-any.whl

Download URL moneytools_x402_guard-0.2.1-py3-none-any.whl
Size 11.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a5de44e8d59b4cde068c005086f7dd11e5ded9c890b8f0d6df3facc9230bbb5b
BLAKE2b-256 checksum
How to use checksums
53db42474f890f2071682a5c7b257da66f724e9ce3a4c91a286ca99e59ec7081
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.1

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.1 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