Spending firewall meets the HTTP 402 payment protocol. Policy-based spending controls for AI agent payments.
Project description
๐ธ Bonanza x402 Adapter
Spending firewall meets the HTTP 402 payment protocol
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
- Website: bonanza-labs.com
- Live Demo: bonanza-labs.com/firewall
- x402 Protocol: github.com/x402-foundation/x402
- Agent Wallet: github.com/c6zks4gssn-droid/bonanza-labs-website
Built by Bonanza Labs ๐งจ
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bonanza_x402-0.1.0.tar.gz.
File metadata
- Download URL: bonanza_x402-0.1.0.tar.gz
- Upload date:
- Size: 9.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f3942f3e5bb453f5548dfdb51eea97127b0d56d4ec13fbd7e25caddbcbf1f92b
|
|
| MD5 |
66a4934ec62078f7302fb02479d30428
|
|
| BLAKE2b-256 |
ce2dfdb2c05b61a541e5b9e0f1425384fd6de63e2cb570ae72abad17d6117315
|
File details
Details for the file bonanza_x402-0.1.0-py3-none-any.whl.
File metadata
- Download URL: bonanza_x402-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
42f45cbbb0cceabe66912a4dd1262d823dbb0335acb0333dfeccd0f98ae43d68
|
|
| MD5 |
00223ae466cb1cba178290de0dd2652e
|
|
| BLAKE2b-256 |
16da0ad80a106e1d872361e588f125ba94634a360b1918376b224be4ff32048c
|