Skip to main content

💸 Bonanza x402 Adapter

Spending firewall meets the HTTP 402 payment protocol

PyPI Python License x402

Bonanza x402 brings policy-based spending controls to the x402 payment protocol. Every payment request goes through a firewall that checks budgets, risk scores, vendor allowlists, and approval queues — before money moves.

Why?

AI agents are starting to spend real money via the x402 protocol. But x402 alone doesn't answer:

  • "Is this payment within budget?"
  • "Is this vendor trusted?"
  • "Should a human approve this?"
  • "What's the risk level of this transaction?"

Bonanza x402 adds these guardrails. Think of it as ulimit for agent payments — but with Stripe checkout, crypto wallets, and approval flows.

Quick Start

pip install bonanza-x402

Basic: Wrap any x402 payment with a budget

from bonanza_x402 import Firewall, Policy

# Define your spending policy
policy = Policy(
    max_spend_usd=10.00,          # Hard limit per session
    daily_budget_usd=50.00,       # Daily cap
    allowed_networks=["base"],     # Only Base chain
    allowed_tokens=["usdc"],      # Only USDC
    require_approval_above=5.00,  # Human approval above $5
    trusted_vendors=["api.weather.com", "api.data.gov"],
)

# Create the firewall
firewall = Firewall(policy=policy)

# Check before paying
result = firewall.evaluate(
    amount=3.50,
    vendor="api.weather.com",
    network="base",
    token="usdc",
    description="Weather API call"
)

if result.approved:
    print(f"✅ Payment approved: {result.reason}")
else:
    print(f"❌ Payment blocked: {result.reason}")
    if result.requires_approval:
        print(f"⏳ Awaiting human approval: {result.approval_url}")

With x402 Protocol Integration

import x402
from bonanza_x402 import Firewall, Policy

# Set up x402 client
client = x402.Client()

# Set up Bonanza firewall
firewall = Firewall(Policy(
    max_spend_usd=25.00,
    trusted_vendors=["api.premium-data.com"],
    require_approval_above=10.00,
))

# Wrap x402 calls with firewall
response = client.get(
    "https://api.premium-data.com/v1/analysis",
    payment_config=x402.PaymentConfig(
        max_amount=5.00,
        network="base",
    ),
    # Bonanza intercepts before payment is sent
    pre_payment_hook=firewall.x402_hook(),
)

Stripe Checkout Fallback

For payments that need human approval, Bonanza creates a Stripe Checkout session:

from bonanza_x402 import Firewall, Policy, StripeConfig

firewall = Firewall(
    policy=Policy(
        max_spend_usd=100.00,
        require_approval_above=25.00,
    ),
    stripe=StripeConfig(
        api_key="sk_live_...",
        success_url="https://your-app.com/success",
        cancel_url="https://your-app.com/cancel",
    ),
)

result = firewall.evaluate(amount=50.00, vendor="api.expensive-ai.com")
# result.approved = False
# result.checkout_url = "https://checkout.stripe.com/pay/cs_live_..."

Policy Rules

Rule Type Default Description
max_spend_usd float ∞ Hard limit per session
daily_budget_usd float ∞ Daily spending cap
per_transaction_limit_usd float ∞ Max single transaction
allowed_networks list ["*"] Allowed blockchain networks
allowed_tokens list ["*"] Allowed payment tokens
trusted_vendors list [] Auto-approved vendor domains
blocked_vendors list [] Always-blocked vendor domains
require_approval_above float 0 Threshold for human approval
risk_threshold float 1.0 0-1 scale, block above this

Firewall Result

@dataclass
class FirewallResult:
    approved: bool           # Whether the payment is allowed
    reason: str              # Human-readable explanation
    risk_score: float        # 0-1 risk assessment
    requires_approval: bool  # Whether human approval is needed
    approval_url: str | None # Stripe checkout URL if approval needed
    transaction_id: str      # Unique ID for audit trail
    metadata: dict           # Additional context

Audit Trail

Every evaluation is logged:

# Get audit log
entries = firewall.audit_log()

for entry in entries:
    print(f"{entry.timestamp} | {entry.amount} | {entry.vendor} | {entry.decision} | {entry.reason}")

CLI

# Evaluate a payment
bonanza-x402 evaluate --amount 5.00 --vendor api.weather.com --network base

# Check policy status
bonanza-x402 policy show

# View audit log
bonanza-x402 audit log

# Create a test checkout
bonanza-x402 checkout --amount 10.00 --stripe-key sk_test_...

Architecture

┌─────────────┐     ┌──────────────────────┐     ┌─────────────┐
│  AI Agent   │────▶│  Bonanza Firewall    │────▶│  x402 Proto  │
│             │     │                      │     │  (Payment)   │
└─────────────┘     │  ┌──────────────┐   │     └─────────────┘
                    │  │ Policy Check  │   │
                    │  ├──────────────┤   │     ┌─────────────┐
                    │  │ Risk Score    │───┼────▶│  Stripe      │
                    │  ├──────────────┤   │     │  (Approval)  │
                    │  │ Vendor List   │   │     └─────────────┘
                    │  ├──────────────┤   │
                    │  │ Budget Check  │   │     ┌─────────────┐
                    │  └──────────────┘   │────▶│  Audit Log   │
                    └──────────────────────┘     └─────────────┘

Comparison

Feature x402 alone AgentBudget Bonanza x402
Budget limits ❌ ✅ ✅
Vendor allowlist ❌ ❌ ✅
Risk scoring ❌ ❌ ✅
Human approval queue ❌ ❌ ✅
Stripe checkout ❌ ❌ ✅
Crypto (USDC/SOL) ✅ ❌ ✅
x402 native ✅ ❌ ✅
Audit trail ❌ ✅ ✅

Requirements

  • Python 3.10+
  • x402>=2.0 (optional, for protocol integration)
  • stripe>=5.0 (optional, for checkout fallback)
  • solana>=0.30 (optional, for Solana payments)

License

Apache License 2.0 — see LICENSE for details.

Links


Built by Bonanza Labs 🧨

Metadata

Release files for bonanza-x402 0.1.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 bonanza-x402 0.1.0
File Size Uploaded Provenance
bonanza_x402-0.1.0.tar.gz 9.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for bonanza-x402 0.1.0
File Interpreter ABI Platform
bonanza_x402-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 19.6 kB

Release files / bonanza_x402-0.1.0.tar.gz

Download URL bonanza_x402-0.1.0.tar.gz
Size 9.5 kB
Tags Source
SHA-256 checksum
How to use checksums
f3942f3e5bb453f5548dfdb51eea97127b0d56d4ec13fbd7e25caddbcbf1f92b
BLAKE2b-256 checksum
How to use checksums
ce2dfdb2c05b61a541e5b9e0f1425384fd6de63e2cb570ae72abad17d6117315
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.5

Release files / bonanza_x402-0.1.0-py3-none-any.whl

Download URL bonanza_x402-0.1.0-py3-none-any.whl
Size 10.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
42f45cbbb0cceabe66912a4dd1262d823dbb0335acb0333dfeccd0f98ae43d68
BLAKE2b-256 checksum
How to use checksums
16da0ad80a106e1d872361e588f125ba94634a360b1918376b224be4ff32048c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.5

Security for bonanza-x402 0.1.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.1.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